Micro SD card works in arduino ide but not in platformio

So I recently created a custom board based around the samd21e18 and it works great! I got the project intergrated in platformio and so far everything works except for the microsd card reader. Basically, I tested the microsd card out a few times in arduino ide using the Rapid Prototypes arduino Tau board and it worked. However, using the exact same variant.cpp and variant.h files in platformio, the microsd card reader does not work.

here is the code I have been using accross arduino ide and pio:

  SD card read/write

  This example shows how to read and write data to and from an SD card file
  The circuit:
   SD card attached to SPI bus as follows:
 ** MOSI - pin 11
 ** MISO - pin 12
 ** CLK - pin 13
 ** CS - pin 4 (for MKRZero SD: SDCARD_SS_PIN)

  created   Nov 2010
  by David A. Mellis
  modified 9 Apr 2012
  by Tom Igoe

  This example code is in the public domain.


#include <Arduino.h>
#include <SPI.h>
#include <SD.h>

File myFile;

void setup() {
  // Open serial communications and wait for port to open:
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only

  Serial.print("Initializing SD card...");

  if (!SD.begin(10)) {
    Serial.println("initialization failed!");
    while (1);
  Serial.println("initialization done.");

  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  myFile = SD.open("test.txt", FILE_WRITE);

  // if the file opened okay, write to it:
  if (myFile) {
    Serial.print("Writing to test.txt...");
    myFile.println("testing 1, 2, 3.");
    // close the file:
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");

  // re-open the file for reading:
  myFile = SD.open("test.txt");
  if (myFile) {

    // read from the file until there's nothing else in it:
    while (myFile.available()) {
    // close the file:
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");

void loop() {
  // nothing happens after setup

Its possible that the variant.cpp or variant.h files are causing trouble. I have used the adafruit trinket m0 as the board in pio and then added the variant.cpp and variant.h files directly into the src folder. That is the only change I made and It works because I tested it with a neoPixle LED and it was able to use the LED_BUILTIN that i defined in the new variant files and didnt work if I made changes to those files. The hope was that the variant.cpp and variant.h files would automatically overide the default ones for the trinket m0. Any thoughts as to what might be happening?

So another issue popped up. For some strange reason, a simple sketch for the BMI088 wont print anything while the same exact code works totally fine in arduino IDE. These may be related? Honestly im out here pulling my hair. I can’t really find anyone else who has had this issue and im getting close to giving up :confused:

So you’re trying to get a custom Arduino core and variant supported? What are the exact project files? One missing build flag or wrong configuration and it could be dead in the water.

Hey! So I actually got most of the things working since I later realized that the Sparkfun Samd21 Mini board actually uses the same pins for i2c and spi even though it uses the samd21g18 and not the e18. Previously, I had selected the adafruit trinket m0 board and just included the variant.cpp and variant.h files in the src and thats it. That approach kinda worked for things like setting digital outputs but never really worked with things like spi. The sparkfun board however is not a 100% match to my pinout and I am wondering if I could use the same approach to include the variant.cpp and variant.h files because I need to change a single pin (named AREF) to an analog input.

If you have a custom variant you should use the options to control the variant directory and name of the board variant, as well as any identifiyng macros. Basically, a new board JSON should be created. It’s basically the same concept as in https://github.com/maxgerhardt/pio-custom-stm32duino-variants.

Thanks so much! I got every part of my board to work and basically I only had to change one pin in the new variant.cpp file.