How To Get Started with Phidgets on the Raspberry Pi

IMG_3346   Before beginning, you’ll want to have a few things in place. You’ll need:

  1. A functioning Raspberry Pi (obviously).
  2. A separately powered USB hub, since the Raspberry Pi isn’t capable of delivering enough power on the USB ports to drive most Phidgets or other USB devices that require the full 500mA.
  3. An internet connection either via the ethernet port or a USB wifi dongle.
  4. The Phidget you wish to connect.


Install a Linux based OS:

Phidgets already come with support for Linux operating systems, and so getting started on the Raspberry Pi is really just a variant of our getting started on Linux guides; You can read a tutorial or watch a video for more background on that.

The first thing to do is ensure you have a Raspberry Pi that is functional and boots into one of the linux based distributions available for it. This means no using RISC OS for those of you who like to go against the grain. There are a couple of ways you can get the Raspberry Pi up and running; you can install one of the distribution images directly, or you can install it from the NOOBS installer. There is already ample documentation on the install process provided by each distribution and the Raspberry Pi foundation itself, so we won’t go into detail on how to complete this step. If in doubt though, use the NOOBS installer as it’s designed to be very straight forward. The rest of this guide will be based upon the Raspbian distribution, so if you do not have a preference you may wish to select that one as it will minimize any potential differences between your own experience and this guide.


Install the Phidgets Drivers:

Okay, so we have a functioning version of Raspbian. We’re working from the LXDE desktop environment, though most of this guide will be completed using the terminal so the instructions apply to a console only install of Raspbian as well. We’re going to want to install some dependencies first. Start by opening the terminal (LXTerminal) Then typing;

sudo apt-get install libusb-1.0-0-dev

Now we will download and install the Phidgets libraries.

tar zxvf libphidget.tar.gz

Next we’ll change into that directory. Type “cd libphidget-” then hit [TAB] to complete the line. This will take care of the long string of version numbers. You should see something like:

cd libphidget-

Press enter to go to that directory, where we’ll start building the drivers


This step will compile the libraries on the Raspberry Pi, which will take some time. Now is a great time to go get some coffee. Once that is complete, finish the installation with:

sudo make install


Test the Drivers with the Example Code:

Okay, so now it’s time to test if the Phidgets work. We’ll do this by running some of the C examples that are provided on the Phidgets website. First we need to download and unpack the examples:

tar zxvf phidget21-c-examples.tar.gz

Now we do the TAB trick again to change into the correct directory. “cd phidget21-c-” [TAB] to get something like:

cd phidget21-c-examples-

Lets start with the hello world example. Compile it with gcc, remembering to link it to the Phidget libraries:

gcc HelloWorld.c -o HelloWorld -lphidget21

And then run it with super user privileges to ensure we have access to the USB ports

sudo ./HelloWorld

You should see something like this: Output-HW2 As you can see, it listed a Unipolar Stepper Controller here, though you should only see that if you happened to have one set up too. It’s more likely you’ll see an InterfaceKit if that’s what you’re getting started with, or no devices at all if you haven’t connected anything yet. We realize not everyone will have a Stepper Phidget for this, so you can substitute your own Phidget. For example, the InterfaceKit example is InterfaceKit-simple.c. Let’s see what happens if we run the Stepper-simple.c example though:

gcc Stepper-simple.c -o Stepper-simple -lphidget21
sudo ./Stepper-simple

You’ll be prompted to hit a key a few times while it spins the stepper motor around in various directions. Output-SS So there you have it, we’ve successfully connected Phidgets to the Raspberry Pi and gotten them to do something real. Suppose you don’t want to use C as your programming language though. Phidgets supports plenty of other languages under Linux such as C++, C#, Python, Java and even Ruby!

Trying Other Languages: Python:

Installing any of these other languages is similar to the way we installed the Phidgets C drivers. Let’s use Python as an example since the Raspberry Pi already comes with Python installed. Go back to the home directory:

cd ~

Download the Python libraries:


Because the libraries come as a zipped archive, we’ll likely need to install zip support

sudo apt-get install zip unzip
cd PhidgetsPython/

Now we can install the Python libraries

sudo python install

And download the examples:

cd Python/

Lets try the HelloWorld example again, but this time in python:

sudo python

You should see the exact same results as you did using the C example. Most of the other languages listed above will have a similar installation process, with the exact nuances detailed on each of their respective pages in our Programming Resources documentation.

The instructions to get it working with a Raspberry Pi should be identical to the general Linux instructions on each page. If you find you are having trouble installing the libraries for your language and getting the examples working then we encourage you to check our forums or contact support.

Tagged with: , , , , , , ,
Posted in How-Tos
3 comments on “How To Get Started with Phidgets on the Raspberry Pi
  1. NK says:

    I’ve been trying to connect a PhidgetInterfaceKit 0/16/16 to a Raspberry without success for several months – I follow the instructions, the card is recognized by the Raspberry (dmesg), but the HelloWorld refuses to see the Phidget. On Windows the Phidget works fine…
    Today I tried connecting a ver 605 of the same Phidget, and it works!!!
    So, it seems that my v6.0 cards are not recognized by Raspberry, but new versions are.
    Are there any other limitations with running Phidgets on Raspberry?

    • kahht says:

      It’s great to hear that you got it working! The only limitation we’re aware of is needing a powered USB hub, but there may be some undiagnosed limitations out there, but we haven’t come across any.

  2. NK says:

    Yes, I used a powered hub. I have a bunch of v6.0 0/16/16’s that all work with Windows, but none worked with the Pi, and all the v6.05’s worked fine.
    Any way you can support also v6.0 on the Pi?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: