hawaiiankong
Posts: 12
Joined: Thu Nov 07, 2019 3:46 pm

RPi Internal Pull-Up Resistors Not Functioning

Thu Nov 07, 2019 4:10 pm

I've been working on this and googling furiously for almost a week, but have finally conceded defeat and wanted to reach out for help. I'm adding a Reset button that is normally closed, which is placed between GPIO21 (physical pin 40 on my RPI 3B+) and Ground. When I press the switch, it disconnects GPIO21 from ground, and goes on to run a Python script to reboot the Pi.

I've enabled the internal Pull-Up resistor and set the pin as INPUT in the script, but no matter what, I can't get the pin to do anything. I know that without the pin connected to anything, and the Pull-Up Resistor enabled, I should be seeing 3.3VDC. However, with a DMM, it reads about 150mV to ground (without the button wire connected).

Here's my code:

Code: Select all

import RPi.GPIO as GPIO
import os

GPIO.setmode(GPIO.BCM)

GPIO.setup(21, GPIO.IN, pull_up_down=GPIO.PUD_UP)

def psReset(channel)
os.system("sudo shutdown -r now")

GPIO.add_event_detect(21, GPIO.RISING, callback = psReset, bouncetime = 250)

I've run the following script manually from PuTTy using the command:

Code: Select all

sudo python /home/pi/reboot.py
and the cursor just goes to the next line. I'm assuming that the script is now running. But with no wire connected, it sits at ~150mV, and with the wire in place, pressing the button has no effect.

I've double- and triple-checked that I'm on the correct pin (physical board 40; GPIO21).

What could I be doing wrong?

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

Re: RPi Internal Pull-Up Resistors Not Functioning

Thu Nov 07, 2019 4:31 pm

Did you modify /boot/config.txt to enable anything like I2S?

Does it work if you use another pin?

hawaiiankong
Posts: 12
Joined: Thu Nov 07, 2019 3:46 pm

Re: RPi Internal Pull-Up Resistors Not Functioning

Thu Nov 07, 2019 4:39 pm

trejan wrote: Did you modify /boot/config.txt to enable anything like I2S?

Does it work if you use another pin?
No I haven't enabled any GPIO alternate modes, and yes I've tried GPIO24 (physical pin 18) and GPIO20 (pin 38) as well, and it does the same thing on both. So I don't suspect 3 random pins to be damaged at once.

Another odd (and repeatable) behavior is that when I place the DMM on GPIO20 (pin 38) to ground, the RPi reboots. I don't understand other than I know the DMM's internal resistance creates a voltage-divider on the pin, but shouldn't it be too high to trigger anything like that?

User avatar
rpiMike
Posts: 1052
Joined: Fri Aug 10, 2012 12:38 pm
Location: Cumbria, UK

Re: RPi Internal Pull-Up Resistors Not Functioning

Thu Nov 07, 2019 4:51 pm

Your need something to stop your code from exiting, one way is a simple loop:

Code: Select all

import RPi.GPIO as GPIO
import os
import time

GPIO.setmode(GPIO.BCM)

GPIO.setup(21, GPIO.IN, pull_up_down=GPIO.PUD_UP)

def psReset(channel):
    os.system("sudo shutdown -r now")

GPIO.add_event_detect(21, GPIO.RISING, callback = psReset, bouncetime = 250)

while True:
    time.sleep(0.1)

hawaiiankong
Posts: 12
Joined: Thu Nov 07, 2019 3:46 pm

Re: RPi Internal Pull-Up Resistors Not Functioning

Thu Nov 07, 2019 5:40 pm

rpiMike wrote:
Thu Nov 07, 2019 4:51 pm
Your need something to stop your code from exiting, one way is a simple loop:

Code: Select all

import RPi.GPIO as GPIO
import os
import time

GPIO.setmode(GPIO.BCM)

GPIO.setup(21, GPIO.IN, pull_up_down=GPIO.PUD_UP)

def psReset(channel):
    os.system("sudo shutdown -r now")

GPIO.add_event_detect(21, GPIO.RISING, callback = psReset, bouncetime = 250)

while True:
    time.sleep(0.1)
I forgot to copy that in the original post, but yeah I did have:

Code: Select all

while True:
   time.sleep(1)
   
Is maybe 1 second too long...?

PiGraham
Posts: 3678
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: RPi Internal Pull-Up Resistors Not Functioning

Thu Nov 07, 2019 5:51 pm

What do you see if you just poll the input and print the state and press the button?

Code: Select all

mport RPi.GPIO as GPIO
import os
import time

GPIO.setmode(GPIO.BCM)

GPIO.setup(21, GPIO.IN, pull_up_down=GPIO.PUD_UP)

while(True):
	print (GPIO.input(21))
	time.sleep(0.1)
	

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

Re: RPi Internal Pull-Up Resistors Not Functioning

Thu Nov 07, 2019 5:57 pm

Not sure if this is part of the problem.

I would use a pull-down if you are looking for a rising edge. The code is using a pull-up.

User avatar
rpiMike
Posts: 1052
Joined: Fri Aug 10, 2012 12:38 pm
Location: Cumbria, UK

Re: RPi Internal Pull-Up Resistors Not Functioning

Thu Nov 07, 2019 6:03 pm

The code worked on my Pi4 - albeit with a print in place of the shutdown.

Edit: Just noticed OP's button is normally closed - mine is normally open.

hawaiiankong
Posts: 12
Joined: Thu Nov 07, 2019 3:46 pm

Re: RPi Internal Pull-Up Resistors Not Functioning

Thu Nov 07, 2019 8:35 pm

joan wrote:
Thu Nov 07, 2019 5:57 pm
Not sure if this is part of the problem.

I would use a pull-down if you are looking for a rising edge. The code is using a pull-up.
The idea is that while the RPi is powered on, the pin remains grounded. When I press the normally-closed button, the pin gets pulled to 3.3V via the internal pull-up resistor, and with that rising edge the script executes a system reboot.

In my mind that should work. This is bugging me like crazy.

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

Re: RPi Internal Pull-Up Resistors Not Functioning

Thu Nov 07, 2019 9:07 pm

Perhaps it is time for a photo of the wiring.

hawaiiankong
Posts: 12
Joined: Thu Nov 07, 2019 3:46 pm

Re: RPi Internal Pull-Up Resistors Not Functioning

Fri Nov 08, 2019 1:14 am

PiGraham wrote: What do you see if you just poll the input and print the state and press the button?

Code: Select all

import RPi.GPIO as GPIO
import time
import os

GPIO.setmode(GPIO.BCM)

GPIO.setup(21, GPIO.IN, pull_up_down=GPIO.PUD_UP)

while True:
    print(GPIO.input(21))
    time.sleep(0.5)
I changed my code to poll GPIO21 (above). With nothing attached to the pin, it prints all 0's.

I even grabbed a 10k resistor and touched it between GPIO21 and a 3V3 pin, and it was still all 0's...no change.

Here's a simple representation of what I'm doing, since the internal pull-up isn't working on GPIO21. Still prints all 0's.
https://i.imgur.com/r7H9G3s.png

This is a fresh image of RetroPie -- are there any libraries other than rpi.gpio that I need to install for the GPIOs to work?

I hope somebody can point out I'm doing something really dumb. That would be progress lol

hawaiiankong
Posts: 12
Joined: Thu Nov 07, 2019 3:46 pm

Re: RPi Internal Pull-Up Resistors Not Functioning

Fri Nov 08, 2019 3:05 am

Update:

I ran gpiotest and every single pin failed.

I replaced my RPi 3B+ with an older 3B and ran the same test, and every pin passed. Also ran the previous test script and got 1's and 0's where they should be.

I must have somehow fried the GPIO peripheral. I'm usually very careful too.

Anybody wanna buy a Raspberry Pi 3B+ cheap??

Haha oh well...kind of relieved now. thanks for the help guys.

Return to “Troubleshooting”