Python with Arduino LESSON 2: Installing the Software

There are some really incredible things we can do when we get our little Arduino to talk to the big bad Python programming language. To do that, we have to start by downloading some software. Never fear . . . it is all free and I will take you step by step through the installation. The video above shows you how to do it. If you are the impatient and technically adept type, you can download these three software packages:

1) Download and Install Python 2.7.8. Please note all my tutorials use this flavor of python. If you want to follow my tutorials, do not download a Python 3.x. Also download 32 bit version of the software, even if you have a 64 bit windows machine.

2) Download and Install Pyserial version 2.7. Again, download the 32 bit version of the software.

3) Download and install the Vpython library for 32 bit windows.

Now, lets get python and arduino talking together. First up, we need a simple program to get the Arduino sending data over the serial port. The following program is a simple program that will have the Arduino count and send the data to the serial port.

Now, open the VIDLE environment which you downloaded with the Vpython library. Once you have done that, you are ready to write a Python Program that will go out and read the data over the serial port. Full explanation is in the video. Do note, however, that the line:

This is for a windows machine. Also, the ‘com11’ has to be adjusted and set to whatever com port your arduino is talking on. You can figure that out by looking at Tools – Port on the Arduino. Set this parameter to whatever port your Arduino is talking on. Then, the baud rate needs to match as well. You can use whatever you want by Arduino and Python need to be on the same baud rate, which you set on this line of code. OK, the complete Python code to read the Arduino data from the serial port is here:

Simple as that! Welcome to the world of having the Power of Python now at your fingertips.

31 thoughts on “Python with Arduino LESSON 2: Installing the Software”

  1. Paul : I am following your programs on the internet for Python that I find to be of great value for my projects. On programme #2 I keep getting the error that there is an attribute error
    “serial object has no attribute read line. Would you please direct me how to correct this problem.
    Thanking you in advance
    Doug Milburn

    1. Doug, I am not sure, but just do your best to troubleshoot. Check every letter in your code, paying attention to capitalization and every minute detail.

      1. Paul you where right I misspelled ardunio in the programme .I now have it working .
        I will be working with all your lessons ,so please keep up the good work.
        Thanking You in Advance
        Doug Milburn

  2. Like your lessons very much. Very interesting, great stuff.
    I use Linux Ubuntu variant, so I have some trouble with the instals of some apps. Vpython for instance, I’m working on it.

    sincerely

    1. Hy Richard, i’m am having problems with installation on ubuntu. i got it working now, but he crahes on: from visual import * (see lesson 3 using python with arduino), do you know a solution?
      thx in advance.

      1. I have not tried running Vpython on Linux, so am not sure what the issues might be. Let us know if you get it working.
        PJM

  3. First of all, i must say that i really love al the lessons (which i have followed from lesson 1 till now) and i really learned a lot. For installation on Ubuntu i used the descriptions on “http://vpython.org/contents/download_linux.html”, you really need to do step by step as described and this works fine. For installation of the serial communication library, i downloaded the exe file and opened it in wine to install. Now i am still looking on ow to install the visual library, because now, to run my code it crashes. I hope to find a solution very soon, so i can continue to follow the lessong. if anyone has a solution ….

  4. Thank for sharing these knowledge!
    Your tutorials are so cool and I have just started working on Python programming.
    Before that I work with C# programming and can you help me in Python programming :
    + I need a code that can automatically identify the COM port that connected to my computer.
    Thank a lot and hope your project about Space will be successful.

  5. Hello,

    I really like your walk through and tutorials in understanding more on the arduino.

    I’ve been following many of your videos for some time now, but could you do a request? Is there a video you can do on how to successfully run multiple tabs in the arduino IDE at once?

    For example, if i’m trying to run multiple sensors and each sensor has its own type of function. I can run these sensors individually, however trying to run them at once has proven difficult and not very many other tutorials are good at explaining this. Thank you so much

  6. I managed to get everything installed and working last night. The programs worked just fine except for one thing. In the Python shell, I was seeing a square box at the end of each line (after Mississippi. ), which I assume is the line \n character. Is there a way to not print this out?

    Thanks and great job with the tutorials!

  7. This is good information, but as a Mac user, I feel a bit left out. Python comes installed as part of OS X, but the general consensus is that it shouldn’t be used for anything (except perhaps some of the X-code stuff). Anyway – beating the bushes for some info, I found a couple of things that should help anyone trying to follow this on their Mac:

    1. Homebrew, and
    2. http://hackercodex.com/guide/python-development-environment-on-mac-osx/

    I’ll report back if and when I get through this. In the meantime, any comments or suggestions are appreciated.

  8. Hello! Thanks for this great tutorials! I have just started working with python, and I find it great that I can give some kick to the development of my ideas by using my arduino to gather data out of my sensors and being also able to process my data in an environment which is very close to MATLAB that I use for everyday life. I have just tried to implement the code for the first example, but for some reason I see no output on the terminal the software simply hangs without errors. The code is anyway correct, on what could this issue depend? How can I debug this?

    1. I have found out the problem, maybe this can come handy to somebody else with my same problem. The issue was that the script generating the counts on the Arduino, as shown in the tutorial, would not write an end of line character, so my readline() would not be able to read anything. By adding a “Serial.print(“\n”)” into the Arduino code, this will work.

  9. Hi Paul.
    Thank you for your excellent videos. You are good at explaining.
    A single comment:
    I kept getting error
    #SerialException: Could not open port ‘com7’: WindowsError (5,
    After a few attempts I found out it was because I had Arduino Serial Monitor open. Perhaps it might be helpful to others.
    I subscribed now your youtube channel and am excited to see the next video.

    Thank you

  10. Thank you !
    This is awesome. I was using Firmata and pyfirmata to control the Arduino. But could not get the ultrasonic sensor to work. I came across that website and now I have my solution.
    Thank you again.

  11. Nice tutorial series. One thing you might try, in python you can create a simpler while loop by:
    while 1:
    #do stuff

    Since the True keyword in python is 1, the while will always be true.

    1. Also, in python the () at the end of names indicates the object method is to be run. For example, you could write:
      myData = aduinoSerialData.readline

      This would actually set myData equal to the method itself, not run the code inside of the method.

  12. Great instructional programs. Thank you for your efforts. New to both the Arduino and Raspberry Pi. Therefore need to learn the basics quickly. So far the instructional books are of little value. Interested in Python of the Arduino. Would also like to know what program you are using to webcast the two camera shot with the screen shot. Also how do you get the circular cursor? The project I am working that uses the RPi and Arduino is a microscope stage controller. Located in Texas also.

  13. Thank you very much. the Article brought me to a new world and solve a major problem for me.
    I’m sure I’m not the only one who feels this way.

  14. Thank you Sir.

    you are very exceptional.
    really helped me to switch the program interface with python.
    respect all,
    is there a tutorial to read from python to arduino?

  15. Thank you for the quality videos! I’ve learned a lot and am trying things I thought would be to hard to implement. Worked through the Arduino lessons and have started the Python lessons. They are all great. Hoping my grand kids will get interested.
    Blessings!

  16. Hi,
    I tried to follow your tutorial on Python with Arduino. However, I am using a Mac computer and I get the following error message when I try to follow your example in lesson 2:
    “Traceback (most recent call last):
    File “Untitled”, line 1
    import serial #Import Serial Library
    ImportError: No module named serial”

    Obviously, the program cannot find library called “serial”.
    1) Where to I find this library for mac, and in which folder should the library folder be stored?
    2) What name should I give the serial port, instead of “Com11”, when I use a Mac?
    Best regards,
    Kenneth Lundkvist
    Sweden

Leave a Reply

Your email address will not be published. Required fields are marked *