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.
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.
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);According to that fragment, if the LED turns on for 1 second and off for 1 second inside loop(), what pattern should you observe?
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. 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.
Open the
stm32-nucleo-arduinolab with thestm32-nucleo-ide-arduinoaccess.In CodeIDE, open
main.ino.Replace the contents of
main.inowith the reference program below.Save the file.
Compile. If an error appears, check braces
{}, semicolons;, and pin names.Upload the program to the real board.
Observe the LED for at least three complete cycles.
Change both waits from
1000to a value between250and2000, compile, upload again, and compare.
#include <Arduino.h>
const int BLUE_LED = PB5;
void setup() {
pinMode(BLUE_LED, OUTPUT);
}
void loop() {
digitalWrite(BLUE_LED, HIGH);
delay(1000);
digitalWrite(BLUE_LED, LOW);
delay(1000);
}
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: original version with delay(1000).
- 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 | Observed pattern | Does it match the prediction? | Adjustment or problem |
|---|---|---|---|---|
Describe concrete evidence that your program ran on the real board. Include which output you observed and how it changed when you modified delay.
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.
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.
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.