XIAO ESP32C3 pin mapping in MicroPython

Does anyone know the pin mapping used in MicroPython for XIAO ESP32C3? It looks like the MicroPython build is for “Generic” ESP32C3, i.e. ESP32_GENERIC_C3-20240105-v1.22.1.bin and gives an error “invalid data bits” on: uart = UART(0, 115200, 21, 20)
In Arduino the RX and TX pins defined as below works perfectly:

static const uint8_t TX = 21;
static const uint8_t RX = 20;

In fact, here is a citation from MicroPython’s reference, and pin 20 is not mentioned:

Available Pins are from the following ranges (inclusive): 0-19, 21-23, 25-27, 32-39. These correspond to the actual GPIO pin numbers of ESP32 chip. Note that many end-user boards use their own adhoc pin numbering (marked e.g. D0, D1, …). For mapping between board logical pins and physical chip pins consult your board documentation.

I just wanted to be able to use MicroPython as well on this chip, and it seems it maybe not fully supported. Any suggestions?
Thanks

//XIAO_ESP32C3

#ifndef Pins_Arduino_h
#define Pins_Arduino_h

#include <stdint.h>

#define EXTERNAL_NUM_INTERRUPTS 22
#define NUM_DIGITAL_PINS        22
#define NUM_ANALOG_INPUTS       6

#define analogInputToDigitalPin(p)  (((p)<NUM_ANALOG_INPUTS)?(analogChannelToDigitalPin(p)):-1)
#define digitalPinToInterrupt(p)    (((p)<NUM_DIGITAL_PINS)?(p):-1)
#define digitalPinHasPWM(p)         (p < EXTERNAL_NUM_INTERRUPTS)

static const uint8_t TX = 21;
static const uint8_t RX = 20;

static const uint8_t SDA = 6;
static const uint8_t SCL = 7;

static const uint8_t SS    = 20;
static const uint8_t MOSI  = 10;
static const uint8_t MISO  = 9;
static const uint8_t SCK   = 8;

static const uint8_t A0 = 2;
static const uint8_t A1 = 3;
static const uint8_t A2 = 4;
static const uint8_t A3 = 5;

static const uint8_t D0 = 2;
static const uint8_t D1 = 3;
static const uint8_t D2 = 4;
static const uint8_t D3 = 5;
static const uint8_t D4 = 6;
static const uint8_t D5 = 7;
static const uint8_t D6 = 21;
static const uint8_t D7 = 20;
static const uint8_t D8 = 8;
static const uint8_t D9 = 9;
static const uint8_t D10 = 10;

#endif /* Pins_Arduino_h */

Yes, I got the TX/RX defines from Arduino’s pins_arduino.h file, but they do not work in MicroPython - please see my description. Those defines work fine in Arduino.

Hello, if you are using the firmware under this Wiki, the pinout information is as shown in the @cgwaltney posting.

The firmware is designed for the ESP32C3 chip, so the GPIOs are defined based on the ESP32C3 chip.
For example, when you are trying to use the pin in the first row on the left. Make sure it is GPIO2 instead of A0 or D0.

Hello, thank you very much for following up! I found the problem was with my syntax:
uart = UART(0, 115200, 21, 20)
it should be:
uart = UART(0, 115200, tx=21, rx=20)
And yes, I verified every pin by toggling it and that led me to finally understanding the problem. Overall, I like this little MCU very much and making a good progress with my project. Thanks again

3 Likes