Tuesday, December 10, 2013

Live plotting of data from serial port using python, pyserial and pyqtgraph

In preparation of a radio-downlink of the rocket to a ground station, using nrf24l01+ modules, I tried to liveplot data from the acceleration sensor on the PC via USB-serial.
Apparently, this was much more trouble than I thougth, but with a lot of help and stealing I finally got it.

This is the Arduino code!
This is the python code!

And here is what it does!

Moving stuff!

Is this good?

Well, I'm quite happy with this working, almost gave up. Speed is okay-ish, but there is some kind of bottleneck on the serial port. The example code which this is based in runs on 300fps with data generated by pythons random module, adding the reading from serial data drops the fps to a mere 10. On the Arduino-side, I use a delay of 100ms, meaning 10Hz, and when I try to go faster, the live plot becomes a lag plot, with a delay between input and display of a couple of seconds. This is sad because with 10Hz you really can't see any vibrations or shocks.
I will have to investigate in the serial connection and what it actually does to make that faster.

On the rocket side I terribly crashed my (n)th attempt on building a reliable parachute ejection system and the parcel service lost my order of new stuffs to build the (n+1)th prototype. The next one will work. Me hopes.