Problems with SD card reader

Hi, so I have recently purchased this, however, I can’t seem to get the card to ever be read. I have tried 4 SD cards, 3 of which are new, and one that is quite old. I have triple checked the wiring, and reformatted the SD cards multiple times over. I have double checked the wiring, and tried 2 different boards (same boards, ESP32 Xiao S3)

Here is the code I used:

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

File myFile;

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


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

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

  if (SD.exists("example.txt")) {
    Serial.println("example.txt exists.");
  } else {
    Serial.println("example.txt doesn't exist.");
  }

  // open a new file and immediately close it:
  Serial.println("Creating example.txt...");
  myFile = SD.open("example.txt", FILE_WRITE);
  myFile.close();

  // Check to see if the file exists:
  if (SD.exists("example.txt")) {
    Serial.println("example.txt exists.");
  } else {
    Serial.println("example.txt doesn't exist.");
  }

  // delete the file:
  Serial.println("Removing example.txt...");
  SD.remove("example.txt");

  if (SD.exists("example.txt")) {
    Serial.println("example.txt exists.");
  } else {
    Serial.println("example.txt doesn't exist.");
  }
}

void loop() {
  // nothing happens after setup finishes.
}

And this is the error I get on all of the SD cards I have:

[   124][W][sd_diskio.cpp:174] sdCommand(): no token received
[   225][W][sd_diskio.cpp:174] sdCommand(): no token received
[   325][W][sd_diskio.cpp:174] sdCommand(): no token received
[   425][E][sd_diskio.cpp:199] sdCommand(): Card Failed! cmd: 0x00
[   425][W][sd_diskio.cpp:516] ff_sd_initialize(): GO_IDLE_STATE failed
[   426][E][sd_diskio.cpp:805] sdcard_mount(): f_mount failed: (3) The physical drive cannot work
[   435][W][sd_diskio.cpp:174] sdCommand(): no token received
[   540][W][sd_diskio.cpp:174] sdCommand(): no token received
[   641][W][sd_diskio.cpp:174] sdCommand(): no token received
[   742][E][sd_diskio.cpp:199] sdCommand(): Card Failed! cmd: 0x00
Card Mount Failed

If more information is required, please let me know. Thanks in advance!

3 Likes

What you are doing should work as best I can tell from the code and comparing it with my own Arduino SD card datalogger project.
The SD library reference says the following.

The library supports FAT16 and FAT32 file systems on standard SD cards and SDHC cards.

Maybe check the SD card format.

Cheers
Jim

3 Likes

Sorry, must not have mentioned, its formatted to Fat32, on a windows platform. All of the sd cards are.

Update: Just did a long format on an sd card, and that didn’t work either.

2 Likes

When I was using a similar card, I remember having trouble getting the standard SD library to work.
I checked my code for a couple of old projects and I used the SDFAT library by Bill Greiman.
The Arduino micro was a ATMega328P chip at 16MHz. Haven’t used SD cards on any other Arduino boards or clock speed.

You could try the library, maybe it will work.
Regards
Jim

EDIT: Bill has changed the library from the one I originally used. I also remember the original clashed with the SD library and I had to put the library code in the same folder as the program code for the IDE to use and find it correctly. If I remember right it took me a while to eventually get it working.

3 Likes

I have now since tried that same library as well, and got no results back from it. Seems that the same issue is happening with both libraries, and two boards. The only thing I can think now is that the SD reader, is simply not compatible with the Xiao.

1 Like

I have a question. Is SD cards the only “easy” method of having data easily converted between a computer, and a microcontroller? I know USB can’t work, but is there any relatively basic storage devices like that? It needs to store text documents and json files (preferably able to be put in folders.)

2 Likes

Flash

What about some flash memory like this? :slight_smile:

EEPROM

Another option would be an EEPROM. Something like the Atmel 28c. I’m not sure Core sell this. Maybe someone from the core team will be able to help source something similar in there inventory.
http://cva.stanford.edu/classes/cs99s/datasheets/at28c16.pdf

SD Cards :frowning:

I chose not to comment on this thread until now because I’ve never tried using SD cards with micro controllers and I didn’t want to mislead with guesses.
However, you did peek my curiosity when you first posted this over the weekend and I did find this helpful thread which is marked resolved on github. Maybe it will help you.

2 Likes

Hi Maddie,

Sorry to hear you are having trouble with the modules.
I’ve been using them quite a bit on the Pico and have mis-wired them quite a few times.They are basically direct connections to the SD cards themselves.
Would it be possible to send through a photo of your wiring quickly to verify the connections?
(I’ve shot a message through to the support team to take a look into the details of this one as well!)

Thanks heaps for jumping in and helping Jim!

Great suggestion Pix, I’ve added it to the list of bits to source - we might even be able to assemble a breakout inhouse!

Liam

2 Likes

I’d buy it! :heavy_heart_exclamation:

