Apr 16, 2013

Exposing Arduino pins to Raspberry Pi with USB connection

This guide helps you to setup Arduino to talk with a Raspberry Pi, but this will work with any other computer/operating system as long as it has python installed. We will be using python code to send commands with Firmata -protocol to Arduino (Uno) which will have corresponding firmata program running. This guide assumes you have Raspbian installed.




0 Content


  1. Setting up  Raspberry Pi
  2. Setting up Arduino
  3. Run simple test program
  4. Links

1 Setting up Raspberry Pi

Install needed libraries pySerial and pyFirmata

Log in to your RPi with ssh and go to downloads

 $ cd Downloads/  

Next download and extract pySerial library

 $ wget https://pypi.python.org/packages/source/p/pyserial/pyserial-2.6.tar.gz#md5=cde799970b7c1ce1f7d6e9ceebe64c98  
 $ tar -zxvf pyserial-2.6.tar.gz  

Install pySerial and go back to Downloads

 $ cd pyserial-2.6/  
 $ sudo python setup.py install  
 $ cd ..  

Install a git client, because we will be cloning pyFirmata library from github.

 $ sudo apt-get update  
 $ sudo apt-get install git-core  

 $ git clone https://github.com/tino/pyFirmata.git  
 $ cd pyFirmata  
 $ sudo python setup.py install  


2 Setting up Arduino

Connect your arduino and open Arduino IDE. Open StandardFirmata sketch from examples: File>examples>Firmata>StandardFirmata. Upload the code to your arduino, then connect it to Raspberry Pi with usb. Make sure raspberry pi sees arduino:

 $ lsusb  

You sould see something like this "Bus 001 Device 007: ID 2341:0001 Arduino SA Uno (CDC ACM)".

3 Running simple test program

Download blink example to your Raspberry Pi from https://bitbucket.org/fab/pyfirmata/src/96116e877527/examples

Connect a led to arduino pin 12 and run blink.py from raspberry.

 $ python blink.py  

4 Links



1 comment: