Built-in project · WCH CH32V003 (RISC-V, 16 KB)

CH32V003 blink

An LED on PD2 of the CH32V003, a tiny 16 KB RISC-V chip. The whole build, a WCH CH32V003 and 2 more parts, 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 10 minutes to build and run. Runs in your browser. Free, and no account needed.

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

The circuit runs here once the page has loaded.

What you'll learn

  • Lights
  • Choosing and reading a resistor
  • How an LED lights and why it needs a resistor
  • Difficulty: Beginner
  • Time: About 10 minutes
  • Board: WCH CH32V003 (RISC-V, 16 KB)
  • Parts: 4

How it works

An LED on PD2 of the CH32V003, a tiny 16 KB RISC-V chip.

WCH CH32V003 (RISC-V, 16 KB) runs the sketch below. The circuit around it: Resistor, 330 Ω, LED, red. pinMode sets LED as an output. digitalWrite drives LED HIGH. delay waits 500 milliseconds.

Parts list

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

Wiring table

Every connection, pin by pin, read from the circuit itself. Each row joins the pin on the left to the pin on the right, by a jumper wire or a breadboard strip.

Part and pinConnects to
LED, red pin CWCH CH32V003 (RISC-V, 16 KB) pin GND
Resistor, 330 Ω pin 1WCH CH32V003 (RISC-V, 16 KB) pin PD2
LED, red pin AResistor, 330 Ω pin 2

The code

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

sketch.ino · WCH CH32V003 (RISC-V, 16 KB)
// Blink: the smallest thing a board can do.
//
// The CH32V003 dev board has no LED of its own on every layout, so wire one:
// PD2 through a resistor (330 ohm is fine) to GND. PD2 is pin 19 of the
// TSSOP-20 chip.
//
// delay() here is a SysTick busy wait: this chip version has no interrupts
// yet, so the core does not sleep through it.

#define LED PD2

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

void loop() {
  digitalWrite(LED, HIGH);
  delay(500);
  digitalWrite(LED, LOW);
  delay(500);
}

Code walkthrough

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

setup sketch.ino

Runs once when the board starts. It gets the pins and libraries ready.

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

loop sketch.ino

Runs over and over for as long as the board has power. This is where the project does its work.

void loop() {
  digitalWrite(LED, HIGH);
  delay(500);
  digitalWrite(LED, LOW);
  delay(500);
}

Troubleshooting

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

  • The LED is dim, burns out, or the pin reads wrong because the resistor value is off. Resistor
    Read the color bands again. A 220 ohm to 330 ohm resistor suits a typical LED on 5 V. 10k is a common pull-up or pull-down value. Check with a multimeter if unsure.
  • A pull-up or pull-down resistor is missing, so the input floats and reads random values. Resistor
    Tie the input to 5 V or ground through about 10k. Or use INPUT_PULLUP and wire the switch to ground.
  • The LED does not light, or it lights once and then dies. LED
    LEDs have polarity. The longer leg (anode) goes toward the positive side. Always add a series resistor, about 220 ohms to 1 k ohm on a 5 V pin.
  • A blue or white LED stays dark on 3.3 V. LED
    Blue and white LEDs drop about 3 V, so 3.3 V leaves almost nothing for the resistor. Use a 5 V supply, or a smaller resistor and a red or green LED.

Change it and keep it

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