element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Members
    Members
    • Benefits of Membership
    • Achievement Levels
    • Members Area
    • Personal Blogs
    • Feedback and Support
    • What's New on element14
  • Learn
    Learn
    • Learning Center
    • eBooks
    • STEM Academy
    • Webinars, Training and Events
    • More
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • More
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • More
  • Products
    Products
    • Arduino
    • Dev Tools
    • Manufacturers
    • Raspberry Pi
    • RoadTests & Reviews
    • Avnet Boards Community
    • More
  • Store
    Store
    • Visit Your Store
    • Choose Another Store
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
Sixth Sense Design Challenge
  • Challenges & Projects
  • Design Challenges
  • Sixth Sense Design Challenge
  • More
  • Cancel
Sixth Sense Design Challenge
Blog Programming Nucleo-F411RE with MBED- Automatic Weeding Robot #12
  • Blog
  • Forum
  • Documents
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Blog Post Actions
  • Subscribe by email
  • More
  • Cancel
  • Share
  • Subscribe by email
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
Author: weiwei2
Date Created: 24 Mar 2019 6:55 PM
Views: 256
Likes: 1
Comments: 1
  • powerbank
  • nucleo-f411re
  • always_on
  • mbed
Related
Recommended

Programming Nucleo-F411RE with MBED- Automatic Weeding Robot #12

weiwei2
weiwei2
24 Mar 2019

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)

Parameters

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.)

pinMode
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
  while(1);
}

analogWrite(pin, value)

Parameters

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 );
  wait(0.5);

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

digitalWrite(pin, value)

Parameters

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

 

Testing

 

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
        
        JogForward();
        JogForward();
        JogBackward();
        JogBackward();
    }
}

 

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

   

You don't have permission to edit metadata of this video.
Edit media
x
Upload Preview

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

You don't have permission to edit metadata of this video.
Edit media
x
Upload Preview

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

Anonymous
  • DAB
    DAB over 3 years ago

    Nice update.

     

    DAB

    • Cancel
    • Up 0 Down
    • Reply
    • More
    • Cancel
Element14

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2022 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • Facebook
  • Twitter
  • linkedin
  • YouTube