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.
Sign in with an educator account to prepare a class session. Students join with a class code.
New to LabsLand? Create your teacher account
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;LOWturns 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?
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.
Launch the lab from this block. In CodeIDE, select the
main.inoeditor tab.Replace its contents with the starter program below.
Replace TODO 1-4. Each comment says what kind of code belongs there without supplying the token. Search
main.inoforTODO; zero TODOs may remain before compilation.Save
main.ino, choose Compile, and wait for a successful build message. Compile checks and translates the code; it does not change the real board.Only after compilation succeeds, choose Upload and wait for the upload success message. Upload installs that compiled version on the board.
Observe the blue LED for at least three complete on/off cycles. Record this unchanged initial behavior in row 1.
Change only
BLINK_MSto a different visible interval from250 msto2000 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 msinterval. - Row 2: your modified version.
- In Observed pattern, write what you saw on the real board.
- In Adjustment or problem, write
noneif 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.
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.
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.
Turn this preview into a live class session
Continue to LabsLand Teach to use this lesson with your students and review the access available to your account.
New to LabsLand? Create your teacher account