XIAO CircuitPython on-board LED control

Goal: I want to control all of the on-board LEDs by Python.

First: I am having trouble understanding the logical mapping of LEDs to the hardware pins. Is there a list somewhere that explains this? Pin 13 for the LED does not go to pin 13 on the schematic [ https://files.seeedstudio.com/wiki/Seeeduino-XIAO/res/Seeeduino-XIAO-v1.0-SCH-191112.pdf ].

Second: I see the following ports in the REPL:
[‘name’, ‘A0’, ‘A1’, ‘A10’, ‘A2’, ‘A3’, ‘A4’, ‘A5’, ‘A6’, ‘A7’, ‘A8’, ‘A9’, ‘BLUE_LED’, ‘D0’, ‘D1’, ‘D10’, ‘D13’, ‘D2’, ‘D3’, ‘D4’, ‘D5’, ‘D6’, ‘D7’, ‘D8’, ‘D9’, ‘I2C’, ‘LED’, ‘MISO’, ‘MOSI’, ‘RX’, ‘SCK’, ‘SCL’, ‘SDA’, ‘SPI’, ‘TX’, ‘UART’, ‘board_id’]

different formatting:

board.A0 board.D0
board.A1 board.D1
board.A10 board.D10 board.MOSI
board.A2 board.D2
board.A3 board.D3
board.A4 board.D4 board.SDA
board.A5 board.D5 board.SCL
board.A6 board.D6 board.TX
board.A7 board.D7 board.RX
board.A8 board.D8 board.SCK
board.A9 board.D9 board.MISO
board.BLUE_LED board.D13 board.LED

You can see the BLUE_LED does not map to the blue led, instead the amber/red on 13.

How can I control the blue LED? Is this locked out in this board?

It looks like you are using circuitpyhon … looking at those pin (pin.c) definiitions for the XIAO SAMD board the following LED definitions are made:

    // LED pins
    { MP_ROM_QSTR(MP_QSTR_LED),   MP_ROM_PTR(&pin_PA17) }, // status

which map both the LED, and BLUE_LED to the samd chip pins for PortA-17. In the schematic this chip pin goes to the amber LED on the board.

Chip pin PortA-18 goes to the blue LED used for uart RX
Chip pin PortA-19 goes to the blue LED used for uart TX

The circuitpython build will need to be modified to reference those pins (unless there is a low level function call … which I think would be counter to circuitpython philosophy.) I am not familiar with circuitpython - but I would guess the changes woud be pretty simple: Adding something like:

    // correct: LED pins
    { MP_ROM_QSTR(MP_QSTR_LED),   MP_ROM_PTR(&pin_PA17) }, // status
    // new LED pins
    { MP_ROM_QSTR(MP_QSTR_BLUERX),   MP_ROM_PTR(&pin_PA18) }, 

and then figuring out how to define MP_QSTR_BLUEx

It may be as simple as just adding to the pin.c file and recompiling.
see: micropython string interning
circuitpython is a fork of micropython.

1 Like

The latest circuitpython release (20220308 … ) will have the LED nomenclature corrected for the XIAO board.