Spying on People with Guns


Talking to your Arduino, from Python, on Cygwin

December 3, 2007 · File under Electronics

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);
}

Archive

Categories

Found
Things that suck
Unsolicited advice
Adventure time
Generative art
Fun and games
Electronics
Kids
Technical argle-bargle
Sheet music
Apropos of nothing

A collection of posts about things that suck, and posts that suck about things that don't suck.


RSS feed

@efredricksen
@efred
efredricksen
grumdrig (gh)
grumdrig (bb)
efredricksen
©2022 Eric Fredricksen