Plotting live serial input from arduino/microcontroller using python matplotlib
Hello all, I’m writing once again after almost six months. As the title of this post suggests I’ll be writing about plotting the live input data from a serial device using python. This data can be any input data that is comming through a serial port from any device such as a microcontroller, Arduino, any usart based wireless module such as HC-05 or HM-10 etc.
The reason I am writing this post is during past three or four months I did few small projects for Slightgen. where in most of the projects one of the main task was to plot the data that is coming from a microcontroller over serial port in the realtime.
Now to plot this data is certainly not a big thing but it becomes really hectic when you have to do the same thing over and over again. I searched if there is any python library that lets me do that but found none. So once the projects were done I decided to write one so that the next time I won’t have to write the long code again.
This way I started writing Plotcat. I just wanted to create a tool where all I have to do is give logic to get the data from serial device and the tool will take care of all the plotting.
Now Using plotcat now I can do that.
Sample code for using plotcat ca be found here.
there is also a script live_plot.py with plotcat.
live_plot.py handles a lots of exceptions and lets you
- multiple subplots inside the figure.
- set max and min limit for y axis.
- set how many samples to be plotted.
for more details take a look at the wiki
Once everything was done Chandan taught me how to create .spec file and rpm packaging for python.
plotcat is also hosted on copr at https://copr.fedorainfracloud.org/coprs/girish946/plotcat/
you can install plotcat on fedora 22 and above.
$ dnf copr enable girish946/plotcat $ dnf install python-plotcat