Hands-on: ST Nucleo board with a shield


The mbed platform support has been expanded recently to include a new family of boards - the ST Nucleo. Four boards are supported at the time of this writing and ST's plans are to release a full line of STM32 Microcontrollers in the Nucleo family, all of which will have out-of-the-box support for the mbed ecosystem. In this blog post I'll show you how easy it is to use the a ST Nucleo board on mbed.

First, this is how the board packaging looks (click to enlarge):

Click to enlarge Click to enlarge

When connected for first time, the green LED blinks with a familiar rate, hinting that the preloaded program is in fact the mbed Blinky Hello World program. The USB storage device of the Nucleo contains an mbed.htm file, which, when clicked, takes me to the mbed website and gets the board added to my account.

Like the whole Nucleo family, the ST Nucleo L152RE has 2 type of headers - Arduino and Morpho. The Arduino header standard is popular for the compatibility and ease of use it offers. In this example I'm using the Arduino shield 16x2 LCD by Freetronics.

Click to enlarge Click to enlarge

This LCD already has a page in mbed Components, which provides an example program and library contributed by Koen Kempeneers.

Click to enlarge

Clicking on “Import program” takes me to the mbed Online Compiler to import the program into my workspace.

/media/uploads/screamer/2014-02-20_22-59-19.png

I'm opening main.cpp and the first thing I notice is that the initialization string for the LCD library is using Arduino pin names, meaning that I won't have to change them - everything is pre-set for me.

freetronicsLCDShield lcdshield(D8, D9, D4, D5, D6, D7, D3, A0);

Тhe second thing I notice is that the program is more than a Hello World program. It's a full-featured demo of the shield and library, which is somewhat too complex for my example.

I'm replacing the code with the simplified:

main.cpp

#include "mbed.h"
#include "freetronicsLCDShield.h"

freetronicsLCDShield lcdshield(D8, D9, D4, D5, D6, D7, D3, A0);

int main() {
    lcdshield.setBackLight(true);
    lcdshield.printf("mbed application");
}

And then hit "Compile" which successfully compiles my code and prompts me for a save location.

But before saving the compiled binary I'd like to attach the LCD shield. Note that some shields, like this LCD screen, use less pins than the full Arduino headers, so remember to be extra careful when attaching them. If you get it wrong you might damage the board and/or the shield.

Now that I have the LCD shield correctly mounted, I reconnect the board to the PC. The backlight turns on and the first row of the display filled with squares indicating that it's powered properly.

Click to enlarge

I then save the binary to the Nucleo’s USB storage device, which “consumes” the binary and restarts the board. A moment later the following text appears on the LCD screen:

Click to enlarge

Ah, sweet success!

7 comments on Hands-on: ST Nucleo board with a shield:

21 Feb 2014

Thanks Mihail for sharing this demo !

21 Feb 2014

So, all pins are 5v tolerant ?

22 Feb 2014

Checked in the datasheet, not all pins, but vast majority is. I would assume they took that into account when connecting the arduino headers, but didn't verify that.

Also many arduino shields use the reference pin to choose between 3.3V and 5V (this one doesn't though).

25 Feb 2014

options should be made to use GPIO or other pin(function) as 3.3V or 5V,as user selectable

27 Feb 2014

Of the pins the LCD shield uses, the A0 pin is not 5V tolerant, it is 3.3V tolerant directly connected to the ADC.

Sticking to the Arduino headers only, the 5V tolerant pins are D2 - D10 and D14, D15. The rest are 3.3V tolerant directly connected to the ADC. I found this information by checking in the datasheet.

17 Apr 2014

I love this board.

17 Apr 2014

A simple way around the 5V problem with A0. Is to set A0 as an output, and low. This will simply ground the pin. Unfortunately the buttons of this shield cannot be used with the nucleo due to the 5V issue. If you use Google you can find direction for modifying the shield so the buttons are pulled to 3V, and then you can use the buttons with the nucleo board.