For using a firmata (Respberry <-> Arduino) you must install it on:
- Arduino (Firmata - Arduino)
- Raspberry Pi (Firmata - Raspberry Pi)
Statement of connection types:
device/connection type | get_pin(...) string | available values |
---|---|---|
relay shield | d:pin_no:o | 0 and 1 |
DC motor | d:pin_no:p | 0.0 - 1.0 |
servo | d:pin_no:s | 0 - 255 |
analog input (*) | a:pin_no:i | 0.0 - 1.0 |
(*) you must start reading analog input:
from pyfirmata.util import Iterator ... board = ArduinoMega('/dev/ttyUSB0') iterator = Iterator(board) iterator.start() ...
Example use servo:
from pyfirmata import ArduinoMega board = ArduinoMega('/dev/ttyUSB0') # Arduino usb port servo = board.get_pin('d:2:s') # pin PWM no 2 servo.write(50) # set servo position 0-255