Project 1: Blink an LED light on a breadboard

From LawrenceWiki
Jump to: navigation, search

Project 1: led_mine

Breadboard

Use CN9 connector on the stm32nucleo board.

  • Connect GND on CN9 connector to ground rail on breadboard
  • Connect D7 on CN9 to power rail
  • Connect short LED leg to ground rail and long leg onto board
  • Connect resistor (≤5K) from power rail to LED

Fritzing led mine.png

Figure 1: Fritzing diagram for the led_mine project. The CN9 connector on the stm32nucleo board is equivalent to the Arduino board.

Code

Enter this code into your favorite editor and save as led_mine.cpp.

#include "mbed.h"

// stm32nucleo pin D7 = Arduino 7 or D7 = PA_8
DigitalOut ledPin(PA_8);

int main()
{
    ledPin = 1;
    while(true)
    {
        wait(0.5f);
        ledPin = 0;
        wati(0.5f);
        ledPin = 1;
    }
}

mbed

Go to http://developer.mbed.org and click Compiler in the upper right corner.

Click New | New Program

Platform = NUCLEO-F401RE
Template = Empty Program
Program Name = led_mine

Right-click on led_mine and choose New File
File Name = main.cpp

Copy and paste your code into the main.cpp window. Click Save.

Right-click led_mine and choose Import Library | From Import Wizard. After libraries are loaded, click mbed then Import. Accept all the defaults by clicking Import.

Click once on main.cpp and click the Compile button. Correct errors and click Compile until you get Success! in the Compile Output window at the bottom of the compiler window. Mbed throws a BIN file in your Downloads folder.

Plug in the stm32nucleo board to your USB port. You should get a device icon on your desktop or in the file manager. Drag and drop the BIN file from the Downloads folder onto this icon.

Your LED should start blinking. If it doesn’t, try hitting the black reset button on the stm32nucleo.