Further to a comment I received http://www.adamsinfo.com/the-robot-phidgets-usb-interface-board-kit-works/comment-page-1/#comment-490 I thought that it might be a good idea to write a quick high level overview of getting the USB Phidget Interface Kit working under Linux. In my case I am of course using 32bit Debian, however these instructions should mostly be portable to any other Linux based OS
Download the Linux version of the Phidget SDK from http://www.phidgets.com/drivers.php
#wget http://www.phidgets.com/downloads/libraries/Phidgetlinux_2.1.6.20090717.tar.gz
#tar -xzf Phidgetlinux_2.1.6.20090717.tar.gz
#cd Phidgetlinux
#cd phidget21/
#make
#cd ..
Now you can write some test code:
#include <stdio.h>
#include “phidget21/phidget21.h”
#include <stdlib.h>
int main(int argc, char **argv)
{
int result;
const char *err;
CPhidgetInterfaceKitHandle ifKit = 0;
//create the InterfaceKit object
CPhidgetInterfaceKit_create(&ifKit);
int InputChangeHandler(CPhidgetInterfaceKitHandle IFK, void *usrptr, int Index, int State)
{
printf(”Digital Input: %d > State: %d\n”, Index, State);
return 0;
}
//Registers a callback that will run if an input changes.
//Requires the handle for the Phidget, the function that will be called, and an arbitrary pointer that will be supplied to the callback function (may be NULL).
CPhidgetInterfaceKit_set_OnInputChange_Handler (ifKit, InputChangeHandler, NULL);
//open the interfacekit for device connections
CPhidget_open((CPhidgetHandle)ifKit, -1);
if((result = CPhidget_waitForAttachment((CPhidgetHandle)ifKit, 10000)))
{
CPhidget_getErrorDescription(result, &err);
printf(”Problem waiting for attachment: %s\n”, err);
return 0;
}
CPhidgetInterfaceKit_setSensorChangeTrigger(ifKit, 0, 10); //we’ll just use 10 as a sensitivity trigger and work on sensor 0 (the first one).
CPhidget_close((CPhidgetHandle)ifKit);
CPhidget_delete((CPhidgetHandle)ifKit);
return 0;
}
Then compile as follows:
#gcc -O -o test test.c -Lphidget21/ -lphidget21
This should output the status of sensor 0. Further information can be found in the Phidget Kit API and with the demo code supplied with the library. This is one of the easiest libraries to work with and has good documentation. The only problems that I did find are that the temperature, voltage and current formulas to translate the sensor value into relevant data are incorrect but i suspect this to be the hardware and not the software.
Tags: debian, gcc, Linux, phidget, phidget interface kit, usb