6 days, 18 hours ago.

Control classic Servo Motor with STM32 and Mbed library

I'm using STM32 F401RE board and i'm trying to do a very simple thing. I want to control a servo (0-180). The problem is that it looks like it doesn't respound to my commands.

include the mbed library with this snippet

#include "mbed.h"

PwmOut myServo(D9);

int main() {
    myServo.period_ms(20);    

    while(1)
    {
        myServo.pulsewidth_ms(1);
    }
}

The Servo Motor i'm using. At the beginning i though something is wrong with my board pinout or pinout meaning, but it seems like D9 is the same with PC_7. My servo is properly installed and is supplyed by 5V source. I tried many tutorials i've found online but no one worked.

If i generate the same PWM with an oscilloscope it does work.

Comment on this question

2 Answers

5 days, 21 hours ago.

Hi there,

That part of code need to be before the while loop I think.

myServo.pulsewidth_ms(1);

Check the documentation and examples about PwmOut.

  • Try to check this page about a SERVO.
  • When you use different power supply for the servo then to power the MCU, you need to have connected all GND together I think.
  • PC_7 is standard marking of the seventh pin on Port C of the chip and D9 is marking what according to the arduino header. D9 and PC_7 is one same pin (line 137).

BR, Jan

5 days, 20 hours ago.

Hi,

I recommened to use name PC_7 -> PwmOut myServo(PC_7);

Regards, Pekka


You need to log in to post a question