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