Controlling a servo with lopy (library or manually)
-
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
-
-
@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?? :)
-
@soren
yes, what do you tiried already?
How your setup looks like? -
@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 GNDSetup #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.
-
@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. -
@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" ?
-
@soren Software
-
@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.
-
@robert-hh I can see with my multimeter that it's switching, but maybe that isn't accurate enough?
-
@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. -
@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 putsleepcommand
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 -
@livius sleep() does not turn off the PWM.
-
@robert-hh
yes, but it is not needed from terminal - this was my intention -
@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.
-
@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%
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