XIAO ESP32-C6 PCB Design
platformio.iniIni
[env:xiao_esp32c6] platform = espressif32 board = seeed_xiao_esp32c6 framework = arduino lib_deps = fastled/FastLED@^3.7.8 monitor_speed = 115200
src/main.cppCpp
#include <Arduino.h> #include <Wire.h> #include <FastLED.h> static constexpr uint8_t LED_PIN = D3; // GPIO21 static constexpr uint8_t IMU_INT_PIN = D2; // GPIO2 static constexpr uint8_t SDA_PIN = D4; // GPIO22 static constexpr uint8_t SCL_PIN = D5; // GPIO23 static constexpr uint8_t MPU_ADDR = 0x68; static constexpr uint16_t NUM_LEDS = 40; static constexpr uint8_t BRIGHTNESS = 96; // Must remain current-limited CRGB leds[NUM_LEDS]; uint8_t mpuRead8(uint8_t reg) { Wire.beginTransmission(MPU_ADDR); Wire.write(reg); if (Wire.endTransmission(false) != 0) return 0xFF; if (Wire.requestFrom(MPU_ADDR, (uint8_t)1) != 1) return 0xFF; return Wire.read(); } bool mpuWrite8(uint8_t reg, uint8_t value) { Wire.beginTransmission(MPU_ADDR); Wire.write(reg); Wire.write(value); return Wire.endTransmission() == 0; } bool readAccel(int16_t &ax, int16_t &ay, int16_t &az) { Wire.beginTransmission(MPU_ADDR); Wire.write(0x3B); // ACCEL_XOUT_H if (Wire.endTransmission(false) != 0) return false; if (Wire.requestFrom(MPU_ADDR, (uint8_t)6) != 6) return false; ax = (int16_t)((Wire.read() << 8) | Wire.read()); ay = (int16_t)((Wire.read() << 8) | Wire.read()); az = (int16_t)((Wire.read() << 8) | Wire.read()); return true; } void setup() { Serial.begin(115200); pinMode(IMU_INT_PIN, INPUT); Wire.begin(SDA_PIN, SCL_PIN); Wire.setClock(400000); FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS); FastLED.setBrightness(BRIGHTNESS); FastLED.setMaxPowerInVoltsAndMilliamps(5, 2500); // LED budget only FastLED.clear(true); delay(100); const uint8_t who = mpuRead8(0x75); // WHO_AM_I, expected 0x68 Serial.printf("MPU WHO_AM_I: 0x%02X\n", who); if (who == 0x68) { mpuWrite8(0x6B, 0x00); // PWR_MGMT_1: wake, internal clock mpuWrite8(0x1C, 0x00); // ACCEL_CONFIG: ±2 g } } void loop() { int16_t ax, ay, az; if (readAccel(ax, ay, az)) { Serial.printf("accel %d %d %d\n", ax, ay, az); uint8_t hue = (uint8_t)map(constrain(ax, -16384, 16384), -16384, 16384, 0, 255); fill_solid(leds, NUM_LEDS, CHSV(hue, 255, BRIGHTNESS)); FastLED.show(); } delay(50); }
Table
| Function | XIAO pin | ESP32-C6 GPIO | Net |
|---|---|---|---|
| WS2812B data | D3 | 21 | LED_DATA_3V3_GPIO21_D3 |
| MPU SDA | D4 | 22 | I2C_SDA_GPIO22_D4 |
| MPU SCL | D5 | 23 | I2C_SCL_GPIO23_D5 |
| MPU INT | D2 | 2 | IMU_INT_GPIO2_D2 |
PlatformIO
Final Pin Mapping