Code is SD example code.
My connections are
Ground to Ground
VCC -> 5V
MISO -> 12
MOSI -> 11
SCK -> 13
CS -> 10
An SD card runs off 3V3 not 5V.
What processor are you using? Can you post a link to your schematic and link to your code.
You might want to look at this How to get the best out of this forum before you proceed any further.
@PaulCr125 Hello there, can you explain a little bit more about wiring or which sd adapter you are using, the microcontroller used, is this ArduinoUno, mini, ESP8266MOD, ESP32.... Also the code used will be fine.
With kind regards.
@Grumpy_Mike An SD card runs off 3V3 not 5V.
https://randomnerdtutorials.com/guide-to-sd-card-module-with-arduino/
I also use 5V on my sd cards, depending on which adapter you´re using and which microcontroller.
more accurately:
the SD CARD runs on 3.3 VDC
the SD card MODULE may run on 3.3 or 5 VDC. Voltage reduction, and providing a socket, are the primary function of the module.
CS = 10: 10 is the CS pin used when the board is receiving data over SPI. everyone uses it for outgoing data, and it works fine, but you can use any digital pin for CS output.
my SD card started working when I changed from
int CS = 10
to
const int CS = 10
Seeing that this is posted in Arduino WiFi Rev2, the SPI pins are not 11/12/13. The SPI pins are only available on the 6-pin header !!
While many modules include a voltage regulator to reduce the voltage to 3V3, few include level shifters to reduce the 5V signals from a 5V processor to 3V3, nor boost the 3V3 signals from the SD card to the 5V signal required .
Please answer the questions asked of you in my first post.
I am sure it will be but can we see it, to make sure.
sterretje.... This must be it..... but those pins are not marked. Which is which?
Third page of https://docs.arduino.cc/static/d37f6b33c17c09612ff4ac7ce94fa68f/ABX00021-full-pinout.pdf
Please note that MISO is called CIPO and MOSI is called COPI.
I so appreciate your help. I am an "old" programmer just getting into tinkering. My SD module has a CS , SCK, MOSI (COPI), MISO (CIPO),VCC, GRND pins.
Does my CS go to Digital 10 on my Arduino UNO WIFI Rev 2?
Again thanks for your help.
You can use any available pin; just make sure that you match the code to it.
sterretje.. I'm going to walk away for a while, I can't thank you enough for being patient and also very helpful. My head is spinning....
Where I am now is leaving CS not connected to anything, see serial monitor output below. it's hit and miss as to if it reads the card or not. I have tried different sd cards, and I'm formatting them via the "SD Card Formatter" recommended in other posts. I'm closer than I was before but something is not right. I can't imagine the board is bad but I'll try anything at this point. Thanks again...
Take your time.
That's wrong. The input on the card module is more than likely floating which can result in what you're observing.
Here's a code to test the SD card:
// Arduino Uno
/* Wiring µSDCard ARDUINO UNO
* CS 4
* SCK SCK (ICSP)
* MOSI MOSI(ICSP)
* MISO MISO(ICSP)
* VCC 5V
* GND GND
*/
#include <Arduino.h>
#include <SD.h>
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
delay(2000);
Serial.println(F("Initialize system"));
Serial.print("\nInitializing sd card...");
// we'll use the initialization code from the the utility libraries since we're just testing if the card is working
if (!SD.begin(4)) {
Serial.println("Initialization failed. Things to check:");
Serial.println("Is a card inserted?");
Serial.println("Is your wiring correct?");
Serial.println("Did you change the ChipSelect pin to match your shield or module?");
while (1)
;
} else {
Serial.println("Wiring is correct and a card is present");
}
}
void loop() {
// put your main code here, to run repeatedly:
}
I hope to help other people with the same problem on the Arduino UNO with this test code .
Im usind the esp 32 and get the intialization failed message. I have connected it like shown in this website MicroSD Card Module with ESP32 using Arduino IDE, and I use the standart code for the sd card read write
/*
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 <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(4)) {
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:
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
}
@iviyan Hi there, sorry for the late respons, but I´m just back from holidays. What version are you using of the esp32? I use the development kit v3. Like this:
https://www.az-delivery.de/nl/products/esp32-dev-kit-c-unverlotet?_pos=9&_sid=644608f39&_ss=r If you are using ESP32 like me, you have to connect the sd card on other pins, CS to pin 4 is for Arduino UNO. Try following:
CS: GPIO2, SCK: GPIO18, MOSI: GPIO23, MISO: GPIO19, VCC:5V, GND: GND.
With kind regards, Rudy.
@dingsken thanks for the help though Im using the NODE MCU esp32s. I ended up using these pins GND - GND, VCC - 5v, MISO - pin19, MOSI - pin23, CS - pin5, SCK - pin18 with the mySD library.
btw sorry it took me so long I rearly visit this forum
No problem, I´m glad you´ll get it working. It´s always a little surching which pins to use on different versions and very important to know and reading the data-sheet before starting.
I wish you success and a lot of fun with programming and using the microcontroller.
With kind regards, Rudy.
2 posts were split to a new topic: Giga R1: Initializing SD card...initialization failed
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.