Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    Servo Motor Issues

    Scheduled Pinned Locked Moved GPy
    2 Posts 1 Posters 221 Views 1 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • shanefowler25S Offline
      shanefowler25
      last edited by

      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) 
      
      1 Reply Last reply Reply Quote 0
      • shanefowler25S Offline
        shanefowler25
        last edited by

        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)
        
        1 Reply Last reply Reply Quote 0

        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

        With your input, this post could be even better 💗

        Register Login
        • 1 / 1
        • First post
          Last post

        Pycom on Twitter

        Pycom