1

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 module\nInstall with: sudo pip install psutil")

try:
  import blinkt
except ImportError:
  exit("This script requires the blinkt module\nInstall 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.

6
  • Have you tried your setup with the simple blinkt demo program at pinout.xyz/pinout/blinkt? Commented Jun 19, 2024 at 10:41
  • Yes, that example and others yields the same error I posted above only on the pi 5 not pi 4 Commented Jun 20, 2024 at 15:53
  • This error: Traceback (most recent call last): File "//./test.py", line 10, in <module> show() File "/usr/local/lib/python3.9/dist-packages/blinkt.py", line 76, in show GPIO.setup(DAT, GPIO.OUT) RuntimeError: Mmap of GPIO registers failed Commented Jun 20, 2024 at 15:56
  • The other difference between the pi 3 and 4 is the pi 5's are running Bookworm: Debian GNU/Linux 12 (bookworm) 6.6.20+rpt-rpi-2712 Commented Jun 20, 2024 at 16:25
  • The fact that you get the same error with the demo program is very useful. It gets rid of a mass of possibilites. Why not rewrite your question giving just the code from the demo program, and quoting the error message that you get from it. Commented Jun 20, 2024 at 17:40

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.