1

Try to run this Code in one of my Docker Container on Raspberry Pi 5:

import board
import digitalio
import busio
print("Hello, blinka!")
pin = digitalio.DigitalInOut(board.D4)
print("Digital IO ok!")
i2c = busio.I2C(board.SCL, board.SDA)
print("I2C ok!")
spi = busio.SPI(board.SCLK, board.MOSI, board.MISO)
print("SPI ok!")
print("done!")

I am currently working on a project based on a Raspberry Pi 5. I have installed Docker and Docker-Compose on it to build my containers. One container contains Node-Red, one Samba Share and another one a websocket server. All containers work as they should. Now to my actual problem. I want to communicate with DS3502 via I2C in the container of the websocket server. To do this, I followed the instructions for installing Blinka at the following link:

https://learn.adafruit.com/circuitpytho ... spberry-pi

I first did this on the host and was able to get the desired output:

(env) admin@bero-raspberrypi:~ $ python blinkatest.py
Hello, blinka!
Digital IO ok!
I2C ok!
SPI ok!
done!

When I do the same on my websocket server, I get the following error:

root@3fa8c9358df0:/app# python3 blinkatest.py
Traceback (most recent call last):
File "/app/blinkatest.py", line 1, in
import board
File "/usr/local/lib/python3.10/site-packages/board.py", line 45, in
from adafruit_blinka.board.raspberrypi.raspi_4b import *
File "/usr/local/lib/python3.10/site-packages/adafruit_blinka/board/raspberrypi/raspi_4b.py", line 6, in
from adafruit_blinka.microcontroller.bcm2711 import pin
File "/usr/local/lib/python3.10/site-packages/adafruit_blinka/microcontroller/bcm2711/pin.py", line 5, in
from RPi import GPIO
ModuleNotFoundError: No module named 'RPi'

Maybe someone can help me with this problem, because unfortunately I can't help myself at the moment.

admin@bero-raspberrypi:~ $ docker exec -it websocket-server bash
root@c14213fc6074:/app# ls /dev/i2c* /dev/spi*
/dev/i2c-1 /dev/i2c-13 /dev/i2c-14 /dev/spidev0.0 /dev/spidev0.1 /dev/spidev10.0
root@1d4e004fae1e:/app# i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- 28 29 -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

Only the server.py script is executed, as this uses websocket messages to control or call the other scripts or the functions they contain. For example, the DS3502 should ultimately be controlled in this way. Currently, however, the problem is to control them at all from the container.

Here is the Dockerfile and the docker-compose.yml

FROM python:3.10-slim

RUN apt-get update && apt-get install -y gcc git i2c-tools libgpiod-dev python3-libgpiod && pip install --upgrade pip gpiod websockets numpy pyserial && apt-get clean && rm -rf /var/lib/apt/lists/*

RUN pip install --no-cache-dir --upgrade pip setuptools

RUN pip install --no-cache-dir adafruit-blinka adafruit-python-shell

WORKDIR /app

COPY server.py /app/ COPY led.py /app/ COPY distance.py /app/ COPY script.py /app/ COPY sensor.py /app/ COPY poti.py /app/ COPY blinkatest.py /app/ COPY gsv8py3pi /app/gsv8py3pi/

ENV PYTHONPATH="${PYTHONPATH}:/app/gsv8py3pi" ENV PYTHONUNBUFFERED=1 ENV BLINKA_FORCEBOARD=RASPBERRY_PI_5

CMD ["python", "server.py"]

version: '3.10'

services:

node-red:
image: nodered/node-red
container_name: node-red
ports:
- "1880:1880"
networks:
- network
volumes:
- /home/admin/bero_core/data/node_red_data:/data

samba:
image: dperson/samba
container_name: samba-share
ports:
- "137:137"
- "138:138"
- "139:139"
- "445:445"
volumes:
- /home/admin/bero_core:/mount
networks:
- network
environment:
- USERID=1000
- GROUPID=1000
command: -s "bero;/mount;yes;no;yes"

python_websocket:
build: /home/admin/bero_core/websocket_server
privileged: true
container_name: websocket-server
networks:
- network
ports:
- "8765:8765"
volumes:
- /home/admin/bero_core/websocket_server:/app
devices:
- "/dev/gpiochip0:/dev/gpiochip0"
- "/dev/i2c-1:/dev/i2c-1"
- "/dev/spidev0.0:/dev/spidev0.0"
- "/dev/spidev0.1:/dev/spidev0.1"
- "/dev/ttyACM0:/dev/ttyACM0"
environment:
- PYTHONBUFFERED=1

networks:
network:
driver: bridge
TheMrGack
  • 11
  • 1

1 Answers1

0

You have a library written for Raspberry Pi 4 (or earlier) using RPi.GPIO, on a Raspberry Pi 5. Even if you try to force the board as:

ENV BLINKA_FORCEBOARD=RASPBERRY_PI_5

The RPi.GPIO library is not compatible with the Raspberry Pi 5 due to significant changes in the GPIO hardware architecture. The Raspberry Pi 5 utilizes a separate RP1 chip for GPIO control, which differs from previous models. Consequently, software libraries designed for earlier Raspberry Pi models, such as RPi.GPIO, do not function on the Raspberry Pi 5.

You'll have to modify the source code to make it work or use gpiod.

You may be saying: But I2C works, and that is on the GPIO bus. That is true, the i2c pins are on the GPIO header, but they are on a separate chip, on its own bus.

MatsK
  • 2,882
  • 3
  • 17
  • 22