Complete MicroPython development for XIAO boards. Use when writing MicroPython scripts for XIAO (ESP32C3/C5/C6/S3, RP2040/RP2350, nRF52840, nRF54L15)...
Complete MicroPython development guide for SeeedStudio XIAO series. This skill works with the /xiao skill - use /xiao for pin definitions, /xiao-micropython for MicroPython-specific APIs and libraries.
/xiao skill first for board-specific pin mappingsmpy-cross for fast offline syntax checking (recommended)For first-time MicroPython environment setup, see setup/:
setup/thonny-ide.mdsetup/esptool.mdsetup/mpy-cross.md (recommended for syntax validation)| Board | Firmware Download | Getting Started |
|---|---|---|
| ESP32C3 | micropython.org | getting-started/esp32c3.md |
| ESP32C5 | ESP32 generic (C3 works) | getting-started/esp32c5.md |
| ESP32C6 | micropython.org | getting-started/esp32c6.md |
| ESP32S3 | micropython.org | getting-started/esp32s3.md |
| RP2040 | micropython.org | getting-started/rp2040.md |
| RP2350 | micropython.org | getting-started/rp2350.md |
| nRF52840 | Community port | getting-started/nrf52840.md |
| nRF54L15 | Seeed port | getting-started/nrf54l15.md |
Note: SAMD21, MG24 MicroPython support is limited or requires community forks.
MicroPython projects typically use these file patterns:
main.py - Main application script (auto-runs on boot)boot.py - Initialization script (runs before main.py)config.py - Configuration constants and settingslib/ - Custom library modulesMicroPythonProject/
βββ main.py # Main application (auto-runs)
βββ boot.py # WiFi/initialization
βββ config.py # Pin definitions, settings
βββ lib/
βββ wifi.py # WiFi connection module
βββ sensor.py # Sensor driver module
When a user requests MicroPython code generation, you MUST:
Write tool to create the actual .py file(s)xiao_expansion_base_rtc.py or a full project with main.py, config.py, etc.mpy-cross to verify syntaxpip install esptool
esptool.py --chip esp32c3 --port COM3 write_flash -z 4MB 0 firmware.bin
from machine import Pin
import time
led = Pin(10, Pin.OUT) # D10
while True:
led.value(1)
time.sleep(1)
led.value(0)
time.sleep(1)
| Module | Reference | Usage |
|---|---|---|
| GPIO (machine.Pin) | api/gpio.md |
Digital I/O, interrupts |
| PWM (machine.PWM) | api/pwm.md |
Analog output, servo control |
| ADC (machine.ADC) | api/adc.md |
Analog input reading |
| I2C (machine.I2C) | api/i2c.md |
Sensor communication |
| SPI (machine.SPI) | api/spi.md |
High-speed peripherals |
| UART (machine.UART) | api/uart.md |
Serial communication |
from machine import Pin
led = Pin(10, Pin.OUT)
led.on() # Turn on
led.off() # Turn off
led.toggle() # Toggle
button = Pin(6, Pin.IN, Pin.PULL_UP)
if button.value() == 0:
print("Pressed")
from machine import I2C, Pin
i2c = I2C(0, scl=Pin(1), sda=Pin(0), freq=100000)
devices = i2c.scan()
print(f"I2C devices: {[hex(d) for d in devices]}")
| Module | Reference | Usage |
|---|---|---|
| WiFi (network.WLAN) | api/wifi.md |
Wireless connectivity |
| HTTP (urequests) | api/http.md |
Web requests |
| MQTT (umqtt) | api/mqtt.md |
IoT messaging |
| BLE (bluetooth) | api/ble.md |
Bluetooth Low Energy |
| Socket | api/socket.md |
TCP/UDP networking |
import network
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect('SSID', 'password')
while not wlan.isconnected():
time.sleep(1)
print(f'IP: {wlan.ifconfig()[0]}')
import urequests
response = urequests.get('http://httpbin.org/get')
print(response.text)
response.close()
| Library | Reference | Usage |
|---|---|---|
| SSD1306 | libraries/ssd1306.md |
OLED displays |
| BME280 | libraries/bme280.md |
Weather sensors |
| NeoPixel | libraries/neopixel.md |
RGB LEDs |
| DHT | libraries/dht.md |
Temp/Humidity sensors |
| SD (sdcard) | libraries/sdcard.md |
SD card storage |
from machine import Pin, I2C
import ssd1306
i2c = I2C(0, sda=Pin(0), scl=Pin(1))
oled = ssd1306.SSD1306_I2C(128, 64, i2c)
oled.fill(0)
oled.text("Hello XIAO!", 0, 0)
oled.show()
Quick syntax validation (no device needed):
# Install mpy-cross
pip install mpy-cross
# Verify syntax
mpy-cross script.py
# β
No error = valid, β SyntaxError = fix code
Device testing (optional):
# Install mpremote
pip install mpremote
# Test on device
mpremote run script.py
For detailed verification workflow, see setup/mpy-cross.md and setup/mpremote.md.
api/esp32-sleep.mdapi/esp32-ble.mdapi/esp32s3-camera.mdapi/nrf-sleep.mdapi/nrf-ble.mdapi/rp-sleep.mdapi/rp2040-pio.mdXIAO expansion boards add peripherals. For hardware specs, see /xiao/references/expansion_boards/.
| Expansion Board | Key Features | Reference |
|---|---|---|
| Expansion Base | OLED, RTC, SD card, buzzer | expansion-boards/expansion-base.md |
| Round Display | 1.28" touchscreen | expansion-boards/round-display.md |
| Grove Shield | 8 Grove connectors | expansion-boards/grove-shield.md |
| CAN Bus | MCP2515 controller | expansion-boards/can-bus.md |
| GPS/GNSS | L76K GNSS module | expansion-boards/gps-gnss.md |
from machine import Pin, I2C
import ssd1306
import time
# OLED (I2C address 0x3C)
i2c = I2C(0, sda=Pin(0), scl=Pin(1))
oled = ssd1306.SSD1306_I2C(128, 64, i2c)
oled.fill(0)
oled.text("XIAO Base", 0, 0)
oled.show()
# RTC (DS3231, I2C address 0x68)
def set_rtc(datetime_tuple):
i2c.writeto(0x68, bytes([0x00] + list(datetime_tuple)))
def get_rtc():
i2c.writeto(0x68, b'\x00')
data = i2c.readfrom(0x68, 7)
return (data[0], data[1], data[2])
# SD Card (SPI)
import sdcard, machine
sd = sdcard.SDCard(machine.SPI(0), machine.Pin(4))
vfs = os.VfsFat(sd)
os.mount(vfs, '/sd')
with open('/sd/data.txt', 'w') as f:
f.write('Hello from XIAO!')
import time
def main():
while True:
try:
# Your code here
time.sleep(1)
except Exception as e:
print(f"Error: {e}")
time.sleep(5)
if __name__ == "__main__":
main()
import time
last_check = 0
interval = 5000 # 5 seconds
while True:
current = time.ticks_ms()
if time.ticks_diff(current, last_check) >= interval:
last_check = current
# Do periodic task
# Other code here
| Issue | Solution |
|---|---|
OSError: [Errno 5] |
Check I2C/SPI pins with /xiao skill |
ImportError |
Verify module exists in firmware |
| WiFi won't connect | Ensure 2.4GHz network (ESP32 only) |
| Board won't upload | ESP32: Hold BOOT; RP2040: Hold BOOTSEL |
setup/thonny-ide.md - Thonny IDE installationsetup/esptool.md - Firmware flashingsetup/mpy-cross.md - Offline syntax verificationsetup/mpremote.md - Device testing and deploymentBoard-specific setup instructions.
MicroPython module documentation (GPIO, I2C, WiFi, BLE, sleep, etc.)
Common libraries (SSD1306, BME280, NeoPixel, etc.)
Complete project examples:
examples/weather-station.md - BME280 weather station with MQTTexamples/ble-peripheral.md - BLE environmental sensorexamples/mqtt-sensor.md - MQTT temperature/humidity sensor/xiao - Core board reference with pin definitions/xiao-arduino - Arduino development/xiao-esphome - ESPHome configuration