Posted on Feb 24, 2014 By Philip Whitt


If you're into home automation or general environment computing then two tools you need to know about are the Raspberry Pi and Phidgets USB device. Raspberry Pi is a very popular micro computer running Linux that includes a variety of I/O options including HDMI. Phidgets is a Canadian computer hardware company offering low cost USB interfaces for a wide selection of sensors and controls. 

Why Phidgets?
If I could sum up Phidgets in two words, I'd say "amazing flexible". They offer a wide array of hardware components including servos, humidity/light/temperature sensors and much more. But this isn't the true gem that Phidgets has to offer - it's their programming APIs. Along with developing the wide array of hardware interfaces they also provide, free of cost, an insane amount of programming resources in just about any language you'd ever want! From Java to Python, they've got it covered. 

Checkout their documentation for complete code examples for any of their supported languages.

http://www.phidgets.com/docs/Programming_Resources

Phidgets Setup
All you need to get started is the Interface Kit, a sensor and a usb cable. For this example, I'm using the 8/8/8 Phidget Interface kit with several magnetic switches

Raspberry Pi Setup
I'm running the default Raspbian OS on the Model B Raspberry Pi. I also have a wireless USB adapter so I can use SSH from a laptop. Since this post is focused on setting up Phidgets on the Raspberry Pi, I'll assume you have your Pi up and running with the basics.

Looking for a complete setup guide? Checkout Raspberry's own quick start guide.


Step 1: Install Java on Raspberry Pi
For this post, I'll be using Java to test the Phidget functionality on the Raspberry Pi. Feel free to substitute your preference.
sudo apt-get update
sudo apt-get install oracle-java7-jdk

Step 2: Install libusb-dev
libusb-dev is needed for the phidget C library to interact with the interface kit. This is needed regardless of the language you choose to interface with.

apt-get install libusb-dev

Step 3: Download Phidget Linux Library

wget http://www.phidgets.com/downloads/libraries/libphidget.tar.gz
tar -xvf libphidget.tar.gz

Step 4: Configure libphidget
This part can take a while as you'll be compiling the libphidget for your device, so be patient while it does stuff.

In the libphidget dir, configure the library
cd libphidget # the output of the above tar -xvf
./configure

Compile and install
make
sudo make install

Copy the shared object file (.so) into your /usr/lib
cp .libs/libphidget.so /usr/lib

Step 5: Plug and Play
Plug the Phidget Interface Kit, and associated sensors into the (already running) Raspberry Pi. All that's left is to run the phidget-test-connection.jar and confirm you get a "Success" output.
sudo java -jar phidget-test-connection.jar

Step 6: Profit?
Now, go forth and build something awesome.


Example: Finger Strength Test


Similar to the carnival strength test, this simple program demonstrates the integration of several components including the Raspberry Pi, Phidgets 8/8/8 Interface Kit, bread board, LEDs and a Phidgets Pressure sensor.

Setup
Install gradle http://www.gradle.org/installation

Phidgets Required:
Optional:
Phidgets Configuration
Add LEDs into output 0-5. A bread board may be necessary to ground multiple I/O with phidgets. Plug the force sensor into sensor input 0.

Run the Program
Simply clone the git hub source and using gradle run the program

git clone https://github.com/philipwhitt/phidgets-finger-strength-test.git
cd phidgets-finger-strength-test
gradle run

Full source code for the above game can be found at:
https://github.com/philipwhitt/phidgets-finger-strength-test



Back to Blog