Teach Remote lab lessons

Teach lesson

STM32 with Arduino API (1/4): first blink

Students use STM32 CodeIDE with the Arduino API to write setup() and loop(), blink a real output, and document compile/upload evidence.

  • STM32 Nucleo (Arduino)
  • 50 min
  • Grade 10-12 / introductory vocational electronics
  • English
  • Embedded systems
Reference photo of the STM32 Nucleo WB55RG board, without the external components of the remote setup.
STM32 Nucleo (Arduino)

Learning Outcomes

  • Write a minimal Arduino sketch for an STM32 board.

  • Distinguish the code that prepares the board from the code that repeats.

  • Record observable evidence from a real digital output.

Student activity preview

Activity Content

Preview only. In a class session, students can fill in responses and submit their work to the teacher.

1

Before opening the lab

8 min

A microcontroller does not "understand" sentences: it executes concrete
instructions. Today we only need one digital output, one LED, and two waits.

In an Arduino sketch:

- setup() runs once and prepares the board.
- loop() repeats while the board is powered.
- pinMode(pin, OUTPUT) declares that a pin will be an output.
- digitalWrite(pin, HIGH) sets an output high; LOW turns it off.

The main cycle will have this shape:

digitalWrite(BLUE_LED, HIGH);
delay(1000);
digitalWrite(BLUE_LED, LOW);
delay(1000);

If the LED is on for 1000 ms and off for 1000 ms inside loop(), which
pattern should repeat?

2

Create and test the blink

24 min

This photo helps you recognize the STM32 Nucleo WB55RG board. The photo shows
the board by itself; in the real remote lab, the board is part of a pre-wired
setup with LEDs and other components already connected. You do not need to wire
anything: you will use an LED that is already available in that remote setup.

Reference photo of the STM32 Nucleo WB55RG board, without the external components of the remote setup.

Reference photo of the STM32 Nucleo WB55RG board. In the remote lab, the board
is part of a pre-wired setup; in this first session you will use it like a
text-based Arduino board: write, compile, upload, and observe.

  1. Launch the lab from this block. In CodeIDE, select the main.ino editor tab.

  2. Replace its contents with the starter program below.

  3. Replace TODO 1-4. Each comment says what kind of code belongs there without

  4. supplying the token. Search main.ino for TODO; **zero TODOs may remain

  5. before compilation**.

  6. Save main.ino, choose Compile, and wait for a successful build message.

  7. Compile checks and translates the code; it does not change the real board.

  8. Only after compilation succeeds, choose Upload and wait for the upload

  9. success message. Upload installs that compiled version on the board.

  10. Observe the blue LED for at least three complete on/off cycles. Record this

  11. unchanged initial behavior in row 1.

  12. Change only BLINK_MS to a different visible interval from 250 ms to

  13. 2000 ms. Save, compile, upload, observe three cycles, and record row 2.

#include <Arduino.h>

const int BLUE_LED = PB5;
const int BLINK_MS = TODO_BLINK_INTERVAL;  // TODO 1: one-second interval, in ms

void setup() {
  pinMode(BLUE_LED, TODO_LED_DIRECTION);  // TODO 2: mode that lets the pin drive the LED
}

void loop() {
  digitalWrite(BLUE_LED, TODO_LED_ON_LEVEL);   // TODO 3: level for the on action
  delay(BLINK_MS);
  digitalWrite(BLUE_LED, TODO_LED_OFF_LEVEL);  // TODO 4: opposite level for the off action
  delay(BLINK_MS);
}

Fill in the table after testing the program on the board. Use only two rows and
leave the others blank if Teach shows more:

- Row 1: completed starter version with a 1000 ms interval.
- Row 2: your modified version.
- In Observed pattern, write what you saw on the real board.
- In Adjustment or problem, write none if it worked, or what you would
check if it did not match.

Version tested Delay value (ms) Observed pattern Does it match the prediction? Adjustment or problem

Describe concrete evidence that your program ran on the real board. Name the
output, give both delay values in ms, and compare at least three initial
cycles with at least three modified cycles.

3

Submit your code

8 min

Before submitting, leave the final code saved in main.ino. Your teacher should
be able to see the pin you used, pinMode, the two digitalWrite calls, and
the delay value you tested. Search once more for TODO; the submitted file
must contain none.

Submit your final main.ino

Save main.ino before attaching it. The snapshot must show the final program you compiled, uploaded to the board, and want your teacher to review.

4

Exit ticket

10 min

Explain the difference between setup() and loop() using your blink program as an example. Add why it is useful to change only one thing at a time while debugging.