How do you control an MG90S servo with a Jetson Nano? Here’s everything I’ve done and tried (somewhat in order)
-
Using a separate 5v power supply for the servo. I tried both: having the ground be connected to the jetson, power supply, and servo and just having the ground be between the jetson and servo.
-
I tried validating the servo works as expected using an Arduino micro-controller separately to isolate the problem
-
enabled the PWM pins by going into
sudo /opt/nvidia/jetson-io/jetson-io.py
, and following the steps from there -
several versions of a python script (using Jetson GPIO)
-
several reboots, hours and attempts later, no success :(
Please let me know what the proper steps are. My code is fairly straightforward:
import Jetson.GPIO as GPIO
import time
# Pin Definitions
SERVO_PIN = 33 # Adjust to your GPIO pin
print("Imports successful")
# Setup
GPIO.setmode(GPIO.BOARD) # BOARD pin-numbering scheme
GPIO.setup(SERVO_PIN, GPIO.OUT)
print("GPIO setup success")
# Initialize PWM
pwm = GPIO.PWM(SERVO_PIN, 60) # 50Hz frequency for servo
print("frequency setup success")
def set_servo_angle(angle):
duty_cycle = angle / 18. + 2.5 # Convert angle to duty cycle
pwm.ChangeDutyCycle(duty_cycle)
time.sleep(0.02) # Allow the servo to move
pwm.start(0)
try:
print('starting-sweep')
while True:
print('sweep reset')
# Sweep from 0 to 180 degrees
for angle in range(0, 181):
set_servo_angle(angle)
time.sleep(0.01) # Adjust speed of sweep
# Sweep back from 180 to 0 degrees
for angle in range(180, -1, -1):
set_servo_angle(angle)
time.sleep(0.01) # Adjust speed of sweep
print('Finished Loop')
except KeyboardInterrupt:
print('Cleaning up pwm')
pwm.stop()
GPIO.cleanup()
The script runs without throwing any errors, and there’s no sign of life from the stepper. I’ve tried both pin 32 and 33 on the GPIO in my attempts to get this working