Plt.ylabel('Humidity (g/m^3)') #label second y axis Plt.plot(humidity, 'g*-', label='Humidity (g/m^3)') #plot humidity data Plt.grid(True) plt.ylim(45,70) #Set limits of second y axis Plt.legend(loc='upper center') #plot the legend plt.subplot(2,1,2) # Height,Width,Second plot Plt.plot(tempC,'b^-', label='Degree C') #plot the temperature Plt.title('Real Time DHT11 Data') #Plot the title Plt.subplot(2,1,1) #Height,Width,First plot plt.ylim(22,34) #Set y min and max values Import numpy # Import numpy import matplotlib.pyplot as plt #import matplotlib library from drawnow import * tempC = #Empty array humidity = arduino = serial.Serial("/dev/ttyACM0", 115200) #Serial port to which arduino is connected and Baudrate plt.ion() #Tell matplotlib you want interactive mode to plot live data def CreatePlot(): #Create a function that makes our desired plot
#RASPBERRY PI INSTALL MATPLOTLIB SERIAL#
To plot humidity and temperature separately import serial # import Serial Library If(count>20): #only take last 20 data if data is more it will pop first tempC.pop(0) humidity.pop(0)Ģ. While (arduino.inWaiting()=0): #Wait here until there is data pass #do nothing arduinoString = arduino.readline() dataArray = arduinoString.split(',') #Split it into an array temp = float( dataArray) hum = float( dataArray) tempC.append(temp) humidity.append(hum) drawnow(makeFig) Plt2.legend(loc='upper left') while True: # While loop that loops forever t_ylabel('Humidity') #label second y axis plt2.ticklabel_format(useOffset=False) Plt.ylim(50,70) #Set limits of second y axis ot(humidity, 'g*-', label='Humidity') #plot pressure data Plt.ylim(20,30) #Set y min and max values plt.title('Real Time DHT11 Data') #Plot the title plt.grid(True) #Turn the grid on plt.ylabel('Temp C') #Set ylabel plt.plot(tempC,'b^-', label='Degree C') #plot the temperature plt.legend(loc='upper right') #plot the legend plt2=plt.twinx() #Create a second y axis Import numpy # Import numpy import matplotlib.pyplot as plt #import matplotlib library from drawnow import * tempC = #Empty arrayhumidity = arduino = serial.Serial("/dev/ttyACM0", 115200) plt.ion() # interactive mode to plot live datacount = 0 def makeFig(): #Create a function that makes our desired plot Plot data in one graph import serial # import Serial Library Next step is to write a python script for that you can use any editor to write it.ġ. To install it use command sudo pip install drawnow Drawnow is generally used to see the results after each iteration as we use "imshow" in MATLAB. To install it use command sudo pip install matplotlibĤ. Matplotlib is a 2D plotting library which provides an object-oriented API for embedding plots into applications using general-purpose GUI toolkits like Tkinter, wxPython, Qt, or GTK+. Or if you wanna use apt package sudo apt install python-numpyģ.
Here I am installing using pip for that first we have to install pip sudo apt-get install python-pip python-dev build-essential sudo pip install numpy You can install it in many ways either use apt package or pip. It also provides simple routines for linear algebra and FFT (Fast Fourier Transform) and sophisticated random-number generation. Numpy is a package that defines a multi-dimensional array object and associated fast math functions that operate on it. PySerial is a library which provides support for serial connections over a variety of different devices.
#RASPBERRY PI INSTALL MATPLOTLIB CODE#
Once code is uploaded, Install some libraries so that we can plot graph of data which is coming serially from Arduino Uno.ġ. Once sketch is compiled, select board and port and upload it. The following program is a simple program that will have the Arduino count and send the data to the serial port.Īrduino Code #include "DHT.h" float tempC // Variable or holding temp in C float tempF // Variable for holding temp in F float humidity //Variable for holding pressure reading #define DHTPIN 7 // what digital pin we're connected to #define DHTTYPE DHT11 // DHT 11 //#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321 //#define DHTTYPE DHT21 // DHT 21 (AM2301) // Initialize DHT sensor. Firstly we need a simple program to get the Arduino sending data over the serial port. Now, lets get python and Arduino talking together.