1 / 20

Getting Started with Phidgets

Getting Started with Phidgets. CSCI 1302 Proposals. Equipment. Visit phidgets.com Look up specifications for each sensor Online documentation: http://www.phidgets.com/documentation/web/javadoc/index.html Order additional phidgets http://www.phidgets.com http://www.trossenrobotics.com

vondra
Download Presentation

Getting Started with Phidgets

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Getting Started with Phidgets CSCI 1302 Proposals

  2. Equipment • Visit phidgets.com • Look up specifications for each sensor • Online documentation: 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) • Download Phidget Framework (Phidget 21.MSI) • Install Phidget Framework • Microsoft.NET should be installed on your computer, • After installing Microsoft .net., install Phidget 2.1 MSI. This will create the folder Program Files/Phidget on your computer. • 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 2

  9. Using JGrasp to Extract Files 3 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. Connect the Analog Sensor to any of the analog input ports (labeled 0 to 7) using a Phidgets sensor cable. Connect the InterfaceKit board to the PC using the USB cable. Connect one end of the wire to a digital input port and the other end to the ground connection. 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. Interface Kit

  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 General Tab WebService 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 InterfaceKitPhidget instance field • InterfaceKitPhidgetik; • 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( newInterfaceSensorChangeListener()); }//end trycatch (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. . • privateclassInterfaceSensorChangeListenerimplementsSensorChangeListener • { publicvoidsensorChanged(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 = newServoPhidget(); • 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 trycatch (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.

More Related