I have an UNO, and built an SD card reader board, and have a program to read a file.
It all works.
Enter Mega, and begin mega-headache.
I used the exact same SD board I made, and slightly modified the program to accommodate the Mega.
I documented what I did in the program.
I move the wires from my homemade board straight over to the mega according to the pin in the program below, pins coming from documentation at Arduino.cc
I changed only one line of code, documented below, which is change 10 to 53 for the CS.
And.... no good.
The output says:
Initializing SD cart I'm at ONE.
Initialization failed! I'm at TWO
that's all.
(Yes I know there is a typo on cart should be card....)
I've spent the entire morning chasing this around, and don't even know what to try next.
Thanks in advance for any help.
#include <SPI.h>
#include <SD.h>
File myFile;
//this is for Arduino MEGA MEGA MEGA
/*
changes from Uno version:
UNO MEGA
pin 13, clk, now goes to 52
pin 12, MISI, now goes to 51
pin 11, MOSI, now goes to 50
pin 10, CS, now goes to 53
also, below, if (!SD.begin(10)) { now has (53). I think that can be () as default
and.... it doesn't work
*/
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.println("Initializing SD cart I'm at ONE.");
delay(100);
if (!SD.begin(53)) {
Serial.println("initialization failed! I'm at TWO");
while (1)
;
}
Serial.println("initialization done.");
// open the file for reading:
myFile = SD.open("pinList.txt");
if (myFile) {
Serial.println("pinList.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 test1.txt");
}
}
void loop() {
// nothing happens after setup
}