So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By FrankB
#72026 Hi.
I just received a couple of wemos D1 mini compatible SD-card shields.
As a first test I was trying to run a couple of demo programs. see below.

The issue is, that the code compiles fine and uploads to the wemos D1, however only if the SD-shield is not connected.
If I install the shield, a connection to the wemos can't be established.

Any thoughts on that would be much appreciated.
p.s. I tried it from Arduino IDE and via Platformio... same same

Code: Select all/*
 * Micro SD Shield - Read/Write
 *
 * This example shows how to read and write data
 * to and from an SD card file
 *
 * The WeMos Micro SD Shield uses:
 * D5, D6, D7, D8, 3V3 and G
 *
 * The shield uses SPI bus pins:
 * D5 = CLK
 * D6 = MISO
 * D7 = MOSI
 * D8 = CS
 *
 * The SD card library uses 8.3 format filenames
 * and is case-insensitive.
 * eg. IMAGE.JPG is the same as image.jpg
 *
 * created Nov 2010 by David A. Mellis
 * modified 9 Apr 2012 by Tom Igoe
 *
 * This example code is in the public domain.
 * https://github.com/esp8266/Arduino/blob/master/libraries/SD/examples/ReadWrite/ReadWrite.ino
 */

#include "SPI.h"
#include "SD.h"

const int chipSelect = D8;
File myFile;

void setup()
{
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect.
  }

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

  if (!SD.begin(chipSelect)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");

  /* open the file.
   * note that only one file can be open at a time
   */
  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:
    myFile.close();
    Serial.println("done.");
  } 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) {
    Serial.println("test.txt:");

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

void loop()
{
  // nothing happens after setup
}
User avatar
By jumblies
#72807 I have this exact same problem. 2 different shields, 2 different wemos modules. I'll say that neither are "authentic" but that has never prevented it from working in the past. I guess the thing to do next (for me anyway) is to test the SD card shield on a regular arduino uno and see if works. That would help tease out if it's the shield.

It's hard to imagine they messed up the SD card shield since it's only a few traces and a resistor.
User avatar
By Boopboopboopers
#94445 I suggest you both use the HSPI interface instead of the standard SPI interface. The standard SPI is used to communicate in some way when plugged into USB for programming. A quick search will yield results on how to utilize this. May not be the solution, but a suggestion none the less.