Having trouble with GPIO pins

I have just gotten my jetson orin nano and can’t seem to get some simple python tester code working on it before i wire it to my motor drivers. Am I doing something wrong here? the 5v seems to be working, as well as the servo, as it twitches when I attach and detach the 5v wire. The code runs with no issues. Here is my code and my setup. I would be grateful if you could help. Thanks.

import Jetson.GPIO as GPIO
import time

Pin Definitions

servo_pin = 32 # Physical pin 32 (GPIO07)

‘’’
Servo Connection Guide:

  • Red wire → Pin 2 (5V)
  • Brown wire → Pin 6 (GND) [or any other GND: 14, 20, 30, 34]
  • Orange wire-> Pin 32 (GPIO07/PWM)
    ‘’’

def setup():
GPIO.setmode(GPIO.BOARD)
GPIO.setup(servo_pin, GPIO.OUT)
# Create PWM object at 50Hz (standard frequency for servo motors)
# servo_pin = which pin to use
# 50 = 50Hz frequency (20ms period)
return GPIO.PWM(servo_pin, 50)

def cleanup():
GPIO.cleanup()

def main():
try:
# Initialize GPIO and PWM
pwm = setup()
pwm.start(0)

    print("Servo Test Program")
    print("Press Ctrl+C to exit\n")
    
    while True:
        # Position control through duty cycle:
        # 2.5% = 0.5ms pulse (0 degrees)
        # 7.5% = 1.5ms pulse (90 degrees)
        # 12.5% = 2.5ms pulse (180 degrees)
        
        print("Moving to 0 degrees")
        pwm.ChangeDutyCycle(2.5)
        time.sleep(1)
        
        print("Moving to 90 degrees")
        pwm.ChangeDutyCycle(7.5)
        time.sleep(1)
        
        print("Moving to 180 degrees")
        pwm.ChangeDutyCycle(12.5)
        time.sleep(1)
        
        response = input("Press Enter to repeat or 'q' to quit: ")
        if response.lower() == 'q':
            break
            
except KeyboardInterrupt:
    print("\nProgram stopped")
finally:
    if 'pwm' in locals():
        pwm.stop()
    cleanup()

if name == “main”:
main()

Hi ohme33,

It seems you are using Orin Nano devkit.
What’s the Jetpack version in use?

Have you configured the pinmux for PIN32 of 40-pins header before use?

Or have you tried using gpiod to control this pin?

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