I have a Docker container that will display the CPU load for the Kubernetes cluster on the blinkt LED if they are present for that node. It works fine on a Pi 3B and 4 but I just got some Pi 5’s and the container is failing with this error on start:
Traceback (most recent call last):File "//./cpuload.py", line 33, in <module>blinkt.show()File "/usr/local/lib/python3.9/dist-packages/blinkt.py", line 76, in showGPIO.setup(DAT, GPIO.OUT)RuntimeError: Mmap of GPIO registers failed
Here is the Docker file that I am using and works fine on the Pi 4 for example:
FROM balenalib/raspberrypi4-64-debian-node
RUN apt-get update -qy && apt-get install -qy
gcc
python3-dev
pip
python3
python3-rpi.gpio
RUN pip install --upgrade pip setuptools
RUN pip install psutil blinkt
COPY src/ .
CMD [ "python3", "./cpuload.py" ]
Here is the python code for the cpuload.py:
#!/usr/bin/env python
import time
import os.path
import signal
from os import path
from sys import exit
def sigterm_handler( _signo, _stak_frame ):
for x in range(blinkt.NUM_PIXELS):
blinkt.set_pixel(x, 0, 0, 0)
sys.exit(0)
signal.signal(signal.SIGTERM, sigterm_handler)
try:
import psutil
except ImportError:
exit("This script requires the psutil modulenInstall with: sudo pip install psutil")
try:
import blinkt
except ImportError:
exit("This script requires the blinkt modulenInstall with: sudo pip install blinkt")
blinkt.set_clear_on_exit()
blinkt.set_brightness(0.2)
while True:
for x in range(blinkt.NUM_PIXELS):
blinkt.set_pixel(x, 0, 0, 0)
blinkt.show()
if path.exists("/home/pi/.BLINK"):
v = psutil.cpu_percent() / 100.0
if v > 0.11 or (v > 0 and v < 0.11):
blinkt.set_brightness(0.1)
blinkt.set_pixel(0, 0, 128, 0)
if v > 0.22 or (v > 0.11 and v < 0.22):
blinkt.set_brightness(0.2)
blinkt.set_pixel(1, 0, 128, 0)
if v > 0.33 or (v > 0.22 and v < 0.33):
blinkt.set_brightness(0.3)
blinkt.set_pixel(2, 0, 128, 0)
if v > 0.44 or (v > 0.33 and v < 0.44):
blinkt.set_brightness(0.4)
blinkt.set_pixel(3, 255, 215, 0)
if v > 0.55 or (v > 0.44 and v < 0.55):
blinkt.set_brightness(0.5)
blinkt.set_pixel(4, 255, 215, 0)
if v > 0.66 or (v > 0.55 and v < 0.66):
blinkt.set_brightness(0.6)
blinkt.set_pixel(5, 255, 215, 0)
if v > 0.77 or (v > 0.66 and v < 0.77):
blinkt.set_brightness(0.7)
blinkt.set_pixel(6, 255, 0, 0)
if v > 0.88:
blinkt.set_brightness(0.8)
blinkt.set_pixel(7, 255, 0, 0)
blinkt.show()
time.sleep(0.01)
I understand from reading some posts that somethings have changed on the GPIO but not entirely sure how to fix it, another Python GPIO library?
I have tried it with Pi 3 and Pi 4 and work fine. Above is the error message on the Pi 5 from the Docker container.