How hot is my Pi?
If you have installed the old LedBorg driver version see here for instructions on updating.
We want to know how hot our Raspberry Pis are getting when they do their thing, and what better way then with LEDs?
This is an updated version of the old BakedPi script which uses the new driver free LedBorg code.
As a side benefit the extended colour range allows us to see what the temperature is like more clearly over larger ranges.
The colour displayed starts at minimum temperature represented by blue, 50% by green, and maximum temperature by red:
You can download the code directly to your Raspberry Pi using:
cd ~/ledborg
wget -O HowHotIsMy.py http://piborg.org/downloads/HowHotIsMy.py.txt
Or save the text file from the link on your Raspberry Pi as HowHotIsMy.py
Make the script executable using
chmod +x HowHotIsMy.py
and run using
sudo ./HowHotIsMy.py
#!/usr/bin/env python # coding: latin-1 # Import library functions we need import time import wiringpi2 as wiringpi wiringpi.wiringPiSetup() # Setup software PWMs on the GPIO pins PIN_RED = 0 PIN_GREEN = 2 PIN_BLUE = 3 LED_MAX = 100 wiringpi.softPwmCreate(PIN_RED, 0, LED_MAX) wiringpi.softPwmCreate(PIN_GREEN, 0, LED_MAX) wiringpi.softPwmCreate(PIN_BLUE, 0, LED_MAX) wiringpi.softPwmWrite(PIN_RED, 0) wiringpi.softPwmWrite(PIN_GREEN, 0) wiringpi.softPwmWrite(PIN_BLUE, 0) # A function to set the LedBorg colours def SetLedBorg(red, green, blue): wiringpi.softPwmWrite(PIN_RED, int(red * LED_MAX)) wiringpi.softPwmWrite(PIN_GREEN, int(green * LED_MAX)) wiringpi.softPwmWrite(PIN_BLUE, int(blue * LED_MAX)) # A function to turn the LedBorg off def LedBorgOff(): SetLedBorg(0, 0, 0) # Setup for processor monitor pathSensor = '/sys/class/thermal/thermal_zone0/temp' # File path used to read the temperature readingPrintMultiplier = 0.001 # Value to multiply the reading by for user display tempHigh = 60000 # Highest scale reading tempLow = 30000 # Lowest scale reading interval = 1 # Time between readings in seconds try: # Make sure we are using floats tempHigh = float(tempHigh) tempLow = float(tempLow) while True: # Read the temperature in from the file system fSensor = open(pathSensor, 'r') reading = float(fSensor.read()) fSensor.close() # Pick the relevant colour position = (reading - tempLow) / (tempHigh - tempLow) if position < 0.0: # Below 0%, use blue red = 0.0 green = 0.0 blue = 1.0 elif position <= 0.5: # Between 0% and 50%, slide between blue and green red = 0.0 green = position * 2.0 blue = 1.0 - green elif position <= 1.0: # Between 50% and 100%, slide between green and red red = (position - 0.5) * 2.0 green = 1.0 - red blue = 0.0 else: # Above 100%, use red red = 1.0 green = 0.0 blue = 0.0 # Set the relevant colour SetLedBorg(red, green, blue) # Print the latest reading print '%02.3f' % (reading * readingPrintMultiplier) # Wait a while time.sleep(interval) except KeyboardInterrupt: # CTRL+C exit, turn off the LedBorg print 'Terminated' LedBorgOff()