Created Mon, 07 Nov 2011 10:41:18 +0000 by picluigi
Mon, 07 Nov 2011 10:41:18 +0000
Hi. I am using chipKit 32MAX with Mpide 20110822. This sketch does not work.
This example code is in the public domain.
*/
#include <SD.h>
File myFile;
void setup()
{
Serial.begin(19200);
Serial.print("Initializing SD card...");
// On the Ethernet Shield, CS is pin 4. It's set as an output by default.
// Note that even if it's not used as the CS pin, the hardware SS pin
// (10 on most Arduino boards, 53 on the Mega) must be left as an output
// or the SD library functions will not work.
pinMode(53, OUTPUT);
if (!SD.begin(53)) {
Serial.println("initialization failed!");
return;
}
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("datalog.txt", FILE_WRITE);
// if the file opened okay, write to it:
if (myFile) {
Serial.print("Writing to datalog.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 datalog.txt");
}
// re-open the file for reading:
myFile = SD.open("datalog.txt");
if (myFile) {
Serial.println("datalog.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 datalog.txt");
}
}
void loop()
{
// nothing happens after setup
}
When it comes to line n. 48 crashes: myFile.println ("testing 1, 2, 3."); In SD-Card does not write "testing 1,2,3,." I do not understand why. Can anyone help me? Thank you
Mon, 07 Nov 2011 13:47:16 +0000
Hi there,
Please see the other thread about SD cards (four pages etc). There seem to be a bug in the SD-card library.