Python with Arduino LESSON 11: Plotting and Graphing Live Data from Arduino with Matplotlib

We now have all the pieces put together to allow us to plot live data from the Arduino. If you have kept up with the earlier lessons, you will now have everything you need. If you have not done the earlier lessons, make sure you have python 2.7, vPython and pySerial installed from Python with Arduino LESSON 2.  Make sure you have installed matplotlib (Python with Arduino LESSON 7), and install drawnow (Python with Arduino LESSON 10). Also, you need to build the BMP180 circuit and get the arduino programmed up as explained in Python with Arduino LESSON 9. With this business taken care of, you are now ready to start plotting live data.

Pressure Data
This chart shows live pressure and temperature data being plotted in real time

We are using the Adafruit BMP180 pressure sensor.  We showed how to hook it up and program it in LESSON 9. As a reminder, we are using this code for the arduino. LESSON 9 explained in detail how the code works.

The video in this lesson above explains step-by-step how to develop the code on the Python side, and how matplotlib and drawnow work together to make live graphs and plots of data streaming from the arduino in real time. The code below is what we developed in the video. Do not simply cut and paste this code, but make sure that you understand it so you are able to create your own live graphing programs from scratch. If you are in my class, you will be required to be able to develop live graphing code like this from scratch, so don’t take a shortcut and copy and paste.

You should be seeing data like the graph on the top of this lesson. You will probably need to adjust your y-axis scale parameters in Python to ensure the scale is suitable for the data you are taking. If your chart is blank, likely your y-scales are not right for your data measurements.