Page 1 of 1

Servo in STM32 port

Posted: Tue Dec 14, 2021 7:03 pm
by cyrano1960
Hello, in the source code of the stm32 port there are servo.h and servo.c files in the root directory of this port. But when I compile it I can´t import it. I have tried various possible ways:

Code: Select all

from Servo import servo
from pyb import Servo
and some other variations. I have listed all importable module with:

Code: Select all

help('modules')
and examine singel modules using:

Code: Select all

help(modulename)
but I can´t find the Servo module anyway... What am I doing wrong? I am using a NUCLEO-L476RG board.

Noch ein Nachtrag: die PWM-Klasse finde ich auch nicht :?

Re: Servo in STM32 port

Posted: Tue Dec 14, 2021 8:13 pm
by dhylands
If you look at servo.c you'll see that the entire file is wrapped in a #if MICROPY_HW_ENABLE_SERVO:
https://github.com/micropython/micropyt ... ervo.c#L35

The pyboard enables it in it's mpconfigboard.h file:
https://github.com/micropython/micropyt ... oard.h#L10

Note that the actual pins used by servo.c are hardcoded: https://github.com/micropython/micropyt ... .c#L80-L90

and the timers which are used are also hard-coded (i.e. it uses channels 1 thru 4 of TIM5): https://github.com/micropython/micropyt ... #L126-L132

If you can live with those restrictions then you can probably enable MICROPY_HW_ENABLE_SERVO in your mpconfigboard.h file.

Re: Servo in STM32 port

Posted: Tue Dec 14, 2021 9:01 pm
by cyrano1960
Hi Dave,
again you are my angel of Salvation :P

Thanks a lot!

Re: Servo in STM32 port

Posted: Mon Jan 17, 2022 4:07 pm
by henryd
Has anyone got this to work correctly?
I have an STM32 based pyboard and cannot get the builtin Servo module to turn to an angle less than 0 degrees.
A typical SG90 servo has a midpoint of 1500 microsec, 90 degrees at 2500, -90 at 1000.
servo.calibration() shows values that correspond to the above.
Sending the servo to any negative angle and the doing servo.pulse_width() always shows 1500 i.e. 0 degrees

Re: Servo in STM32 port

Posted: Mon Jan 17, 2022 4:30 pm
by henryd
Further to my previous post, I did some more experimentation
I set calibration as s4.calibration(640,2400,640,2470,2200)
Then manages to get to servo to move through 180 degrees as follows
servo.angle(0) went to left extreme
servo.angle(45) went to midpoint - 90 degrees
servo.angle(90) went to right extreme.

Comments?