Button pull-up resistor behaves weirdly

Hi!

I’m trying to integrate and implement an external button with my Nvidia Xavier NX. I want to be able to detect a button-push in my Python code. I’m using the package Jetson.GPIO to interact with the GPIO pins.

After quite some investigation, I found out that the package Jetson.GPIO doesn’t support pull-up resistors (because “there’s no way to control pull-up/-down from user-space on Jetson.”: pull_up_down value is unused · Issue #5 · NVIDIA/jetson-gpio · GitHub).

Because of this, I’ve soldered and integrated my own pull-up resistor, with the following schema:

pull-up_resistor

Where:

  • R1: 1kΩ
  • GPIO (read in code): pin 15 (board mode)
  • 3.3v: pin 17 (board mode)
  • GND: pin 14 (board mode)

Here’s the code snippet that handles the button push:

def start(self) -> None:
    """Starts infinate loop listening to button click. When clicked, it changes the active artwork."""
    while True:
        input_state = GPIO.input(self.GPIO_pinout)
        if input_state == False:
            self._change_active_artwork()
            time.sleep(self.loop_sleep_sec)

PROBLEM
For some reason, the button is sometimes “pushed” without me pushing it. In my setup, each time the button is pushed, a new image is displayed on a screen. It’s a big problem that the button “self-push”, as the image changes without any manual interaction.

I’m trying to trouble shoot the reason for this weird behaviour, and I’m suspecting that I might be because I’m using the wrong ohm on my resistor. Could the ohm be to high, thus the state of the GPIO pin will randomly sometimes fall back to 0/False even though it shouldn’t?

Could anyone with more knowledge please point me in the right direction? Am I using the correct Ohm for this application?

Best,
Max Fischer

you may also check GPIO input... stuck / not resetting? - #30 by Trumany as see-also.

Hi!

Thanks for the link. Isn’t that equivalent with what I’ve implemented? They also use a 1kΩ resistor and 3.3v power.

//Max

hello max.v.fischer,

please check you’re having correct GPIO configuration, for example, $ sudo cat /sys/kernel/debug/gpio
you may also trace kernel messages, i.e. $ dmesg --follow, to gather some logs for reference.
thanks

Hi!

Thanks, I’ll check that. What should a correct GPIO configuration look like?

So what is weird is that my setup seems to work during long periods (hours), I can register the switch/button push in the code. But then suddenly, a false negative is triggered (which of course also is registered in the code).

Which GPIO pin on the Xavier NX would you recommend to use for this type of setup?

Best,
Max

Do you work with Nvidia Xavier NX Developer Kit or your custom carrier board?

I work on a Nvidia Xavier NX Developer Kit

Using decoupling ceramic capacacitor might help you. It assists to setup more stabilize hardware conditions.

If anyone is reading this and has the same problem, here’s how I solved it. The problem was that my wires from the Xavier NX to the button were too long (~1.5m each way), thus acting as antennas. This triggered the false positives.

I solved it by adding a 100ms timeout and a secondary check if the button was still pushed:

def _is_false_negative_click(self):
    """Check if false negative click by timeout"""
    time.sleep(0.1)
    input_state = GPIO.input(self.GPIO_pinout)
    return input_state

def start(self) -> None:
    """Starts infinate loop listening to button click. When clicked, it changes the active artwork."""
    while True:
        input_state = GPIO.input(self.GPIO_pinout)
        if (input_state == False) and (not self._is_false_negative_click()):
            self._change_active_artwork()
            time.sleep(self.loop_sleep_sec)