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

Step 1: 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.*
<p>This helped me a lot! However, there are a couple of pitfalls in the python script that could cause a major headache if not noticed:</p><p>1) You should always remember to close the serial port when you're done using ser.close()</p><p>2) There should be some way to exit out of the infinite while loop. The program is not very useful if it doesn't have a way to end. I ended my loop once count reached 255, but some other approach would work as well, perhaps watching for an end signal from the Arduino?</p>
<p>Hi there! Nice tutorial! I was wondering whether this could be used to interface between the Raspberry Pi and Arduino? I mean I want my RPi to trigger my Arduino to run its sketch depending upon some conditions, so I could simply check for those conditions on the RPi's python script and then send a variable to Arduino and it runs the script. Can this happen?</p>
<p>Where on python does this get printed? I am running the python script and also opened up the serial monitor on Arduino. It reads &quot;Ready&quot; 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.</p>
It's displayed in the python terminal
<p>OK, what is Idle?</p>
<p>Idle is a python IDE. Basically, what you write your python script in.</p>
<p>Thanks urshur.</p>
<p>I love the combination of Python and the Arduino. So I have created a collection about it. I have added your instructable, you can see the collection at: &gt;&gt; <a href="https://www.instructables.com/id/Arduino-and-Python-and-perhaps-a-Rasberry-Pi/"> https://www.instructables.com/id/Arduino-and-Pytho...</a></p>
<p>Note for Unix you might want to add this to the top of the code.<br>#!/usr/bin/python</p>
<p>Got me going!</p>
<p>Easy enough!</p>
<p>liked the idea, decided that having its own gui and easily adjustable parameters would be good. <a href="https://www.instructables.com/id/Python-Terminal-for-Cheap-Pi-Arduino-Connection/" rel="nofollow">https://www.instructables.com/id/Python-Terminal-fo...</a></p>
<p>Thank you for the tutorial, it is really useful. Just one question: Is <br>it possible to reuse somehow Arduino libraries to interface Arduino <br>shields (gsm.h) from Python?</p>
<p>oh yes :D </p>
<p>Excellent tutorial, just what I needed to start reading data from my 'Barometric Differentiation Engine'</p><p>Thanks</p>
<p>Nice! it work for me, the only change I made was instead of</p><p>('/dev/tty.usbmodem1d11', 9600) I used (2) what is the COM3 port.</p><p>Thanks</p>
<p>Nice! it work for me, the only change I made was instead of</p><p>('/dev/tty.usbmodem1d11', 9600) I used (2) what is the COM3 port.</p><p>Thanks</p>

About This Instructable




Bio: From solder to zip ties, lead acid batteries and LEDs, and especially Legos, putting things together has always fascinated me. The more challenging the better ... More »
More by Hammock Boy:Chipper Board - ATtiny Programming Shield Boxhead recreated with Python with Tkinter Interface Python and Arduino with pySerial 
Add instructable to: