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 = pwm.channel(0, pin='P22', duty_cycle=0.5)
    pwm_c.duty_cycle(0.3) 
    


  • 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:
    https://learn.sparkfun.com/tutorials/pulse-width-modulation/all

    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 = pwm.channel(0,pin='P8', duty_cycle=1)
    
    while True:
        pwm_c.duty_cycle(0.097)
        sleep(1)
        pwm_c.duty_cycle(0.043) 
        sleep(1)
        pwm_c.duty_cycle(0.097)
    

Log in to reply
 

Pycom on Twitter