Picture of Interface Python and Arduino with pySerial
Over the last few months I have learned how to program with Python. With one of the upcoming projects that I am working on it would be nice to have a computer’s display to view the data collected by a rover in real-time as well as crunch numbers while the rover completes its  mission. The rover will have an Arduino as a brain. What I found after some searching was pySerial. This is a really neat piece of software that allows Python to send and receive data much like the Serial Monitor does.

pySerial is available to download at

Remove these adsRemove these ads by Signing Up

Step 1: Installation

Picture of Installation
Once you download it open up Terminal and type in:

tar xfvz /Users/*Account*/Downloads/pyserial-2.6.tar.gz
cd pyserial-2.6
sudo python setup.py install

To make sure that everything installed correctly open up Idle and type in 'Import Serial'. If no errors appears then everything is good to go.

You can check the available ports with the line

ls /dev/tty.*

Step 2: Program the Arduino

Picture of Program the Arduino
Now to test it out, upload the below sketch to your Arduino. I do not know how this will or will not work on Arduino clones.

void setup() {
Serial.begin(9600); // set the baud rate
Serial.println("Ready"); // print "Ready" once
void loop() {
char inByte = ' ';
if(Serial.available()){ // only send data back if data has been sent
char inByte = Serial.read(); // read the incoming data
Serial.println(inByte); // send the data back in a new line so that it is not all one long line
delay(100); // delay for 1/10 of a second

Step 3: Program Idle

Picture of Program Idle
Screen Shot 2012-12-29 at 4.14.28 PM.png
Next in Idle create a new window and create the below program.

from time import sleep
import serial
ser = serial.Serial('/dev/tty.usbmodem1d11', 9600) # Establish the connection on a specific port
counter = 32 # Below 32 everything in ASCII is gibberish
while True:
     counter +=1
     ser.write(str(chr(counter))) # Convert the decimal number to ASCII then send it to the Arduino
     print ser.readline() # Read the newest output from the Arduino
     sleep(.1) # Delay for one tenth of a second
     if counter == 255:
     counter = 32

Two things to keep in mind. To determine what serial port your Arduino is connected to look at the bottom right corner of your Arduino sketch. Whatever that is should be what is in quotes in line 3 of the Python program.

You can also change the baud rate in line 3 of the Python program and line 2 of the Arduino program as long as they stay the same.

Once you run the program it will print out the majority of ASCII characters. By first sending them to the Arduino, which will in turn send it back to the computer that Python then prints out.

brorobw1 month ago

Got me going!

vtank114 months ago

Where on python does this get printed? I am running the python script and also opened up the serial monitor on Arduino. It reads "Ready" and that's about it. Nothing else seems to happen. Is there a serial monitor-type thing I need to open on IDLE? Please help me. I need to figure this out for my project ASAP.

kbarre1234 months ago

Easy enough!

russ_hensel made it!4 months ago

liked the idea, decided that having its own gui and easily adjustable parameters would be good. http://www.instructables.com/id/Python-Terminal-fo...

Katal11 months ago

Thank you for the tutorial, it is really useful. Just one question: Is
it possible to reuse somehow Arduino libraries to interface Arduino
shields (gsm.h) from Python?

Abu10baker Katal6 months ago

oh yes :D

gothma8 months ago

Excellent tutorial, just what I needed to start reading data from my 'Barometric Differentiation Engine'


pauwy10 months ago

Nice! it work for me, the only change I made was instead of

('/dev/tty.usbmodem1d11', 9600) I used (2) what is the COM3 port.


pauwy10 months ago

Nice! it work for me, the only change I made was instead of

('/dev/tty.usbmodem1d11', 9600) I used (2) what is the COM3 port.