Servo Motor Issues

  • Hello,

    I'm new to pycom and using the GPy board. I have my board attached to an expansion board v3.1 and I am trying to control a servo motor by starting it at on location and then setting it at another location.

    I'm using the example code given @ the PWM documentation page and configured it to my the way my pins are setup, yet when I run my program on my device the servo motor just spins uncontrollably.

    Can someone help explain to me why this is happening, my code is as follows:

    from machine import PWM
    pwm = PWM(0, frequency=5000)  # use PWM timer 0, with a frequency of 5KHz
    pwm_c =, pin='P22', duty_cycle=0.5)

  • I solved my own problem, I realized the frequency was too high and that the duty cycle should be between 5 and 10 percent.

    I used Sparkfun's PWM page to help me get this information and solve my issue. The link is here:

    Also my code is here for anyone who may run into the same issue with a servo motor:

    from machine import PWM
    from time import sleep
    pwm = PWM(0,frequency=50)  # use PWM timer 0, with a frequency of 50Hz
    pwm_c =,pin='P8', duty_cycle=1)
    while True:

Log in to reply

Pycom on Twitter