Introdution
We have prepared earlier Arduino with an installed library Firmata (post how to prepare Arudino with firmata - link). Now we connect from the Raspberry to the Arduino with Firmata. We have the possibility to connect from most programming languages.
We need
- Raspberry Pi with installed ArchLinux
- Arduino(Mega) with installed Firmata library (Firmata - Arduino)
The ArduinoMega connected to the Raspberry Pi
Installation Python 2.7
refresh of all package list:
install python:# pacman -Syy
# pacman -Sy python2 python2-pip python2-virtualenvtest installation:
# python2 --versionwe should see something like:
Python 2.7.6if all is ok, create python enviroment:
# mkdir robot
# cd robot/
# virtualenv2 --no-site-packages python_firmata_test
# cd python_firmata_test/
# source bin/activate
install pySerial:
# pip2 install pyserial
install pyFirmata:
# pip2 install pyfirmata
Now we can write simple application that controls LED13 on Arduino, full code of this app is below (file binkingLed13.py):
from pyfirmata import ArduinoMega, time
board = ArduinoMega('/dev/ttyUSB0')
while True:
board.digital[13].write(1)
time.sleep(1)
board.digital[13].write(0)
time.sleep(1)
We can run this command:
# python binkingLed13.pyAfter a few seconds, the LED should start blinking at a frequency of 1 Hz. To exit, press ctrl + c
Localization LED13
If you have problems with usb port you can list usb ports:
# ls /dev/ttyUSB*
links:
https://www.python.org/
https://pypi.python.org/pypi/pyserial/2.7
https://pypi.python.org/pypi/pyFirmata/0.9.5