I feel really silly for asking this, but I've been shocked at my inability to find the simplest example I can imagine for talking to an Arduino over Serial. I have a connection set up, and I understand how to write both Arduino Code and Python, but I have no idea how to write to an arduino pin using python. Can anyone point me to a location with this example or show me how it's done?
2 Answers
There isn't a direct way to control the Arduino through the serial port, so you would need to have some program running on the Arduino that could respond to serial information and do what you want. There are programs like Firmata that will do this for you (or Firmata and Pyduino). Or you could write your own sketch and put it on the Arduino, that waits for a certain serial symbol and sets the pin accordingly.
-
Thanks a ton. I'm just getting started with Arduino, Raspberry Pi, sensors and all. I've been struggling for two days to get some data using Python from serial. Now I know why I wasn't getting any. :) – Iqbal Feb 21 '15 at 04:25
The official page on interfacing Arduino with Python is here:
http://playground.arduino.cc/interfacing/python
If you need a "real" example you might want to have a look at my VU meter experiment. I use python to push the volume data into the Arduino. Nothing fancy but it should give you an idea.
http://blog.blinkenlight.net/experiments/basic-effects/vu-meter/

- 6,784
- 1
- 36
- 61