gratefulfrog
Posts: 5
Joined: Fri Aug 18, 2017 7:38 pm

GPIO pins revert on Stretch

Sun Nov 12, 2017 9:10 am

I have installed Stretch from scratch on a new SD card.

When I try to use gpio at the command line or in python, the pins seem to revert to their default states a few seconds after I set them.

for example:

Code: Select all

$ gpio blink 4
will blink a led 3 or 4 times then hang.

Code: Select all

$ gpio mode 4 out
will briefly change the pin to output mode, then 2-3 seconds later it reverts to input mode.

I get exactly the same behavior in python.

Is there something I am missing?

Any help would be greatly appreciated.

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

Re: GPIO pins revert on Stretch

Sun Nov 12, 2017 10:59 am

A common problem new users have when programming gpio via python is they don't have any time delay between turning a pin on and then off or they run gpio.cleanup at the end of a short program again with no time delays.

try this short python program with an led and suitable resistor connected between gpio 21 ( that's pin 40 ) and ground ( that's pin 39 )

Code: Select all

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)

GPIO.setup(21, GPIO.OUT)

print "flashing LED 4 times"
t=0
while t < 4:
    GPIO.output(21, GPIO.HIGH)
    time.sleep(0.5)
    GPIO.output(21, GPIO.LOW)
    time.sleep(0.5)
    t = t + 1
    
print " LED on for 4 seconds"
GPIO.output(21, GPIO.HIGH)
time.sleep (4)

print "running clean up"
GPIO.cleanup()
print " all gpio pins now reset to default"
you should see the LED blink and than stay on finally turning off when the program ends with comments doing displayed telling that the LED is doing at each stage.

once you have the program working try removing the last 3 lines and see what happens.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

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

Re: GPIO pins revert on Stretch

Sun Nov 12, 2017 11:06 am

Could you just confirm which physical pin numbers the LED is connected to on the board.

gratefulfrog
Posts: 5
Joined: Fri Aug 18, 2017 7:38 pm

Re: GPIO pins revert on Stretch

Sun Nov 12, 2017 1:06 pm

I found out that this works but not on the pin I chose, the GPCLK pin... that pin is "special" it seems!

Sorry...

DirkS
Posts: 10371
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: GPIO pins revert on Stretch

Sun Nov 12, 2017 1:14 pm

gratefulfrog wrote:
Sun Nov 12, 2017 1:06 pm
I found out that this works but not on the pin I chose, the GPCLK pin... that pin is "special" it seems!
That's the default pin for one-wire.
Is that activated on your pi? Check for a line starting with

Code: Select all

dtoverlay=w1-gpio
in /boot/config.txt

You can disable it by removing this line or through raspi-config (interfacing options) and then rebooting

gratefulfrog
Posts: 5
Joined: Fri Aug 18, 2017 7:38 pm

Re: GPIO pins revert on Stretch

Sun Nov 12, 2017 1:44 pm

Indeed, when I disable one-wire, pin 7 works again as normal!

Thanks everyone for all the help!!!

Return to “Troubleshooting”