Phidgets
Phidgets are are a set of interfaces, sensors and actuators that have readily made connectors (USB or 3-line). Phidgets let you avoid soldering and microcontroller programming so you
can put together an installation pretty quickly. Good for prototyping.
"Physical Widgets"
How to set up for Java:
Phidgets (physical widgets), www.phidgets.com
- supported in Windows, Mac OS X, Linux, Windows Mobile
- USB devices, installation and re-configuration is "plug and play"
- support available from a number of programming environments:
- Visual Basic
- Visual Basic for Applications (VBA)
- C/C++ (available in Windows, Linux, MacOS)
- Borland Delphi
- ActionScript (Flash)
- Java (Windows, MacOS, Linux) , which we will work with
- etc
- no Processing support, though you can fix that with some form of inter-process communication (e.g. a TCP socket)
USB
- universal serial bus, i.e. lets you hang devices in any order
- needs Phidget driver installation
- Phidgets use the USB HID (Human Interface Device) protocol
- use the "phidget manager" on your platform to see a list of successfully connected
Phidgets
- PC: start from the Ph icon in the system tray
- Mac: System Preferences, select Phidgets
- power issues: some phidgets will need separate power (6-12 V DC) in certain heavier-load conditions, others will simply take their power from USB
- you have to wait a bit more the first time you connect a new type of Phidget (or any other USB device for that matter) in a certain USB connector
- sometimes you will get an error the first time, try disconnecting and reconnecting the device, it may work without errors
8/8/8
"Phidget Interface Kit" (8 digital inputs, 8 digital outputs, 8
analog inputs; there exist boards of other sizes)
- we have 4 boards
- will need external power in some USB connectors
- will surely need external power when other phidgets are connected
to the board. If you want to avoid this, connect the phidget directly
to the computer or use a powered USB hub
- you can monitor the Phidget Interface Kit with the manager applications
- 8 digital
inputs (see page 16) , basically reading the state of a switch. Returns True when the switch is connected to GND, False otherwise.
- 8 digital
outputs
(see page 19)
- basically turns a switch on and off
- simple and frequent example: LEDs
- a LED is a diode, will let current pass in only one direction
- shorter pin to the ground (cathode), the longer one (anode)
to the digital output
- to avoid short, 300 Ohm resistor included in the phidget
output
- 8 analog inputs (page 12)
- you can connect a number of packaged
sensors
- but any other sensor that can be fed with 5V and produce
voltage between 0 and 5V will work. See details below.
- we have 3 sensors for each of: force, light, mini
joystick, rotation, slider, temperature, touch
- besides these, we can also detect acceleration and presence of
RFID tags (see specific phidgets below)
- always disconnect the USB to the computer before modifying the
interface kit circuit! (attaching analog inputs, digital inputs or
outputs)
Phidget Java API
- if you encouter problems with the Phidget21.jar file on the Java download page you can use this, which is taken from the example zip
- package com.phidgets
- important Phidget methods
- info: getSerialNumber(),
getLibraryVersion(), getDeviceVersion()
- useful when software and hardware evolve
- getSerialNumber()
identifies the device uniquely
- open()
looks for the physical USB device
- you can specify the serial number of the device, in case
there are more Phidget interface kits attached
- openAny() will return the first available Phidget of the respective type
- you can open Phidghets connected to another computer by indicating an IP address (the Phidget Web Service should be started on that machine)
- open is pervasive. It will keep the device open even if it is attached or detached
- open is asynchronous, it returns immediately. You can call waitForAttachment()or use events (see below) to
- isAttached()
tells whether the device is really attached
- Events: AttachEvent, DetachEvent, ServerConnectEvent, ServerDisconnectEvent, ErrorEvent
- use addEEEEListener(EEEEListener) where EEEE is the type of event
- removeEEEEListener(EEEEListener)
- close()
gives away resources needed by your program to access the device. No more events are sent.
- device-specific methods depend on the actual device function
- most devices let you register listeners
that will have a method called when a device changes state
InterfaceKitPhidget:
- we look at a Java example and the way it is set up in a IDE (Eclipse)
- board size
- getOutputCount()
the number of digital outputs (8 for our board)
- getInputCount()
the number of digital inputs (8)
- getSensorCount()
the number of analog inputs (8)
- digital input reading: getInputState(int
index)
- digital output setting: setOutputState(int
index, boolean value)
- this may lead to timeout PhidgetException... It looks a lot like harware incompatible with latest software
- happens also to other setting methods (for e.g. servo motors)
- especially if you call them in rapid sequence
- digital output reading: getOutputState(int
index)
- analog input reading
- getSensorValue(int
index) returns 0-1000
- getSensorRawValue(int
index) returns 0-4095 (10 bit Analog-Digital Converter)
- polling vs event subscription
- event subscription for:
- the event object will give information on
- which Phidget produced the event: getSource()
- which input has changed: getIndex()
- what is the new value: getValue()
for analog inputs, getState() for digital inputs our outputs
The Phidget Interface Kit lets us connect a variety of sensors and lets
us drive digital outputs. That is not enough though.
Some inputs and outputs need special circuitry so they come as separate
phidgets that are connected via USB to the computer or using the USB
hub on the Phidget Interface Kit
Phidget actuators (outputs):
- 4
servo motor driver
- we have 3, and a large number of servo motors
- can turn in fine-tuned angles
- can be tested from the Phidget manager
- USB power only goes to motor 0. If you want to drive other servos, you
need to give 6-12V DC power to the board
- API (ServoPhidget)
- getMotorCount()
- double
getPosition(int index)
- getPositionMax(int index), getPositionMin(int index)
- setPosition(int
index, double angle)
- getMotorOn(index), setMotorOn(index, boolean)
- Event: ServoPositionChangeEvent
- Java
example
- initial position is not always zero (or minimum), always
set the servo to the desired position initially! The position of a newly connected motor cannot be known, you have to set it.
- Beware of multiple Java programs running at the same time (esp in Eclipse)
- other types of motors: stepper motors (turn with a precise number of steps)
- LCD and LED output
Phidget sensors (inputs):
- RFID
board
- we have 3
- detects when a certain tag is within 3 inches of the RFID
receiver
- can be tested from the Phidget manager
- one tag can be present only. If more tags are present, one or
none will be reported
- API: (RFIDPhidget):
- the device also has some outputs, e.g. a LED
- getOutputCount(), getOutputState(int
index), setOutputState(int
index, boolean value), OutputChangeEvent
- setAntenaOn(boolean), getAntennaOn()
- Java example
- issues
- some older Phidget RFID receivers do not work with the USB
hub of the newer Phidget Interface Kits
- connect them directly to a computer USB instead
- setAntennaOn(true) seems to be always needed for old boards.
- accelerometer
- we have one
- can be tested from the Phidget manager
- API (AccelerometerPhidget)
- number of axes: getAxisCount()
- sensor value reading: double
GetAcceleration(int axis)
- change trigger for acceleration: setAccelerationChangeTrigger(int
axis, double value)
- AccelerationChangeEvent
- contains information on the axis where
acceleration changed (getIndex())
and the acceleration value (double
getValue())
- Java example
- Other sensors
more about analog input:
- sensor data sheets
- resistive
and active sensors
- resistive sensors are simply given a voltage to measure
their resistance
- some resistive sensors only have 2 pins and an extra
resistance is needed
- active sensors are given a voltage and will output a voltage
proportional to what is measured
- in all cases, analog-digital conversion takes place inside
the phidget
- guide to phidget analog input cable
high-power
digital output
Phidget
videos
Arduino Firmata is suggested as an alternative. Like Phidgets, Firmata can be easily driven from a computer , from various programming environments (it's a so-called sensorbox), with no need for external power. Unlike Phidgets, with Firmata the sensors and actuators are not packaged, they need more wiring and/or soldering. An Arduino Phidget shield might address that.
Moving towards higher-fidelity
prototypes.
Microcontrollers
- allow you to skip the PC if needed
- allow programming via a serial/USB connection
- sensors/outputs are connected to microcontroller pins, via
specific circuits