Blink a LED with STM32 Nucleo

STM32 Nucleo

On the previous tutorial, we managed to create our first program with the STM32 Nucleo board. Now we will dig deeper on the pinout and other functionalities of the board.

The ST Nucleo F103RB page on the Mbed website contains information about the Arduino header pins of the board. Here is the top-left side:

/media/uploads/adustm/nucleo_f103rb_arduino_left_2016_7_21_1.png

You’ll see that the pin assignments is very much like the Arduino UNO. In fact, you can use the same pin names (A0, A1, etc.) when programming in Mbed.

[the_ad id="3059"]

Here’s the top-right side:

/media/uploads/adustm/nucleo_f103rb_arduino_right_2016_7_21_1.png

Again, the similarities with the Arduino UNO is still there, making the Nucleo board compatible with Arduino shields.

Besides the Arduino headers, there are also Morpho headers which gives the user access to all of the pins of the STM32F10RB:

/media/uploads/adustm/nucleo_f103rb_morpho_left_2016_7_21_1.png

[the_ad id="3059"]

/media/uploads/adustm/nucleo_f103rb_morpho_right_2016_7_21_1.png

This gives us an additional 76 pins to work with, much more than the Arduino Mega!

With knowledge on the pin names, I am ready to create some more programs. I attached an LED to D5 using the Grove shield:

STM32 Nucleo with LED attached

[the_ad id="3059"]

Then I created a program that blinks the LED faster and faster:

#include "mbed.h"

DigitalOut myled(D5);

float i;

int main() {
    while(1) {
        for(i = 0.5; i!=0.1; i=i-0.01){
            myled = 1;
            wait(i);
            myled = 0;
            wait(i);
        }  
    }
}

The LED still blinks if I change the pin name from D5 to PB_4 (which is standard STM32 naming):

#include "mbed.h"

DigitalOut myled(PB_4);

float i;

int main() {
    while(1) {
        for(i = 0.5; i!=0.1; i=i-0.01){
            myled = 1;
            wait(i);
            myled = 0;
            wait(i);
        } 
    }
}

Here’s the video showing the LED blinking:

On the next part of this tutorial, I will show you how to include a button to control the blinking of the LED.

 

Next >> Input and Output