Skip to main content

Using XIAO RP2040 on MicroBlocks

MicroBlocks

MicroBlocks is a blocks-language that makes it easy for beginners (9 years to adults) to program microcontrollers. Yet in spite of its apparent simplicity, MicroBlocks is a powerful programming language with better performance than MicroPython; the ability to control GPIO pins and interface to peripherals via I2C, SPI, and serial; and nearly 200 extension libraries. In fact, some hardware designers prefer MicroBlocks for rapid prototyping and testing because of its fast, interactive development cycle.

XIAO RP2040 Pinout and Hardware Features



This board has 11 GPIO pins (pins 0..10). Pins 0..3 can be analog inputs. It also has three tiny LEDs: red (pin 11, the user LED), green (pin 12), and blue (pin 13). All LEDs are inverted: set the associated pin LOW to turn the LED on.

This board also has a single RGB LED (NeoPixel) on pin 14.

Installing the MicroBlocks Firmware

To enter bootloader mode, hold down the B (boot) button while clicking the R (reset) button. All three LEDs will light and a virtual USB drive named RPI-RP2 will appear.

Download the firmware file, from the vm folder then drag the file onto the virtual USB drive.

The firmware will install and, after a few seconds, the virtual USB drive will disappear. You can ignore any warning that the disk was not ejected properly.

Connecting the board to MicroBlocks

Connect the board to your computer with a data USB cable (not a power-only cable).

Run the MicroBlocks editor in a Chrome or Edge browser. Click the connect (plug icon) button:

Select connect (USB) from the menu:

Select your board from the dialog and click the connect button:

A green circle and the board name will appear when the board is connected:

Coding in MicroBlocks

MicroBlocks is a live coding environment so you can test as you code. Click on blocks and scripts to run them. Drag blocks into the scripting pane and assemble them to create scripts.

Your code is stored in persistent flash memory and can run even when the board is not connected to the MicroBlocks editor. Scripts under a when started block run when the board is powered.

MicroBlocks supports concurrency. Up to ten scripts can run at the same time.

In addition to its many built-in blocks, MicroBlocks has nearly 200 libraries that support additional features and peripherals. Click the Add Library button to add libraries.

Examples

This script will cycle through the red, blue, and green LEDs:

This script will make the RGB NeoPixel change color:

The Blocks Reference includes many additional examples.

Special Thanks

Special thanks to John at MicroBlocks for writing the article.

MicroBlocks Resources

Loading Comments...