Jack
25 July 2024 04:30
21
Hi Maddie,
I’ve recently implemented a XIAO ESP32-C3 into a datalogger and it took ages for me to set up the SD reader.
Fortunately, I have code that works for me.
#include <Arduino.h>
#include <FS.h>
#include <SD.h>
#include <SPI.h>
// Check Pinout for S3 board
#define MOSI D9
#define MISO D10
#define CLK D8
#define CS D7
File datafile; // sets a data file
String filename = text.txt
void setup() {
Serial.begin(115200);
SPI.being(CLK, MISO, MOSI, CS);
if (!SD.begin(CS)) {
Serial.println('No reader detected');
}
datafile = SD.open( (filename) .c_str(), FILE_WRITE); // Initialises datafile object
if (!datafile) {
Serial.println('File not found');
}
}
Filename could be anything. Hopefully this works it is very much chopped up and put together. My error checking is also quite different so hopefully while splicing this together that works.
For my actual project, I have another pair of functions that are a bit more universal for all my projects. I can post these later if you would like. I just input what I want my file to be named and the file type and on each boot of my datalogger it will create a new file with a number on the end. Let’s get something working first.
1 Like
Okay, I have just tried @Jack ’s suggestion (modifying the code slightly btw)
#include <Arduino.h>
#include <FS.h>
#include <SD.h>
#include <SPI.h>
// Check Pinout for S3 board
#define MOSI D9
#define MISO D10
#define CLK D8
#define CS D7
File datafile; // sets a data file
String filename = "test.txt";
void setup() {
Serial.begin(115200);
SPI.begin(CLK, MISO, MOSI, CS);
if (!SD.begin(CS)) {
Serial.println("No reader detected");
}
datafile = SD.open( (filename) .c_str(), FILE_READ); // Initialises datafile object
if (!datafile) {
Serial.println("File not found");
} else {
Serial.println(datafile.readString().c_str());
}
}
void loop() {}
With that said, still the same issue, It cannot find the sd/reader.
EDIT:
I would like to mention, I have bought a few new items from CE, specifically a new SD card reader for the XIAO boards (link )
and I will be trying that later today to see if it also has issues.
2 Likes
Here is something interesting.
I’ve noticed this line on Arduino’s page for the sd library
the hardware SS pin must be kept as an output or the SD library functions will not work .
So then I wondered what the Slave Select Pin on the Seed studio was supposed to be.
I found this README that specifically mentions problems with the default SPI pinouts.
# SeeeduinoXIAO_SPISlave
This repository provides a working Arduino SPI Slave example for the Seeeduino XIAO board. http://wiki.seeedstudio.com/Seeeduino-XIAO/) (ATSAMD21G18A).
Thanks goes out to:
- jeremyherbert - https://github.com/jeremyherbert/playful-turtle-xiao
- The atmel SAMD21 library
- everyone at https://forum.arduino.cc/index.php?topic=360026.0
**Important notes:**
- The seeeduino xiao supports 0V to 3.3V digital signals. Connecting signals outside this range will likely cause permanent damage to the device.
- We are NOT using the default SPI pins per the Seeeduino documentation - we are reassigning these pins to SERCOM0.
- MOSI and MISO should be connected direct to the SPI master device - do not reverse/swap them.
- If you are only receiving/listening, then you can leave pin MISO pin 4 disconnected.
- You can use Serial for USB and Serial1 for UART TX/RX
**Connection information:**
WARNING: Do not use the pinout information provided by seeedstudio.
This file has been truncated. show original
I think based on what I’m reading, you can still use D7 as the CS pin.
The arduino page suggests you just need to add pinMode(D5, OUTPUT);
2 Likes
After trying this as well, I still get the same result.
I have however, received a new item, 2.0 320x240 IPS TFT LCD Display with MicroSD Card Breakout | DFRobot DFR0664 | Core Electronics Australia , which works perfectly fine with the controls, however, the SD reader included, cannot pick up any images on the board.
I also have this new board: Adafruit Audio BFF Add-on for QT Py and Xiao | ADA5769 | Core Electronics Australia to try and drive audio/test SD cards, and I also can’t get it to work at all with an SD card. (or the I2S portion either haha)
Jack
26 July 2024 01:16
25
Hi Maddie,
Can you share how you have these wired. If you are using the XIAO’s one give some of the example code a go. The examples were great for troubleshooting I found.
1 Like
I own these
They were great.
1 Like
MPlaty
10 December 2024 12:29
27
Its been a while, and since I have bought a few new things. So it turns out, my three original SD cards I tested with, did not work! I finally bought a 4GB card from here, and it worked fine. I then went out and bought a 16GB card which also worked fine (both not SanDisk branded!) 16GB is fine for my purposes now, but I will look into buying some more cards from random places with different specs to find stuff out, but hey, now I have almost 10 different SD card readers for all my projects! haha. Thank you all for your help. I should have thought there was an issue after trying a lot of different SD card readers.
3 Likes
Dan
10 December 2024 23:24
28
Hi Maddie,
Great to hear that you got to the bottom of it! Having a known good and a known good backup is always a good idea when it comes to electronics.
2 Likes