Page 1 of 1

Not sure my GPIO pins are working?

Posted: Sat Jul 27, 2019 10:52 am
by tinkerer99
Hi Guys,

I've got a raspberry pi 4 and installed the new Rasbian with everything up to date (i got Raspbian Buster with desktop and recommended software from https://www.raspberrypi.org/downloads/raspbian/). Everything else seems to work fine

First I tried https://projects.raspberrypi.org/en/pro ... th-scratch but get to the 'Constructing a Scratch program' and try gpio pins 2, 3 or 17 and nothing happens - well my led is lit up on pins 2 and 3 like when using 3.3v but off on pin 17

On scratch I've tried the broadcast commands and also added the dark grey extension blocks e.g. set gpio17 to output high

I noticed raspi-config didn't have my remote gpio enabled so i did that under 'Interfacing Options'

I've tried using python - and i get a funny error 'RuntimeError: Not running on a RPi!' (python 3.7)

import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.OUT)
Traceback (most recent call last):
File "<input>", line 1, in <module>
RuntimeError: Not running on a RPi!

as a troubleshooting step i installed sudo apt install rpi.gpio which added 143kB of files. Any ideas why I can't get this to work? Thanks guys

Re: Not sure my GPIO pins are working?

Posted: Sat Jul 27, 2019 1:59 pm
by joan
The Pi4B is quite a recent addition and not all the GPIO libraries have been updated so far. I suspect that is what you are seeing.

Re: Not sure my GPIO pins are working?

Posted: Sat Jul 27, 2019 2:56 pm
by gordon77
Your code works fine on my PI4.

Look at this thread https://www.raspberrypi.org/forums/view ... 8&t=244375 where there is a GPIO issue, not sure if the fix has been uploaded yet, and try the GPIO install at the end.

Re: Not sure my GPIO pins are working?

Posted: Sat Jul 27, 2019 3:33 pm
by neilgl
That fix seems to have been posted now. (Tested your script on a pi4 - ok)

Re: Not sure my GPIO pins are working?

Posted: Sun Jul 28, 2019 11:40 am
by tinkerer99
Thanks Guys,

I just tested but still not working for me, I'm not sure why it's not working with scratch either. I have an older pi 2 and pi 3 and I'll test on those too - this new one was my desktop replacement :D so was handier to start tinkering with electronics

:~ $ pip3 install --upgrade --pre rpi.gpio
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Cache entry deserialization failed, entry ignored
Cache entry deserialization failed, entry ignored
Requirement already up-to-date: rpi.gpio in /usr/lib/python3/dist-packages (0.7.0)

:~ $ python3
Python 3.7.3 (default, Apr 3 2019, 05:39:12)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import RPi.GPIO as GPIO
>>> import time
>>> GPIO.setmode(GPIO.BCM)
>>> GPIO.setup(17, GPIO.OUT)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
RuntimeError: Not running on a RPi!

It does make sense that this is quite new - thanks gordon77 - i tried your script and got the same.

>>> for pin in range (0,26):
... GPIO.setup(pins[pin], GPIO.IN, pull_up_down=GPIO.PUD_UP)
... print ('pin: '+ str(pins[pin]), GPIO.input(pins[pin]))
...
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
RuntimeError: Not running on a RPi!

Re: Not sure my GPIO pins are working?

Posted: Sun Jul 28, 2019 11:42 am
by gordon77
I would build a new Sd card and see if that cures it or is it some hardware fault.

Re: Not sure my GPIO pins are working?

Posted: Sun Jul 28, 2019 11:50 am
by Andyroo
I would use pip to uninstall and download the latest code direct from https://sourceforge.net/projects/raspbe ... an-buster/

(I hate pip - so am biased :lol: )

Re: Not sure my GPIO pins are working?

Posted: Tue Jul 30, 2019 9:02 am
by tinkerer99
Thanks for your help all! Re-installed rasbian and it's all working... glad it is not a hardware fault :D

Re: Not sure my GPIO pins are working?

Posted: Mon Aug 19, 2019 3:43 pm
by tinkerer99
I found out what was causing the issue!! something I may not have mentioned in my original post was that I had created new user accounts and also locked the pi user account :oops: - it didn't occur to me that the new users would have been the cause. Turns out it was a permissions issue

'sudo adduser [username] gpio' resolved it! :D