GPIO not working

Hello there,
I am trying to use the RPi.GPIO to enable a LED on my board. I have added the
RUN pip install smbus2 paho-mqtt requests RPi.GPIO
But when I add in my code import RPi.GPIO as GPIO it returns

sensor    File "/usr/lib/python3/dist-packages/RPi/GPIO/__init__.py", line 23, in <module>
sensor      from RPi._GPIO import *
sensor  ModuleNotFoundError: No module named 'RPi._GPIO'

I’ve tried to make it work from a simple python script:

#!/usr/bin/python3

import RPi.GPIO as GPIO

Led_Pin = 20

GPIO.setmode(GPIO.BOARD)
GPIO.setup(Led_Pin, GPIO.OUT)
GPIO.output(Led_Pin, 0)

But also altering the Sensors block from BalenaHub and in both cases it fails on import RPi.GPIO as GPIO

Hi there, can you share which base image you were using and for which device type so we can try to reproduce? I would try using pip3 instead of pip but depending on your base image they may be the same.

In the case of the sensors block, can you describe the exact changes you made to the Dockerfile and python script when it failed?

Hi again, did you manage to get your application working?

Hello @pipex
I did not resolve it… working on it :frowning:

Hello @pipex,
I did resolve this from led-alerter-code-fails-to-push-to-app. It was that for some reason it does not work if you include in the install_packages the rpio.gpio. I removed it from the Dockerfile.template and it worked as it was supposed to.

Good to hear that you were able to make it work, feel free to contact us in case you have more questions.

1 Like