Start Seeed XIAO RP2040 on PlatformIO

For some reason, PlatformIO hasn’t merged support for other RP2040 boards to its platform. So we have to do it manually.

PIO Home > Platforms > Advanced Installation and add:

 https://github.com/maxgerhardt/platform-raspberrypi.git
Seeed Xiao RP2040 install on PlatformIO

It has support for lots of RP2040-based boards. The full list is here.

Platformio.ini file

For now (21.08.2023), the PlatformIO Project Wizard does not create XIAO RP2040 project files. and therefore we add platform info manually to the project.

Add platform info directly to the platformio.ini file. When you run it the first time it installs all the necessary files. It can take a lot of time.

[env:seeed_xiao_rp2040];
platform = https://github.com/maxgerhardt/platform-raspberrypi.git#develop
board = seeed_xiao_rp2040
framework = arduino

Pins

Seeed Xiao RP2040 pins

My test code:

#include <Arduino.h>
#include <Adafruit_NeoPixel.h>

const int pin_0 = 0;
const int pin_1 = 1;
const int pin_2 = 2;
const int pin_3 = 3;
const int pin_4 = 4;
const int pin_6 = 6;
const int pin_7 = 7;
const int pin_26 = 26;
const int pin_27 = 27;
const int pin_28 = 28;
const int pin_29 = 29;

const int user_led_green = 16;
const int user_led_red   = 17;
const int user_led_blue  = 25;

const int rgb_power_pin  = 11;
const int rgb_data_pin   = 12;

constexpr int num_of_pins = 16;
int all_pins[num_of_pins] = {
  pin_0,
  pin_1,
  pin_2,
  pin_3,
  pin_4,
  pin_6,
  pin_7,
  pin_26,
  pin_27,
  pin_28,
  pin_29,
  user_led_green,
  user_led_red,
  user_led_blue,
  rgb_power_pin,
  rgb_data_pin
};

constexpr int NUM_RGB_COLORS = 5;
int rgb_colors[NUM_RGB_COLORS][3] = {
  {254,10,10},
  {10,254,10},
  {10,10,254},
  {254,254,10},
  {10,254,254}
};

// https://learn.microsoft.com/en-us/cpp/cpp/constexpr-cpp?view=msvc-170&viewFallbackFrom=vs-2019
constexpr int RGB_PIXELS = 1;

constexpr int DELAY_TIME = 500;

Adafruit_NeoPixel pixels(RGB_PIXELS, rgb_data_pin, NEO_GRB + NEO_KHZ800);

void setup() {
  Serial.begin(115200);

  for (int i = 0; i < num_of_pins; i++){
    pinMode(all_pins[i], OUTPUT);
  }

  digitalWrite(rgb_power_pin, HIGH); // RGB Power ON

  pixels.begin();
}

void loop() {

  // Pins test
  for (size_t i = 0; i < (num_of_pins-2); i++){
    digitalWrite(all_pins[i], HIGH);
    delay(DELAY_TIME);
    digitalWrite(all_pins[i], LOW);
    delay(DELAY_TIME);
  }

  // RGB LED test
  for (size_t i = 0; i < NUM_RGB_COLORS; i++){
    pixels.clear();
    pixels.setPixelColor(0, pixels.Color(rgb_colors[i][0], rgb_colors[i][1], rgb_colors[i][2]));
    pixels.show();
    delay(DELAY_TIME);
  }
  pixels.clear();
  pixels.setPixelColor(0, pixels.Color(0,0,0));
  pixels.show();
}

Links:

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.