Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSCI 1302 Proposals Getting Started with Phidgets.

Similar presentations


Presentation on theme: "CSCI 1302 Proposals Getting Started with Phidgets."— Presentation transcript:

1 CSCI 1302 Proposals Getting Started with Phidgets

2 Equipment Visit phidgets.com Look up specifications for each sensor Online documentation: http://www.phidgets.com/documentation/web/javadoc/index.html http://www.phidgets.com/documentation/web/javadoc/index.html Order additional phidgets http://www.phidgets.com http://www.trossenrobotics.com Company ships from USA, competitive pricing Buy USB Hub The laptop computers may only have 1 USB port so buy a HUB to attach multiple devices Interface Kit and Servo Motors each attach to a USB Port

3 Installation Procedure (1 of 6) Computer must have Java Installed JGrasp or TextPad

4 Installation Procedure (2 of 6) Go to location for Phidget Windows Downloads www.phidgets.com Downloads Windows

5 Installation Procedure (3 of 6) 1. Download Phidget Framework (Phidget 21.MSI) 2. Install Phidget Framework 1. Microsoft.NET should be installed on your computer, 2. After installing Microsoft.net., install Phidget 2.1 MSI. This will create the folder Program Files/Phidget on your computer. 3. You will see a PH icon on status bar to indicate success

6 Installation Procedure (4 of 6) Create a Phidget Files Folder on your C Drive Download “Java Files” and save in your Phidget Files Folder Examples: Java (Zip file) Additional Files: phidget21.jar Java API Manual: javadoc.zip

7 Installation Procedure (5 of 6) Unzip Files Use UnZip to extract files from.zip The phiget21.jar is a compressed java file. You can use JGrasp to extract all files (Tools/Jar). Ultimate Zip is another program to extract the java files.

8 Using JGrasp to Extract Files 1 1 2 2

9 3 3 4 4

10 Installation Procedure (6 of 6) 2 folders will be created. (com and meta-inf) All source files you create must be in the Phidget Files folder. They will import data from the com folder

11 Interface Kit 1.Connect the Analog Sensor to any of the analog input ports (labeled 0 to 7) using a Phidgets sensor cable. 2.Connect the InterfaceKit board to the PC using the USB cable. 3.Connect one end of the wire to a digital input port and the other end to the ground connection. 4.Connect the LED to one of the digital output by inserting the long LED wire into any of the digital outputs (labeled 0 to 7) and the shorter wire to Ground. 1.

12 Testing the InterfaceKitPhidget Double Click on the icon to activate the Phidget Control Panel and make sure that InterfaceKitPhidget is properly attached to your PC. If you do not see the device listed Go to WebService Tab Set [Start up Type] Automatic and Press [Start] You may have to detach the Interface Kit from USB port and reattach after WebService status is Running WebService Tab General Tab

13 Testing the InterfaceKitPhidget When you double click on the device name, GUI appears that allows you to interact with the device Remember to close this interface before executing your program. The interface kit may be “connected” to one program at a time.

14 Using Phidget Classes (1 of 6) Source code must be saved in folder that contains the com folder. Your program is looking for this structure. Import the Phidget classes in your source code import com.phidgets.*; import com.phidgets.event.*;

15 Using the Phidget Classes (2 of 6) LISTEN TO ANALOG SENSORS ATTACHED TO THE INTERFACE KIT PHIDGET Declare an InterfaceKit Phidget instance field InterfaceKitPhidget ik; Up to 8 analog sensors can attach to the interface kit. Open the interface kit with openAny() or open methods Add a sensor listener to monitor change in sensors values/

16 Using the Phidget Classes (3 of 6) LISTEN TO ANALOG SENSORS ATTACHED TO THE INTERFACE KIT PHIDGET try { ik = new InterfaceKitPhidget(); // Allocate space ik.openAny(); //Open interface attached //Wait for the device to be attached System.out.println("waiting for InterfaceKit attachment..."); ik.waitForAttachment(); System.out.println(ik.getDeviceName()); //Add a Listener to report change in sensors ik.addSensorChangeListener( new InterfaceSensorChangeListener()); }//end try catch (PhidgetException e) { System.out.println("Phidget Exception Generated"); e.printStackTrace(); } THIS IS A CLASS YOU CREATE!

17 Using the Phidget Classes (4 of 6) Create your class that implements the SensorChangeListener.. private class InterfaceSensorChangeListener implements SensorChangeListener { public void sensorChanged(SensorChangeEvent se) { // Get the port number of the analog sensor that has changed. int port = se.getIndex(); //Get the value of the sensor. int value = se.getValue(); //You must know where each sensor has been attached to the interface kit System.out.println(“Sensor in port: “ + port + “has the value: “ + value); } Required method //SAMPLE CODE if (port == 0) //left light sensor { if (value > 400) // too dark // insert code }

18 Using the Phidget Classes (5 of 6) ACTIVATE A MOTOR CONNECTED TO YOUR USB PORT Create a servo motor instance field ServoPhidget servo; Open the motor try { servo = new ServoPhidget(); servo.openAny(); //If you just have 1 servo attached used openAny() method. // Otherwise you can specify which servo you want to open servo.open(19844); System.out.println("waiting for Servo attachment..."); servo.waitForAttachment(); System.out.println("Serial: " + servo.getSerialNumber()); }//end try catch (PhidgetException e) { System.out.println("Phidget Exception Generated"); e.printStackTrace(); }

19 Using the Phidget Classes (6 of 6) MOVE A MOTOR CONNECTED TO YOUR USB PORT /* The range of a servo motor maybe -23 to 232 however this depends on the servo. Typically, the range might be 25 to 180 degrees. */ try { // Set position to lowest position (rewind) servo.setPosition(0, 90); //motor #0, angle 90 degrees } catch (PhidgetException e) { System.out.println("Phidget Exception Generated"); e.printStackTrace(); } The setPosition method is used to move the motor. A PhidgetExecption may be thrown when setting the motor and must be caught in your code.

20 Frequently Asked Questions Do NOT have the Phidget Control Panel open when you are testing your code. Only one program is able to open the interface at a time. You must close all programs that are trying to access the interface before your code will run.


Download ppt "CSCI 1302 Proposals Getting Started with Phidgets."

Similar presentations


Ads by Google