Built-in project · Seeed XIAO RP2040

XIAO RP2040 blink

The red user LED of the XIAO RP2040, on GPIO 17, which lights when the pin is LOW. The whole build, a Seeed XIAO RP2040, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.

Teaching? Assign it to your class in one click.

Beginner About 5 minutes to build and run. Runs in your browser. Free, and no account needed.

The parts retail for about $10.40. On Mokxi they're free.

The circuit runs here once the page has loaded.

What you'll learn

  • Blinking a built-in LED
  • Setting a pin as an output
  • Active low LEDs that light on LOW
  • Timing with delay
  • Difficulty: Beginner
  • Time: About 5 minutes
  • Board: Seeed XIAO RP2040
  • Parts: 2

How it works

The XIAO RP2040 has a red user LED built into the board, so nothing needs wiring. The sketch turns it on and off every half second.

This LED is wired so that it lights when the pin is LOW, which is the opposite of what you might expect. So the sketch writes LOW to turn it on and HIGH to turn it off.

LED_BUILTIN is the name Arduino gives the board's own LED, GPIO 17 on this board.

Parts list

2 parts, plus the jumper wires. They retail for about $10.40; on Mokxi they're free.

The code

The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.

sketch.ino · Seeed XIAO RP2040
// Blink: the red user LED, GPIO 17, which lights when the pin is LOW.

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  digitalWrite(LED_BUILTIN, LOW);  // on
  delay(500);
  digitalWrite(LED_BUILTIN, HIGH); // off
  delay(500);
}

Code walkthrough

The key functions of the sketch, and what each one does.

setup sketch.ino

It runs once and sets LED_BUILTIN as an output with pinMode, so the sketch can control the LED.

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
}

loop sketch.ino

It runs over and over. It writes LOW to turn the LED on and waits 500 ms. Then it writes HIGH to turn it off and waits another 500 ms.

void loop() {
  digitalWrite(LED_BUILTIN, LOW);  // on
  delay(500);
  digitalWrite(LED_BUILTIN, HIGH); // off
  delay(500);
}

Troubleshooting

The usual mistakes with this circuit, and the fix for each.

  • The LED seems to be on when the code says off. This project
    This LED is active low. LOW turns it on and HIGH turns it off.
  • You want to blink faster or slower. This project
    Change the two numbers in delay. They are in milliseconds.
  • Wrong pin lights up, because the D numbers and the GPIO numbers are mixed. Seeed XIAO RP2040
    The XIAO has silkscreen pins D0 to D10 that map to different RP2040 GPIO numbers. Use the pin names from your board package or look up the mapping.
  • The user LED seems backwards: on when the pin is low. Seeed XIAO RP2040
    The three-color user LED is wired to 3.3 V, so it lights when the pin is LOW. Write LOW to turn a color on and HIGH to turn it off.

Change it and keep it

Open it in the editor, change the circuit or the code, and keep your version in a free account.