Top Banner
CSCI 1302 Proposals Getting Started with Phidgets
20
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: CSCI 1302 Proposals Getting Started with Phidgets.

CSCI 1302 Proposals

Getting Started with Phidgets

Page 2: CSCI 1302 Proposals Getting Started with Phidgets.

EquipmentVisit phidgets.com

Look up specifications for each sensorOnline documentation:

http://www.phidgets.com/documentation/web/javadoc/index.html

Order additional phidgets http://www.phidgets.comhttp://www.trossenrobotics.com

Company ships from USA, competitive pricingBuy 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

Page 3: CSCI 1302 Proposals Getting Started with Phidgets.

Installation Procedure (1 of 6)Computer must have

Java InstalledJGrasp or TextPad

Page 4: CSCI 1302 Proposals Getting Started with Phidgets.

Installation Procedure (2 of 6) Go to location for Phidget Windows

Downloads www.phidgets.com Downloads Windows

Page 5: CSCI 1302 Proposals Getting Started with Phidgets.

Installation Procedure (3 of 6)1. Download Phidget Framework (Phidget 21.MSI)

2. Install Phidget Framework1. 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

Page 6: CSCI 1302 Proposals Getting Started with Phidgets.

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

Page 7: CSCI 1302 Proposals Getting Started with Phidgets.

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.

Page 8: CSCI 1302 Proposals Getting Started with Phidgets.

Using JGrasp to Extract Files

11

22

Page 9: CSCI 1302 Proposals Getting Started with Phidgets.

Using JGrasp to Extract Files

33

44

Page 10: CSCI 1302 Proposals Getting Started with Phidgets.

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

Page 11: CSCI 1302 Proposals Getting Started with Phidgets.

Interface Kit1. 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.

Page 12: CSCI 1302 Proposals Getting Started with Phidgets.

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 listedGo 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

Page 13: CSCI 1302 Proposals Getting Started with Phidgets.

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.

Page 14: CSCI 1302 Proposals Getting Started with Phidgets.

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 codeimport com.phidgets.*;import com.phidgets.event.*;

Page 15: CSCI 1302 Proposals Getting Started with Phidgets.

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/

Page 16: CSCI 1302 Proposals Getting Started with Phidgets.

Using the Phidget Classes (3 of 6)LISTEN TO ANALOG SENSORS ATTACHED TO THE INTERFACE KIT

PHIDGETtry{ 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!

Page 17: CSCI 1302 Proposals Getting Started with Phidgets.

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}

Page 18: CSCI 1302 Proposals Getting Started with Phidgets.

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(); }

Page 19: CSCI 1302 Proposals Getting Started with Phidgets.

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.

Page 20: CSCI 1302 Proposals Getting Started with Phidgets.

Frequently Asked QuestionsDo 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.