BakedPi - See how hot your Raspberry Pi is with LedBorg

This is an old driver based LedBorg script
The new driver free example which replaces this one can be found here.

We want to know how hot our Raspberry Pis are getting when they do their thing, and what better way then with LEDs?

We decided to use an LedBorg to show how hot the processor is by the following guide:
Colour displayed is the range from a minimum temperature (0%, Blue) to a maximum temperature (100%, Red).
0% is used when below range, 100% is used when above range

<=11% <=22% <=33% <=44% <56% <67% <78% <89% >=89%

The result was BakedPi.py, a Python script which reads the current processor temperature and controls an LedBorg appropriately.

Our example uses values of tempLow (0%) and tempHigh (100%) which work well when watching the Raspberry Pi warm up from boot, you will probably want to change these to show a better temperature range!

Here's the code, you can download the BakedPi script file as text here
Save the text file on your pi as BakedPi.py
Make the script executable using
chmod +x BakedPi.py
and run using
sudo ./BakedPi.py

#!/usr/bin/env python
# coding: latin-1

# Import libary functions we need
import time

# Make a function to set the LedBorg colour
def SetColour(colour):
    LedBorg=open('/dev/ledborg','w')
    LedBorg.write(colour)
    LedBorg.close()

# Set up our temperature chart, from cool to hot
colours = ['002', '012', '022', '021', '020', '120', '220', '210', '200']


# 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 = 40000                                        # 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)
        position = int(position * len(colours))
        if position < 0:
            position = 0
        elif position >= len(colours):
            position = len(colours) - 1
        # Set the relevant colour
        SetColour(colours[position])
        # 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'
    SetColour('000')
Subscribe to Comments for &quot;BakedPi - See how hot your Raspberry Pi is with LedBorg&quot;