pyFirmata /

Filename Size Date modified Message
107 B
365 B
1.5 KB
3.4 KB
8 B
651 B
14.3 KB

-- restructuredtext --


pyFirmata is a Python interface for the Firmata ( protocol. It is compliant with Firmata 2.1.



The Firmata firmware is included in Arduino ( 0012 or later. Use File -> Examples > Firmata > StandardFirmata to get the sketch with the standard firmware and upload it to your Arduino.

Other devices

Make the Firmata firmaware available on your device. Please refer to the documentation of this device to archive this.


pyFirmata depends on pySerial ( Please install pySerial first.

Dowload the source ( and unpack it:

$ wget -O pyfirmata-0.9.4.tar.gz
$ tar -xzf pyfirmata-0.9.4.tar.gz && mv tino-pyfirmata-599e57b5f400 pyfirmata-0.9.4
$ cd pyfirmata-0.9.4
$ su python install

Or if you like to use the latest source:

$ hg clone ssh://
$ cd pyfirmata
$ su python install


Basic usage:

>>> from pyfirmata import Arduino, util
>>> board = Arduino('/dev/tty.usbserial-A6008rIF')

To use analog ports, it is probably handy to start an iterator thread. Otherwise the board will keep sending data to your serial, until it overflows:

>>> it = util.Iterator(board)
>>> it.start()
>>> board.analog[0].enable_reporting()
>>> board.analog[0].read()

If you use a pin more often, it can be worth it to use the get_pin method of the board. It let's you specify what pin you need by a string, composed of 'a' or 'd' (depending on wether you need an analog or digital pin), the pin number, and the mode ('i' for input, 'o' for output, 'p' for pwm). All seperated by :. Eg. a:0:i for analog 0 as input, or d:3:p for digital pin 3 as pwm.:

>>> analog_0 = board.get_pin('a:0:i')
>>> pin3 = board.get_pin('d:3:p')
>>> pin3.write(0.6)


The examples/ folder contains a few example scripts for the usage of pyfirmata. Please follow the comments in the files for the setup.

Board layout

If you want to use a board with a different layout than the standard Arduino, or the Arduino Mega (for which there exist the shortcut classes pyfirmata.Arduino and pyfirmata.ArduinoMega), instantiate the Board class with a dictionary as the layout argument. This is the layout dict for the Mega for example:

>>> mega = {
...         'digital' : tuple(x for x in range(54)),
...         'analog' : tuple(x for x in range(16)),
...         'pwm' : tuple(x for x in range(2,14)),
...         'use_ports' : True,
...         'disabled' : (0, 1, 14, 15) # Rx, Tx, Crystal
...         }


The next things on my list are to implement the new protocol changes in firmata: