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.

52 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. Hi Mr Peppers;
        First, Do you have an email address?
        I just started learning about Adruino and Raspberry PI the past 3 months. I got out of electronics almost 20 years ago and went back to college for a mathematics degree.
        I will explain more in my email to
        Can I use the Python code using the new version since they do not have the program available that you recommend in your video. I regained my interest in electronics with all you videos. I hope they do not send these videos over sea too? Thank you.!

        1. Are you talking about python 2.7? I am pretty sure it is still available for download. There are things different in python 3.X so I am staying with 2.7

  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.


    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.

  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 “”, 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. Sir,
    Thank you so much for such a Great Tutorial. I love all the lessons , its nice and friendly.

  5. 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.

  6. 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

  7. 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!

  8. 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

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

  9. 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.

  10. 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

  11. 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.

  12. 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.

  13. 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.

  14. 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.

  15. Thanks a lot. It was really helpful. Feels like getting into the new dimension 😀 😉

  16. 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?

  17. 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.

  18. 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

    1. I got also the same kind of error but on the windows computer. I had two versions of pythons 2.7 and 3.6 on my computer installed earlier. I uninstalled python 3. 6 and then downloaded the pySerial 2.7 package again. Now the python compiles properly the script on lesson 2 and no more error report such as
      : No module named serial.

    2. Hi Kenneth,
      Try to install the PIP s/w using this YouTube address:
      later use the following line on the terminal to install the pyserial library:
      sudo pip install pyserial
      I’ve succeeded to overcome the serial module problem but still got the com11 problem as I my computer is Mac as yours
      Good Luck

  19. adding
    “from time import sleep”
    to the top of the code and
    sleep(0.25) OR sleep(0.5)
    under the if statement will DRAMATICALLY reduce Pi’s CPU load and heat output from 25% to less than 1%
    I have a mega blinking the pin 13 LED once a second with 50% duty. Programmed it from inside the Pi 3 using arduino IDE from repo (junk! – have to keep unplugging and replugging to different USB port to get avrdude to not timeout)
    My .py program uses the sleep(0.25) #250mS sleep to reduce CPU usage and modified the serial read to use ‘/dev/ttyACM1’, 9600 as this is the current USB port my MEGA2560 is connected to. Works great-er after adding in the sleep(sec) line.
    Great series!

  20. Hi Paul,
    I installed the software like you said on my windows10 computer but it does not work.
    The Vidle for python goes not open. On my old lapttop with windowsXP does het work. What seems to be the matter.
    greetings from the netherlands from Douwe Bakker

  21. Hello,

    My name is chris and I am a middle school science teacher on Long Island. I hold a degee in physics and simply decided that my students MUST be exposed to the engineering aspect of the STEM/STEAM movement. I’ve been using physical computing by way of the arduino to monitor variables in our classroom’s vertical hydroponic system. I have decided to award digital badges that follow the sequence of lessons that you mapped out for the arduino before assigning my students to teams that will choose components and write code to monitor air and water temps, humidity, pH, water levels, security systems, and time elapsed photography. They are even using 3D printing to design housings for their sensors. Your website has been a revelation!! I just wanted to say thank you for the inspiration to pass this along to the new crop of engineers out there.

    My biggest curiousity is how to use Python running on a Pi to help student visualize data. The fact that you have tutorials on that, the Linux environment, and 3D printing is like we are thinking the exact same way!! The last piece I am looking for is being able to serve the data to the web on student designed widgets that can be monitored from a mobile device. Any suggestions here? I’ve been using Cayenne and Blynk which look great, but sometimes connection is unreliable.

    Thank you again so so much and any advice you could offer would be great. The link I am attaching below is to a proof of concept for my web serving idea.

  22. Hi,
    Thanks for you videos. I am really enjoying them and learning a lot!
    I had a question about arduino and python #2. When you run the phyton script, the counter starts at “0 Mississippi”. You started the arduino stript a while ago, so I expected that to have been counting in the backgroud while we were writing the phyton script. Does the python program somehow restart the arduino script? Is that specified?


  23. having problems with the script
    this is what I get when I run the script

    Traceback (most recent call last):
    File “C:/Users/Jose/Desktop/”, line 1, in
    import serial #Import Serial Library
    ModuleNotFoundError: No module named ‘serial’

  24. Thank you Paul, for all the great work you are doing.

    Just in case anyone facing issue regarding port not accessible, try following:
    a) Close Arduino IDE in case its open as it might be holding on to the port. (disconnect Arduino wire and reconnect)
    b) Enable/Disable port once
    c) make sure you have admin rights on system

  25. Hi Paul,

    Have really enjoyed your tutorials. I am beginning the Python for Arduino section now after completing earlier lessons. Have seen that Python allows bypassing of Arduino Processing app, which I had used previously for ECG recording. But I am not quite sure if Python fully allows elimination of Processing. Using AD8232 ECG from Sparkfun, the sketch gives numerical output over serial monitor and only with Processing is graphical output (the ECG tracing) available. So Processing seems to do more than just transmit numerical data from Serial Monitor. Can I do the same with Python? (Hope I’ve asked this in a way that is understandable!)

    Thanks once more for the great lessons!


  26. Im glad I was able to follow you until this point.

    Im using Debian, and Eclipse as IDE, so some things are different.

    But I have to say, very well done proffessor.

  27. Hi,
    I’ve just started compiling the python program shown in the tutorial. While running the program it shows the following error

    Traceback (most recent call last):
    File “Untitled”, line 1
    import serial #Import Serial Library
    ImportError: No module named serial

    Can you please help me

  28. OMG!!!!!!!!!!! This is crazy!!!!!!!! As a python user, I know how many incredible libraries python has, and as I can see, as I can fetch the data from the Arduino sensors to Python, The amazingly incredible door is now open. Wow. It is the coolest stuff this year I’ve seen lol

  29. + For other people who use Python3

    I tried with python3, and it worked 🙂 Don’t worry to use Python 3.
    The only thing you need to note is this below.

    myData = ser.readline()
    myData = myData.decode(‘utf-8’)

    – After ‘ ser.readline() ‘, you must decode it with the second line of the code 🙂 Then everything will go fine

Comments are closed.