When you use a Raspberry PI, it is important to monitor its temperature. It should no way exceed 85 Degree centigrade. Years ago, I did a project with Raspberry PI, an LCD and a few jumper wires. My project showed the Raspberry PI temperature on the LCD display.
This project can be helpful for those you have begun to learn Raspberry Pi.
Components:
Raspberry PI 3B+ x 1
Breadboard x 1
Connection:
Raspberry Pi | LCD |
VCC | VCC, LED+, 1st pin of 10K variable resistor |
GND | GND,LED-,2nd pin of 10K variable resistor |
V0 connected to the common pin of the 10K variable resistor | |
37 | RS, R/W |
35 | E |
33 | D4 |
31 | D5 |
29 | D6 |
23 | D7 |
Code:
At first, I installed pip
sudo apt-get install python-pip
Then I installed RPLCD.py library
sudo pip3 install RPLCD
I installed the RPLCD.py library.
If you type the following code in Raspberry Pi command prompt, it will show you the temperature.
/opt/vc/bin/vcgencmd measure_temp
We will run this code in our python script and it will show us the temperature in LCD.
import os
import time
from RPLCD import CharLCD
from RPi import GPIO
lcd = CharLCD(numbering_mode=GPIO.BOARD, cols=16, rows=2, pin_rs=37, pin_e=35, pins_data=[33,31,29,23])
def measure_temp():
temp = os.popen("vcgencmd measure_temp").readline()
print (temp)
temp=temp.replace("'C","")
#return (temp.replace("temp","Temp"))
return(temp)
while True:
lcd.clear()
lcd.write_string("CPU ")
lcd.write_string(measure_temp())
lcd.cursor_pos = (0,13)
lcd.write_string(chr(223)+"C")
time.sleep(1)