I am working on getting the encoder pulse count on the jetson nano but i don’t seem to reach the milestone because i have tried many codes which count the pulses and print them on the screen when i physically turn the encoder using my hand i don’t see it printing any data.
import Jetson.GPIO as GPIO from time import sleep counter = 0 Enc_A = 17 Enc_B = 27 def init(): GPIO.setmode(GPIO.BCM) GPIO.setup(Enc_A, GPIO.IN) GPIO.setup(Enc_B, GPIO.IN) GPIO.add_event_detect(Enc_A, GPIO.RISING, callback=rotation_decode, bouncetime=10) return def rotation_decode(Enc_A): global counter sleep(0.002) Switch_A = GPIO.input(Enc_A) Switch_B = GPIO.input(Enc_B) if (Switch_A == 1) and (Switch_B == 0): counter += 1 print("direction -> ", counter) while Switch_B == 0: Switch_B = GPIO.input(Enc_B) while Switch_B == 1: Switch_B = GPIO.input(Enc_B) return elif (Switch_A == 1) and (Switch_B == 1): counter -= 1 print("direction <- ", counter) while Switch_A == 1: Switch_A = GPIO.input(Enc_A) return else: return def main(): try: init() while True : sleep(1) except KeyboardInterrupt: GPIO.cleanup() if __name__ == '__main__': main()
I also connected the signal pins to oscilloscope to check and saw it is giving pulse and also in the code we are attaching interrupt to monitor both the pins whenever there is a rising edge but don’t know why jetson has trouble in counting those pulses, Requesting the community to guide me here in this case.
Board: Jetson-nano 1010
OS: Jetpack 4.6.3