GPIO pull down resistor

I’m using GPIO pin 13 as input and I connect a button between pin 13 and 3.3V. What I want is that every time I press the button, I can read value 1 and when I release the button I can read value 0.
It seems that pin 13 has a internal pull_down resistor according to this topic:


Theoretically, a pull down resistor will set the default value to LOW, but the value stays at HIGH when release the button. Why?
As the internal resistor didn’t work, I use a 100 ohm resistor between pin 13 and GND as pull-down. It worked well using function add_event_detect() with no bouncetime paramater. When I set a bouncetime(no matter what value), the program only works for serval times and after that it gets stuck, and needs ctrl+C twice to interrupet.
It is very magic. What should I do to solve this problem? Thanks.

could you please share your environment setups, which JetPack release version you’re working with.
may I also know the kernel messages which report this failures,
thanks

I’m using JetPack 4.4 which is released on 2020/07/07 and Jetson.GPIO 2.0.8
When interrupeted, the program output like this:
Starting demo now! Press CTRL+C to exit

Value read from pin 13 : HIGH

Value read from pin 13 : LOW

Value read from pin 13 : LOW

^C^CTraceback (most recent call last):

File “GPIO.py”, line 28, in main

while input() != "exit":

KeyboardInterrupt

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File “GPIO.py”, line 34, in

main()

File “GPIO.py”, line 31, in main

GPIO.cleanup()

File “/usr/lib/python3/dist-packages/Jetson/GPIO/gpio.py”, line 396, in cleanup

_cleanup_all()

File “/usr/lib/python3/dist-packages/Jetson/GPIO/gpio.py”, line 293, in _cleanup_all

_cleanup_one(ch_info)

File “/usr/lib/python3/dist-packages/Jetson/GPIO/gpio.py”, line 283, in _cleanup_one

event.event_cleanup(ch_info.gpio)

File “/usr/lib/python3/dist-packages/Jetson/GPIO/gpio_event.py”, line 369, in event_cleanup

remove_edge_detect(gpio)

File “/usr/lib/python3/dist-packages/Jetson/GPIO/gpio_event.py”, line 136, in remove_edge_detect

_mutex.acquire()

KeyboardInterrupt

And this is my program:
import RPi.GPIO as GPIO

import time

Pin Definitions

input_pin = 13

output_pin = 12

def fun(x):

value = GPIO.input(input_pin)

if value == GPIO.HIGH:

    value_str = "HIGH"

else:

    value_str = "LOW"

GPIO.output(output_pin, value)

print("Value read from pin {} : {}".format(input_pin,

                                            value_str))

def main():

prev_value = None

# Pin Setup:

GPIO.setmode(GPIO.BOARD) 

GPIO.setup(input_pin, GPIO.IN)  # set pin as an input pin

GPIO.setup(output_pin, GPIO.OUT)

GPIO.add_event_detect(input_pin, GPIO.BOTH, callback=fun, bouncetime=20)

print("Starting demo now! Press CTRL+C to exit")

try:

    while input() != "exit":

        pass

finally:

    GPIO.cleanup()

if name == ‘main’:

main()

Thanks

When the program gets stuck, I tried to read pin value directly using “cat /sys/class/gpio/gpio14/value”. It worked well and can read the value correctly when I press or release the button.

hello 806615569,

it might related to pd strength not enough, please refer to Topic 115752 for the reference,
thanks