tinkerer99
Posts: 4
Joined: Sat Jul 27, 2019 10:25 am

Not sure my GPIO pins are working?

Sat Jul 27, 2019 10:52 am

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

User avatar
joan
Posts: 14176
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Not sure my GPIO pins are working?

Sat Jul 27, 2019 1:59 pm

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.

gordon77
Posts: 4111
Joined: Sun Aug 05, 2012 3:12 pm

Re: Not sure my GPIO pins are working?

Sat Jul 27, 2019 2:56 pm

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.

User avatar
neilgl
Posts: 746
Joined: Sun Jan 26, 2014 8:36 pm
Location: Near Aston Martin factory

Re: Not sure my GPIO pins are working?

Sat Jul 27, 2019 3:33 pm

That fix seems to have been posted now. (Tested your script on a pi4 - ok)

tinkerer99
Posts: 4
Joined: Sat Jul 27, 2019 10:25 am

Re: Not sure my GPIO pins are working?

Sun Jul 28, 2019 11:40 am

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!

gordon77
Posts: 4111
Joined: Sun Aug 05, 2012 3:12 pm

Re: Not sure my GPIO pins are working?

Sun Jul 28, 2019 11:42 am

I would build a new Sd card and see if that cures it or is it some hardware fault.

Andyroo
Posts: 4136
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

Re: Not sure my GPIO pins are working?

Sun Jul 28, 2019 11:50 am

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: )
Need Pi spray - these things are breeding in my house...

tinkerer99
Posts: 4
Joined: Sat Jul 27, 2019 10:25 am

Re: Not sure my GPIO pins are working?

Tue Jul 30, 2019 9:02 am

Thanks for your help all! Re-installed rasbian and it's all working... glad it is not a hardware fault :D

tinkerer99
Posts: 4
Joined: Sat Jul 27, 2019 10:25 am

Re: Not sure my GPIO pins are working?

Mon Aug 19, 2019 3:43 pm

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

Return to “Troubleshooting”