Skip to content

Instantly share code, notes, and snippets.

@TIS-Arne
Created August 8, 2019 08:05
Show Gist options
  • Save TIS-Arne/dcf74e9467ac5e0f92b46970eac17e1a to your computer and use it in GitHub Desktop.
Save TIS-Arne/dcf74e9467ac5e0f92b46970eac17e1a to your computer and use it in GitHub Desktop.
Jetson GPIO Test
import Jetson.GPIO as GPIO
import time
import os
last = time.time()
def gpio_event(channel):
global last
t = time.time()
print(t-last)
last = t
# Needs RT permissions
# Enable RT with:
# sudo sysctl -w kernel.sched_rt_runtime_us=-1
# and run as root
pri = os.sched_get_priority_max(os.SCHED_RR)
print("Priority:", pri)
sched = os.sched_param(pri)
os.sched_setscheduler(0, os.SCHED_RR, sched)
GPIO.setmode(GPIO.BOARD)
channel = 16
GPIO.setup(channel, GPIO.IN, pull_up_down=GPIO.PUD_OFF)
GPIO.add_event_detect(channel, GPIO.FALLING, callback=gpio_event)
while 1:
time.sleep(1)
GPIO.cleanup()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment