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: 14995
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: 5125
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: 2348
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: 5125
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

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: )

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

_o_
Posts: 4
Joined: Fri Jun 12, 2020 8:05 pm

Re: Not sure my GPIO pins are working?

Fri Jun 12, 2020 8:41 pm

Dear all,
I've just followed all the instruction, I've also reinstalled rasbian I still have problems.

Code: Select all

import RPi.GPIO as gpio
import time
gpio.setmode(gpio.BOARD)
gpio.setup(7, gpio.OUT)
gpio.output(7, True)
time.sleep(15)
gpio.cleanup()

If I use a multimeter using the red cable linked to the pin 7 and black one to pin 39 I read 80 millivolt while the program is running

(The standard pin 1 and pin 2 are working well with 3.3 and 5 v)

Do you think I have to buy another raspberry pi? :cry:

User avatar
rpdom
Posts: 17427
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Not sure my GPIO pins are working?

Sat Jun 13, 2020 4:39 am

_o_ wrote:
Fri Jun 12, 2020 8:41 pm
If I use a multimeter using the red cable linked to the pin 7 and black one to pin 39 I read 80 millivolt while the program is running
It could be that Pin 7 (GPIO4) has been configured for use with 1-wire bus devices and that driver is taking over from your code.

Try using Pin 11 (GPIO17) instead and see if you get the same readings.
Unreadable squiggle

_o_
Posts: 4
Joined: Fri Jun 12, 2020 8:05 pm

Re: Not sure my GPIO pins are working?

Sat Jun 13, 2020 5:28 pm

Thank you for your reply,
I still have the same issue... and I've also doublechecked that the 1-wire is disabled
Any other ideas?

pcmanbob
Posts: 9751
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Not sure my GPIO pins are working?

Sat Jun 13, 2020 5:49 pm

You might post a picture of your wiring to the gpio just so we can check you are actually on the right gpio pins.

The current Raspberry Pi OS with the included RPi.GPIO works perfectly well on my pi's
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

_o_
Posts: 4
Joined: Fri Jun 12, 2020 8:05 pm

Re: Not sure my GPIO pins are working?

Sun Jun 14, 2020 4:24 pm

As I was describing in my first post, I don't use any wires, I was simply using a multimiter to check the voltage when the pin is on

gpio.output(7, True).

I checked the pin 7 with the red wire of the multimeter using pin 39 as GND.

https://www.raspberrypi.org/documentation/usage/gpio/

Then, just to be sure, I opened all the GPIO that can be used to check them with the multimeter and ... magically ... all of them started to work.

I then did another test:
I used a standard 1.5 to 6V

Image

dc motor to check again, strangely if I use the pin 1 (3.3v) and 39(GND) it works, while it doesn't work with pin 40 and 39.
Then I changed dc motor with a tiny one you can find in a small helicopter toy and it works with the pins 40 and 39.
Image
My guess is that the GPIO for the pins like 7,11,38,40 can't provide enough power to make a small dc motor run, while the pin 1,17 can.
I was wondering, is it something that happens only to my Raspberry Pi?
Thank you for your support.

trejan
Posts: 2327
Joined: Tue Jul 02, 2019 2:28 pm

Re: Not sure my GPIO pins are working?

Sun Jun 14, 2020 4:29 pm

_o_ wrote:
Sun Jun 14, 2020 4:24 pm
My guess is that the GPIO for the pins like 7,11,38,40 can't provide enough power to make a small dc motor run, while the pin 1,17 can.
GPIO pins are directly connected to the Broadcom SoC and can't directly power a motor. They can only supply a small amount of current. You must use a transistor or a motor driver to run your motors. Pin 1 + 17 works because they're the 3.3V supply pins.

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

Re: Not sure my GPIO pins are working?

Sun Jun 14, 2020 4:29 pm

Gpios can only supply upto 15mA each, a total of 50mA across them all. Not enough to drive a motor.

User avatar
davidcoton
Posts: 5152
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK
Contact: Website

Re: Not sure my GPIO pins are working?

Sun Jun 14, 2020 4:31 pm

_o_ wrote:
Sun Jun 14, 2020 4:24 pm
My guess is that the GPIO for the pins like 7,11,38,40 can't provide enough power to make a small dc motor run, while the pin 1,17 can.
I was wondering, is it something that happens only to my Raspberry Pi?
Correct guess, applicable to all Pis.

Not only that, but the motor is likely to cause damage to your Pi. GPIOs are not designed to drive a motor directly, you need a transistor or FET as a buffer.

Edit: Gordon77 types short but fast!
Location: 345th cell on the right of the 210th row of L2 cache

User avatar
B.Goode
Posts: 10407
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Not sure my GPIO pins are working?

Sun Jun 14, 2020 4:35 pm

_o_ wrote:
Sun Jun 14, 2020 4:24 pm
As I was describing in my first post, I don't use any wires, I was simply using a multimiter to check the voltage when the pin is on

gpio.output(7, True).

I checked the pin 7 with the red wire of the multimeter using pin 39 as GND.

https://www.raspberrypi.org/documentation/usage/gpio/

Then, just to be sure, I opened all the GPIO that can be used to check them with the multimeter and ... magically ... all of them started to work.

I then did another test:
I used a standard 1.5 to 6V

Image

dc motor to check again, strangely if I use the pin 1 (3.3v) and 39(GND) it works, while it doesn't work with pin 40 and 39.
Then I changed dc motor with a tiny one you can find in a small helicopter toy and it works with the pins 40 and 39.
Image
My guess is that the GPIO for the pins like 7,11,38,40 can't provide enough power to make a small dc motor run, while the pin 1,17 can.
I was wondering, is it something that happens only to my Raspberry Pi?
Thank you for your support.





It is hazardous for your RPi to attempt to drive any motor directly from a gpio pin. (It's a bit like falling off a cliff: you may think everything is OK until you stop... )

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

Re: Not sure my GPIO pins are working?

Sun Jun 14, 2020 7:56 pm

davidcoton wrote:
Sun Jun 14, 2020 4:31 pm


Edit: Gordon77 types short but fast!
:lol: :lol:

_o_
Posts: 4
Joined: Fri Jun 12, 2020 8:05 pm

Re: Not sure my GPIO pins are working?

Sat Jun 20, 2020 9:25 pm

Thank you all of you for the explanation!

Return to “Troubleshooting”