One of the things we are using the Raspberry Pi on Project Curacao for is to generate graphs. Yes, We know we could ship the data to another server and generate the graphs there, but since we have a nice linux platform, we decided to make the graphs on site. Then we ship the graphs both to a webpage and also over to the RasPiConnect directory for display on the RasPiConnect App (www.milocreek.com). Here’s a picture of the embedded graph (in RasPiConnect):
The RasPiConnect Local.py code for a graph follows:
Note that if you want to use a button to select different type of graphs for the same RasPiConnect control, you write the graph name to a file and the read the file to get what graph to display. Make sure you assign the Web Control to refresh when you push the button. Then you get an immediate response. You can select a different graph by using a feedback control button to write that file (that contains the graph name) and cycle through graphs (see my video on this blog for an example) as below:
# FB-11 – change the graph display
if (objectServerID == “FB-11”):
#check for validate request
# validate allows RasPiConnect to verify this object is here
One good thing about running tasks like this in another thread, is that a hang in one of the threads does not stop the whole system. Just that thread. Here is the example matplotlib code and graph for one of the graphs (including the call to MySQL to get the data). We are using the Solar/Wind line to show which power source is selected. Reg Wind Volt gives the voltage on the regulated side of the DC/DC 12V – 6V Buck converter (fed to the solar power charging circuitry) and Unreg Wind Volt is on the Wind Turbine side of the converter. We choose to use just points because of the intermittent nature of the wind. See the post on the wind storm we had a couple of weeks ago. This was the graph generated after a couple of trips in the car with various wind turbines.
# solar wind graph generation
# filename: solarwindgraph.py
# Version 1.4 01/12/14
#
# contains graphing routines
#
#
import sys
import time
import RPi.GPIO as GPIO
import gc
import datetime
import matplotlib
# Force matplotlib to not use any Xwindows backend.
4 Trackbacks / Pingbacks
Comments are closed.