Push button program not running or saying pin number is invalid

I am working on running a program on the Jetson Nano 2GB that has different functions for push buttons. I had this code running on a Raspberry Pi previously without any problems. For some reason, the Jetson will not run or recognize the push buttons when I run it. I have tried multiple GPIO.BOARD setups as well as pin setups without any real success. Any help would be much appreciated!

Here is the code that I’m working on:

import Jetson.GPIO as GPIO

def button_push_1(channel):
print(‘Button 1 was pressed’)

def button_push_2(channel):
print(‘Button 2 was pressed’)

def button_push_3(channel):
print(‘Button 3 was pressed’)

def button_push_4(channel):
print(‘Button 4 was pressed’)

def button_push_5(channel):
print(‘Button 5 was pressed’)

#setup button channels
btn_1=8
btn_2=10
btn_3=12
btn_4=16
btn_5=18

GPIO.setwarnings(False) #ignores the warnings for now
GPIO.setmode(GPIO.BOARD) #uses the physical button numbering system

#setup button inputs
GPIO.setup(btn_1,GPIO.IN, pull_up_down=GPIO.PUD_DOWN) #sets pin 12 to be an input pin and sets initial value to be low/down
GPIO.setup(btn_2,GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(btn_3,GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(btn_4,GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(btn_5,GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

#event detection
GPIO.add_event_detect(btn_1,GPIO.FALLING,button_push_1)
GPIO.add_event_detect(btn_2,GPIO.FALLING,button_push_2)
GPIO.add_event_detect(btn_3,GPIO.FALLING,button_push_3)
GPIO.add_event_detect(btn_4,GPIO.FALLING,button_push_4)
GPIO.add_event_detect(btn_5,GPIO.FALLING,button_push_5)

message=input(‘Press enter to exit program\n’) #runs until user presses enter
GPIO.cleanup() #clean up

hello jaredmz,

please access pinmux spreadsheets to review default pin configuration,
for example, pin-8 and pin-10 were default configured as UART, you’ll need to modify the pin settings as GPIO for your use-case.

I accessed the spreadsheet, but I’m not sure what most of it means. Could you explain what exactly I would be looking for as far as modifying the pin setup in the GPIO?

Thanks!

hello jaredmz,

you may searching for [40 Pin Header] for its default pin definition, and please update the [Customer Usage] fields to change the pin mixing,
please also check this session, Pinmux Changes for the steps to change the pinmux configuration applied by the software.
thanks

So I would use the 40 pin header numbering scheme listed in the spreadsheet? Do you know what GPIO setup mode I would use in the python code with that numbering scheme? Would it be GPIO.BOARD?

Thanks for your time!

there’s [40 Pin Header] for mapping the signal names in the spreadsheets.
please also see gpio_pin_data.py, which include pin definitions with respect to the Jetson boards.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.