breadboard
docs

Example project · Start here

Nucleo-F411RE · MicroPython LED and button

Boot official MicroPython over the ST-LINK UART console. Code pulses the onboard LED, prints the active-low button, then leaves the LED lit. When Serial prompts, press and release B1 to read 0 then 1; the script waits for you. First boot formats the filesystem and can take about two minutes of wall time.

The Nucleo-F411RE · MicroPython LED and button circuit as rendered by the simulator

What's on the bench

  • ST Nucleo-F411RE

The code

This MicroPython script runs on the emulated board every boot; edit it in Code.

from machine import Pin
from time import sleep_ms
led = Pin('D13', Pin.OUT)
button = Pin('SW', Pin.IN)
for state in (1, 0, 1):
    led.value(state)
    print('NUCLEO LED', state, 'BUTTON', button.value())
    sleep_ms(250)
print('Press B1 now')
while button.value():
    sleep_ms(20)
print('BUTTON_PRESSED', button.value())
while not button.value():
    sleep_ms(20)
print('BUTTON_RELEASED', button.value())

Related projects