# GPIO not working

**URL:** <https://forums.balena.io/t/gpio-not-working/335248>\
**Category:** balenaOS\
**Tags:** raspberrypi3\
**Created:** [July 5, 2021, 9:00am UTC](https://forums.balena.io/t/gpio-not-working/335248 "2021-07-05T09:00:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![gmav](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/gmav/32/6219_2.png) [@gmav](https://forums.balena.io/u/gmav)\
**Post date:** [July 5, 2021, 9:00am UTC](https://forums.balena.io/t/gpio-not-working/335248/1 "2021-07-05T09:00:00Z")

</div>

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

```auto
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:

```auto
#!/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`

---

<div class="post-metadata">

**Author:** ![klutchell](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/klutchell/32/861_2.png) [@klutchell](https://forums.balena.io/u/klutchell)\
**Post date:** [July 5, 2021, 7:14pm UTC](https://forums.balena.io/t/gpio-not-working/335248/2 "2021-07-05T19:14:15Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![pipex](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/pipex/32/4840_2.png) [@pipex](https://forums.balena.io/u/pipex)\
**Post date:** [July 8, 2021, 9:05pm UTC](https://forums.balena.io/t/gpio-not-working/335248/4 "2021-07-08T21:05:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![gmav](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/gmav/32/6219_2.png) [@gmav](https://forums.balena.io/u/gmav)\
**Post date:** [July 9, 2021, 1:44pm UTC](https://forums.balena.io/t/gpio-not-working/335248/6 "2021-07-09T13:44:56Z")

</div>

Hello @pipex  
I did not resolve it… working on it ☹

---

<div class="post-metadata">

**Author:** ![gmav](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/gmav/32/6219_2.png) [@gmav](https://forums.balena.io/u/gmav)\
**Post date:** [July 13, 2021, 1:12pm UTC](https://forums.balena.io/t/gpio-not-working/335248/7 "2021-07-13T13:12:25Z")

</div>

Hello @pipex,  
I did resolve this from [led-alerter-code-fails-to-push-to-app](https://forums.balena.io/t/led-alerter-code-fails-to-push-to-app/92354/7). 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.

---

<div class="post-metadata">

**Author:** ![mtoman](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/mtoman/32/3599_2.png) [@mtoman](https://forums.balena.io/u/mtoman)\
**Post date:** [July 13, 2021, 1:18pm UTC](https://forums.balena.io/t/gpio-not-working/335248/8 "2021-07-13T13:18:59Z")

</div>

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