1 Like

Yes, I sure can!

Wiring with boards (matching miso and mosi)

Wiring with boards (alternating miso and mosi)

Wiring without boards (matching miso and mosi)

I have a few other photos, but hopefully that helps with the most of it.

I do have one exactly like this from Adafruit. I love it, however, it would almost be the same as using the library Preferences. I want to be able to use the SD card for a few different things, like the following, which require me to be able to view the data straight away. (I would run a webserver, however, running Bluetooth and wifi at the same time, causes it to heat up to an ungodly temperature, and also seems to cause an insane amount of lag.)

  • Logs: when issues arise, it can log the errors (or crashes) into a folder/file on the SD card, and if the same crash happens more than once, it will just stop doing it, and stay off, until the issue is either ignored (there will be a setting to do this) or can be fixed.
  • Setups, so default settings can be changed, without reprogramming the whole board, I can just simply change the file, and reboot the ESP32.
  • OTA Updating: The ability for me to update all the esp32’s that are connected via the internet by just storing a new file, and changing the version in the setup files
2 Likes

SPI interface MOSI is like TX data (output) and MISO is like RX data (input).
ESP32 MOSI goes to SD card MISO
ESP32 MISO goes to SD card MOSI
ESP32 CLK goes to SD card CLK

The Arduino SPI clock is divided from the system clock. On a 16MHz UNO this becomes 4MHz.
Unsure what the Arduino IDE would set for a ESP32.

There is SPI information in the Arduino reference web pages for changing clock speed.
I still feel the problem could be the clock speed if you have the wiring correct.

If possible, suggest you try to confirm the SD reader/writer device actually works with another Microcontroller.
You try it with a Pico. Core Electronics guide to using Makerverse SD reader/writer which is very similar to the one you have.

Hope you can get it to work.
Regards
Jim

2 Likes

Frankly I would love to test on one of my Pico’s, in micropython, but I physically cannot do it. Thonny doesn’t allow me to save to the connected pico, and only ever worked the first time I plugged them in. I know the pico’s work, because Arduino sees, and allows code to run on them, but Thonny is just broken, and I honestly think its garbage. I have even found more success using a plugin for vsc, but it didn’t support BLE, which made me switch to a whole other device, hence, the esp32’s

1 Like

This sounds super annoying! If you are looking for an alternative, PyCharm also supports MicroPython.

Have you tried reflashing the latest micropython .uf2 file?

What does your Interpreter tab in Options look like?

Do you get COM port errors?
image

no issues with com ports or anything. It’s just thonny stating that it failed to save the data to the device, and a hard reset should fix the issue. The logs show the same thing, and provide no further information.

Is this the type of message you are getting ??
PROBLEM IN THONNY’S BACK-END: Internal error (serial.serialutil.SerialException: WriteFile failed (PermissionError(13, ‘The device does not recognize the command.’, None, 22))).
See Thonny’s backend.log for more info.
You may need to press “Stop/Restart” or hard-reset your MicroPython device and try again.

Process ended with exit code 0.

I have not experienced this particular error. but other types. In every case reloading micropython on the Pico fixed the problem. Also sometimes the COM port starts to play up; removing the Pico, then rebooting the PC usually fixes it.

Development environment Thonny 4.0.0, Windows 10 (64bit), Python 3.10.6.
Recommend installing micropython using Thonny, it can be a little slow but it will load the latest version of mircopython. Thonny is an excellent development environment for the Pico.

If you want to manually load micropython you can get it from Micropython - Python for the Pico web page.

Regards
Jim

3 Likes

Sorry for such a delayed response, I have such moved on from this project, and to another one, that yes, needs an SD card again. I am running into the exact same issues as before, following the same wiring I did before, and everything.

The only thing I physically cannot do is testing on the raspberry PI Pico’s I have, as thonny is not playing ball, and neither is the arduino IDE.

However. I have managed to get a basic arduino uno to read fine from the SD card, with absolutely no issues, which means both the SD card, and the reader are perfectly fine.

This means something on the XIAO side of things is the issue. Going back to what was previously said about being speeds? What things can I try to change to possibly get it to work?


Here is an image of my current settings for the board. I would like to say that the main thing I have changed/tried was simply just the CPU frequency (from 240mhz down to 20mhz).

Nothing seems to show any result.

Hi Maddie.

Try running at 4mhz.

Just an experiment.
It’s so cool that we can buy micro controllers these days, like the xiao, running 240mhz.
SD card mounts have a lot of pings with slow reply’s and I’d like to see what bringing the clock down “slow” will do.

Pix :heavy_heart_exclamation:

Hi Pix!

I tried the lowest setting in the Arduino IDE (10mhz) and it still does not work sadly.

1 Like

10mhz should be slow enough for modern sd card readers.
Is there link to the code you are using? Maybe a second pair of eyes will spot something to google?