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

    Controlling a servo with lopy (library or manually)

    Scheduled Pinned Locked Moved LoPy
    servolopy
    16 Posts 3 Posters 3.8k Views 3 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.
    • sorenS Offline
      soren
      last edited by

      Hello,

      Was wondering if anyone know of an existing library for controlling a hobby servo with the lopy? Or alternatively could point me in a direction of doing it manually ?

      Thanks

      L 1 Reply Last reply Reply Quote 0
      • L Offline
        livius @soren
        last edited by livius

        @soren
        look here
        https://forum.pycom.io/topic/982/mg996r-pwm-3v3-solved

        think about people first, then computers

        sorenS 1 Reply Last reply Reply Quote 0
        • sorenS Offline
          soren @livius
          last edited by

          @livius thank you, but I have already glanced at that topic over and over again. It's not working.. did you get it to work?? :)

          L 1 Reply Last reply Reply Quote 0
          • L Offline
            livius @soren
            last edited by

            @soren
            yes, what do you tiried already?
            How your setup looks like?

            think about people first, then computers

            sorenS 1 Reply Last reply Reply Quote 0
            • sorenS Offline
              soren @livius
              last edited by soren

              @livius OK here goes:

              My servo is a 4,8v C505 Graupner non continuos. Documents about it are very sparse, but to make sure i wasn't wasting my time - I checked it with an arduino, and it's working just fine.

              I have 2 setups that I'm trying:
              Setup #1:
              pin G28 (P12) on the expansion board is connected directly to sig on the servo
              external voltage source (4.8v) to power, and GND to GND

              Setup #2:
              Same setup, but going through a CD74HCT125E logic level converter in order to step up the 3.3v output to a 5v output. Not 100% sure this makes sense though, but at least I haven't ruined anything because of it. When I measure the output of the converter chip, it hits almost 5v - so i can't see why this shouldn't work..

              code:
              pwm = machine.PWM(0, frequency=50)
              pwm_c = pwm.channel(0, pin='P12', duty_cycle=0.04)
              time.sleep(4)
              pwm_c.duty_cycle(0.112)
              time.sleep(4)
              pwm_c.duty_cycle(1)
              time.sleep(4)
              pwm_c.duty_cycle(0)

              servo is moving only occasionally and only a tiny tiny bit on the lopy.

              robert-hhR L 2 Replies Last reply Reply Quote 0
              • robert-hhR Offline
                robert-hh @soren
                last edited by robert-hh

                @soren said in Controlling a servo with lopy (library or manually):

                CD74HCT125

                I'm a little bit shy to ask, but did you pull the OE input of the gate low?
                Besides that, I checked your SW setting with my LoPy, and it fits. The frequency is 50Hz, and the duty cycles also match precisely the setting by SW.

                sorenS 1 Reply Last reply Reply Quote 0
                • sorenS Offline
                  soren @robert-hh
                  last edited by

                  @robert-hh no worries mate, but yes - i did pull OE low. Connected it directly to GND on the lopy. Maybe a stupid question, but what is "SW" ?

                  robert-hhR 2 Replies Last reply Reply Quote 0
                  • robert-hhR Offline
                    robert-hh @soren
                    last edited by

                    @soren Software

                    1 Reply Last reply Reply Quote 0
                    • robert-hhR Offline
                      robert-hh @soren
                      last edited by

                      @soren I just looked into the 74HCT125 data sheet. The minimum level for high is 3.15 V, close to the output level of the lopy. In that case I would check with an oscilloscope or logic analyzer whether the output of the gate really switches.

                      sorenS 1 Reply Last reply Reply Quote 0
                      • sorenS Offline
                        soren @robert-hh
                        last edited by

                        @robert-hh I can see with my multimeter that it's switching, but maybe that isn't accurate enough?

                        robert-hhR 1 Reply Last reply Reply Quote 0
                        • robert-hhR Offline
                          robert-hh @soren
                          last edited by robert-hh

                          @soren Switching while you toggle manually? or between duty cycle 0 and 1?
                          Edit: I see 74HCT125 has a high input level of 2V, like the 74LS125. It's the 74HC125 with the 3.15 V level. So theer should be no problem with the levels.

                          1 Reply Last reply Reply Quote 0
                          • L Offline
                            livius @soren
                            last edited by livius

                            @soren said in Controlling a servo with lopy (library or manually):
                            For me setup 1 not worked when i tested it in the past with MG996R.
                            It does not react properly on 3v3 range pwm.
                            Setup 2 should work but i do not use convertes in chip
                            i trust simple design as converter on simple transistor eg. 2N7000.

                            and to test if it work - try first run commands from terminal
                            pwm_c.duty_cycle(0.127 )
                            look at result but do not put sleep command
                            and decrese value
                            pwm_c.duty_cycle(0.117 )
                            pwm_c.duty_cycle(0.107 )
                            pwm_c.duty_cycle(0.097 )
                            ...

                            any results?
                            P.S. pwm_c.duty_cycle(1) is not good at all ;-)
                            i have done same mistake previously - as you can see in my post from the past

                            think about people first, then computers

                            robert-hhR sorenS 2 Replies Last reply Reply Quote 0
                            • robert-hhR Offline
                              robert-hh @livius
                              last edited by

                              @livius sleep() does not turn off the PWM.

                              L 1 Reply Last reply Reply Quote 0
                              • L Offline
                                livius @robert-hh
                                last edited by

                                @robert-hh
                                yes, but it is not needed from terminal - this was my intention

                                think about people first, then computers

                                1 Reply Last reply Reply Quote 0
                                • sorenS Offline
                                  soren @livius
                                  last edited by

                                  @livius I took everything apart, put it together and double cross checked several times the connections and then tried the pwm_c.duty_cycle() command from console - and it WORKED! @robert-hh I think time.sleep actually does affect pwm. At least it works now for me from console where I'm not using sleep - in contrast to what I did in the code.

                                  robert-hhR 1 Reply Last reply Reply Quote 0
                                  • robert-hhR Offline
                                    robert-hh @soren
                                    last edited by

                                    @soren Good that it works. But omitting the sleep() commands are hardly the reason. I checked with an oscilloscope that PWM output stays when sleep() is performed. It's more something else you did. I worked with these servos decades ago, and remember that the pulse width range they expect is pretty small, from 1 ms to 2ms, at a 20ms period, resulting at a PWM duty cycle range between 5% and 10%

                                    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