Monday, March 07, 2011


Firmata is based (mainly) on a three-byte MIDI-like message. If you read the protocol and have no background, it won't make any sense. Let's start with a digital output message.

import serial
# find your own usb serial port by "ls /dev" and note I changed the Firmata on my Arduino to use 9600 bps
# 0x91 is the digital write message (0x90) + "port" 1 (on larger board, there might be more ports), the second two bytes are a bitmask of the digital I/O pins in terms of if they should be on or off
turn on all digital outputs
# turn off all digital outputs
If that isn't exciting enough, let's enable this over a TCP socket using One on terminal:

python ./ -p /dev/tty.usbserial-A4000QBg -P 6666
--- TCP/IP to Serial redirector --- type Ctrl-C / BREAK to quit
--- /dev/tty.usbserial-A4000QBg 9600,8,N,1 ---
Waiting for connection on 6666...

On the other:

from socket import *

And you know it is working because terminal 1 will say:

Connected by ('', 50961)

Then on terminal 2, you can turn the Arduino pin 13 LED on/off with:


(I should note that for now on I am using BlogTrog CodeWindow for my Python)

No comments: