Products for USB Sensing and Control
Products for USB Sensing and Control

Getting Started with Raspberry Pi and Phidgets

How to configure a Raspberry Pi for working with Phidgets


by Phidgets Education

Introduction

Do you have a Raspberry Pi in your classroom that you'd love to use with Phidgets? Well, you're in luck! Keep reading to find out how to add some awesome functionality to your next Raspberry Pi project.

This guide assumes the use of Raspbian OS.

Prerequisites

This project assumes you have completed The Getting Started Kit.

You should also have previous experience with the Raspberry Pi and Thonny Python IDE.

If you have yet to boot your Raspberry Pi for the first time, follow the setup instructions.

Goal

At the end of this project you will be able to connect and use a Phidget with a Raspberry Pi.

Parts Inventory

Hardware

You can connect your Getting Started Kit to your Raspberry Pi just like you would with any other computer.

Setup

Install Phidget Library

In order to use your Phidgets, you'll need to install libusb on the Raspberry Pi. The first step is to open the terminal:

Next, enter the following command:

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

Now that you have libusb installed, you will need to download the Phidget library for Linux.

Next, right-click libphidget22 and select Extract To...

Change the extract location to /home/pi/ and click Extract.

Navigate to /home/pi/ where you will now find the libphidget22 folder. Right-click on the libphidget22 folder and select Open in Terminal.

Enter the following command in the terminal:

./configure

Followed with the make command (this may take some time to complete):

make

And finally:

sudo make install

Next, restart your terminal (or open a new one) and update the library cache.

sudo ldconfig

Configure Device

In your libphidget22 folder, navigate to /plat/linus/udev. Right click on the udev folder and select Open in Terminal.

In order to allow your programs to access the phidgets connected to your Raspberry Pi, you need to configure the device rules.

You can do this by entering the following command:

sudo cp libphidget22-1.4.20190605/plat/linux/udev/99-libphidget22.rules /etc/udev/rules.d

Note: be sure to replace libphidget22-1.4.20190605 with your library version. Use the TAB key to autocomplete.

Navigate to /etc/udev. You should now find a folder titled rules.d containing 2 files.

Now that everything is set up properly, be sure to reboot!

Code

Your Raspberry Pi is now set up (a one time process). Next, you can start using your Phidgets.

Open Thonny Python IDE.

Switch to regular mode.

Select Tools> Manage Packages.

Find the Phidget22 package and click install.

create a file called test.py and add the following code to run the redLED on your Getting Started Kit.

Conclusion

With that, you are ready to start integrating Phidgets into your Raspberry Pi projects!

Make a cool project using Raspberry Pi and Phidgets? We'd love to hear about it at education@phidgets.com