Meshtastic course problem

Hi, Newbie here.
Have been following along with the course with all the recommended hardware. Btw great presenter Jaryd!
Have got up to the servo part where you type in 180 and the servo moves. I cant get my servo to move. I have checked and rechecked everything many times started over from scratch, but i cant get it to move. I get 180 on the shell recieved from the other meshtastic device but no servo movement. Could the servo be faulty? Its brand new never used. Can i run a simple code to check its on order?

1 Like

Hi @Nicholas290601

Welcome to the forum!

If you’re using a pico like in the guide you can use this code below to test whether or not that servo is working. With the servo on PIN 15 it will sweep the arm from the maximum to the minimum position.

from machine import Pin, PWM
from time import sleep

# Define servo parameters
servo_pin = Pin(15)  # Replace with your GPIO pin number
pwm = PWM(servo_pin)  # Initialize PWM on the selected pin
pwm.freq(50)  # Standard frequency for servos is 50 Hz

# Define duty cycle values
MAX_DUTY = 7500  # Maximum duty cycle (adjust as needed for your servo)
MIN_DUTY = 2500  # Minimum duty cycle (adjust as needed for your servo)

def move_servo_to_position(duty, delay=0.5):
    """
    Moves the servo to a specified duty cycle position.
    Args:
        duty (int): The duty cycle to set for the servo position.
        delay (float): Time (in seconds) to wait after moving.
    """
    pwm.duty_u16(duty)
    sleep(delay)

try:
    while True:
        # Move to maximum position
        move_servo_to_position(MAX_DUTY)
        print("Moved to MAX position")
        
        # Move to minimum position
        move_servo_to_position(MIN_DUTY)
        print("Moved to MIN position")

except KeyboardInterrupt:
    # Cleanup on Ctrl+C
    pwm.duty_u16(0)  # Turn off PWM signal
    pwm.deinit()
    print("Servo control stopped.")
2 Likes