MBED maintains all the supported board programming reference at https://os.mbed.com/platforms/


For our board, F411RE, it can be referred at https://os.mbed.com/platforms/st-nucleo-f411RE/

i copy some of the essence here

Converting from Arduino

The Nucleo-F411RE has arduino compatible pinout. However, to use some of library created orginally for Arduino, we need to do some conversion from the arduino code to MBED.

When naming the pin, it is best to use the pin name under "MCU pin without conflict", those in blue colour. However, arduino pin name, LEDs and Buttons, MCU pins connected to other components

are also usable


The table below map the programming code in Arduino to the equivalent in MBED

TypeMBED codeExampleArduino CodeExample
digital pin definitionrefer to https://os.mbed.com/docs/mbed-os/v5.11/apis/drivers.html

pinMode(pin, mode)


pin: the number of the pin whose mode you wish to set

mode: INPUT, OUTPUT, or INPUT_PULLUP. (see the (digital pins) page for a more complete description of the functionality.)

PWM outputPwmOutPwmOut led(LED1);

int main() {
  // specify period first
  led.period(4.0f); // 4 second period
  led.write(0.50f); // 50% duty cycle, relative to period
  //led = 0.5f; // shorthand for led.write()
  //led.pulsewidth(2); // alternative to led.write, set duty cycle time in seconds

analogWrite(pin, value)


pin: the pin to write to. Allowed data types: int.
value: the duty cycle: between 0 (always off) and 255 (always on). Allowed data types: int

pinMode(_pin1, OUTPUT);


analogWrite(_pin1, speed);

digital write

DigitalOut myled(LED1);


int main()
  // check that myled object is initialized and connected to a pin
  if(myled.is_connected()) {
  printf("myled is initialized and connected!\n\r");

  // Blink LED
  while(1) {
  myled = 1; // set LED1 pin to high
  printf("myled = %d \n\r", (uint8_t)myled );

  myled.write(0); // set LED1 pin to low
  printf("myled = %d \n\r",myled.read() );

digitalWrite(pin, value)


pin: the pin number

value: HIGH or LOW

pinMode(_pin2, OUTPUT);


digitalWrite(_pin2, LOW);


IO Voltage

A check on https://www.st.com/en/evaluation-tools/nucleo-f411re.html  reveals that F411RE is 3.3V logic

however, the motor driver board i use MD13s is 3.3V to 5V logic tolerant




The F411RE provides a user LED, named as "LED1" for its label used in coding (but labelled as LD2 on the board)


To do a simple testing, i use the code snippet as below, where JogForward and JogBackward simple move the bot forward or backward

The LED2 on the F411RE is kept blinking to indicate that it is alive and running

i use the Arduino connector name for the motor function

#include "mbed.h"
#include "CytronMotorDriver.h"

DigitalOut myled(LED1);
CytronMD motorRight(PWM_DIR,D3,D4); //D3==PB_3 for PWM, D4=PB_5 for direction
CytronMD motorLeft(PWM_DIR,D5,D7); //D5==PB_4 for PWM, D7=PA_8 for direction
void JogForward();
void JogBackward();

int main() {
    while(1) {
        //LED blinking to indicate it is running
        myled = 1; // LED is ON
        wait(0.2); // 200 ms
        myled = 0; // LED is OFF
        wait(0.2); // 200ms


I use PicoScope 5444D MSO to capture the PWM and direction control pin for both my left motor and right motor. The video shows the LED is blinking, indicating it is alive

An always on powerbank is used to power the Nucleo-F411RE. It is also the final battery to be used for the MCU and sensor

pwm and dir signal testing with PicoScope 5444D MSO   

Here is a the PWM and direction capture for left and right motor (look at the digital capture. The analog channel is not used). i create 2 groups, one for right motor, another for left motor

Testing with the Automatic Weeding Bot

After verifying that the PWM and direction pin is providing output, i connect it to the bot and see it running forward and backward