YodaVonBeck
Posts: 38
Joined: Wed Mar 16, 2016 10:03 am

Plotting Grove Pi sensor data using matplotlib

Sat May 05, 2018 12:23 pm

I have a Grove Pi sitting on top of my Pi and 2 sensors hooked up.
One that measures the temperature and humidity and one that measures dust.

I would like to plot the data, but cant seem to get my head around how to use matplotlib.

This is my code, which prints data and shows on a small LCD:

Code: Select all

import time
import grovepi
import atexit
from grove_rgb_lcd import *

atexit.register(grovepi.dust_sensor_dis)


sensor = 7
grovepi.dust_sensor_en()

while True:
        try:


                #Gather data from sensor
                [new_val,lowpulseoccupancy] = grovepi.dustSensorRead()
                [temp,hum] = grovepi.dht(sensor,0)

                if new_val:
                
                        #Print data 
                        print ("temp =", temp, "C & Humidity =", hum,"% & Dust consentrantion =",lowpulseoccupancy)

                        #Prepare data for use on LCD
                        t = str(temp)
                        h = str(hum)
                        d = str(lowpulseoccupancy)

                        #Set LCD color
                        setRGB(0,128,64)
                        setRGB(0,255,0)
                        #Print on LCD
                        setText("T:" + t + "C" + " H:" + h + "%" + " Dust:" + d + "ppm")

                #Wait 5 seconds
                time.sleep(5)
                
        except (IOError,TypeError) as e:
                print("Error")
Can you help with the code needed to plot a graph for just one of the inputs?

Return to “Advanced users”