Hi all
Sorry for my first post being a question.
I am doing quite well writing sketches for the Arduino and have built a number of projects. I am really suffering with this one though.
I have an Arduino Mega 2560 with a Mega compatable Ethernet shield connected.
I have a microSD card that has four files on it :-
index.htm
segment.js
favicon.ico
water.jpg
These are used to serve a webpage from the Arduino when a client first connects. The page is then updated every second with an XML burst from the Arduino.
Now all this works fine except the SD card drives me mad.
If I startup the unit from cold the SD card is recognised but I cant see the files
If I reset the Arduino or the Ethernet card with their buttons, the SD is recognised but I cant see the files.
If I remove and re-insert the SDcard with the Arduino and Ethernet shield powered up, then press the reset button I can see all the files on the card and everything is lovely.
BUT, if I now reset either the Arduino or the Ethernet shield, I can no longer access the files till I remove and re-insert the card, then reset again.
This is driving me nuts.
I have tried using the standard Arduino SD library, with SDbegin(4) to start the SD library and SD.exists(filename) to check if the files are there
I then tried using SdFat (which I find harder to understand) and get the same problem
So I have now created a tiny sketch that just takes the SD setup and file checks routines which still suffers exactly the same way. Code attached below.
#include <SPI.h>
#include <Ethernet.h>
#include <SdFat.h>
SdFat sd;
SdFat file;
void setup() {
// disable Ethernet chip
pinMode(10,OUTPUT);
digitalWrite(10,HIGH),
Serial.begin(9600); // for debugging
//check for the SD card and all the files. If they are not present then exit.
//try to initialise the card
if (!sd.begin(4)) {
Serial.println("ERROR - SD card initialization failed!");
}
else Serial.println("SUCCESS - SD card initialized.");
//check for index.htm file
if (!sd.exists("index.htm")) {
Serial.println("ERROR - Can't find index.htm file!");
}
else Serial.println("index.htm found");
if (!sd.exists("favicon.ico")) {
Serial.println("ERROR - Can't find favicon.ico file!");
}
else Serial.println("favicon.ico found");
if (!sd.exists("segment.js")) {
Serial.println("ERROR - Can't find segment.js file!");
}
else Serial.println("segment.js found");
if (!sd.exists("water.jpg")) {
Serial.println("ERROR - Can't find background.png file!");
}
else Serial.println("favicon.ico found");
}
void loop(){
}
When I reset the cards with the SD inserted I get this output on the serial monitor
SUCCESS - SD card initialized.
ERROR - Can't find index.htm file!
ERROR - Can't find favicon.ico file!
ERROR - Can't find segment.js file!
ERROR - Can't find background.png file!
no matter how many times I reset I get the same.
BUT, remove and re-insert the SD card and then reset the Arduino and I get this...
SUCCESS - SD card initialized.
index.htm found
favicon.ico found
segment.js found
favicon.ico found
but the very next reset without removing and inserting the card goes back to the errors again.
Please could anybody give me some advice on how I can get the card and all it's files recognised on every reset?
Many many thanks in advance
Julian