The Raspberry PI is good for a lot of things from computer clusters to homeÂ automationÂ but its missing a few things such as a real time clock, terminal/barrelÂ power connector, or Â Analog pins. Â The ArduinoÂ has analog pins that can be read by the USBÂ virtualÂ serial port from the Raspberry PI.
In MagPI issue 7, has a greatÂ article on using the firmata protocol toÂ communicateÂ between Â Â Arduino and the Raspberry PI.
Install and setupÂ
- Enable SSH on the Raspberry PI
- Install Adafruit Learning System Raspberry Pi WebIDE
- Get the required packages:
sudo apt-get install python-serial mercurial
- Install pyFirmata
sudo apt-get install python-serial mercurial hg clone https://bitbucket.org/tino/pyfirmata cd pyfirmata sudo python setup.py install cd .. ; sudo rm -r pyfirmata
import pyfirmata # Create a new board, specifying serial port board = pyfirmata.Arduino('/dev/ttyACM0') # start an iterator thread so that serial buffer doesn't overflow it = pyfirmata.util.Iterator(board) it.start() # set up pins pin0=board.get_pin('a:0:i') # A0 Input (LM35) pin3=board.get_pin('d:3:p') # D3 PWM Output (LED) # IMPORTANT! discard first reads until A0 gets something valid while pin0.read() is None: pass while True : print "PWM: " + str( pin0.read() ) board.pass_time(1) # pause 1 second board.exit()Â