Ticker

6/recent/ticker-posts

Display Raspberry Pi CPU temperature graphically, using Python 2 with Matplotlib and drawnow

Python 2 example to display Raspberry Pi CPU temperature graphically, with Matplotlib and drawnow.



This exercise work on Python 2 and need matplotlib and drawnow, refer to "Install numpy, matplotlib and drawnow for Python 2".

plotTemp.py
import os
import matplotlib.pyplot as plt
from drawnow import *

tempC = []

plt.ion()
cnt=0

def plotTempC():
plt.ylim(20,80)
plt.title('Raspberry Pi core temperture')
plt.grid(True)
plt.ylabel('Temp C')
plt.plot(tempC, 'rx-', label='Degrees C')
plt.legend(loc='upper right')

#pre-load dummy data
for i in range(0,26):
tempC.append(0)

while True:

ostemp = os.popen('vcgencmd measure_temp').readline()
temp = (ostemp.replace("temp=", "").replace("'C\n", ""))
print(temp)
tempC.append(temp)
tempC.pop(0)
drawnow(plotTempC)
plt.pause(.5)





For Python 3:

Matplotlib for Python 3 is not support currently. I tried to build it from source (refer "Install numpy, matplotlib and drawnow for Python 2" and "Fail to build matplotlib for Python3, run on Raspberry Pi 2"), but nothing plotted while running.



Similar example without using drawnow, "Plot RPi 2 core temperature using Python 2 and matplotlib.pyplot".

إرسال تعليق

0 تعليقات