Archive for December, 2007

Talking to your Arduino, from Python, on Cygwin

It took me an hour or so of googling & trying stuff to figure this out (especially “/dev/ttyS2″), so I’ll put this here in hopes of helping future generations.

Install pyserial. Not the windows installer — download the source and then do this in cygwin:
$ python setup.py build
$ python setup.py install

Now you can connect to your Arduino from Python, inside Cygwin thus:
$ python
>>> import serial
>>> s = serial.Serial('/dev/ttyS2', baudrate=9600) # assuming COM3
>>> # use /dev/ttySn where n = COM port - 1
>>> s.writeln('hello\n')
>>> print s.read(s.inWaiting())

Here’s some Processing code to test with:

void setup() {
  Serial.begin(9600);
}
 
void loop() {
  if (Serial.available())
    Serial.print(Serial.read(), BYTE);
}

Comments