void error_P(const char* str) { PgmPrint("error: "); SerialPrintln_P(str); if (card.errorCode) { PgmPrint("SD error: "); Serial.print(card.errorCode, HEX); } }
/* * print error message and halt if SD I/O error, great for debugging! */ void sdErrorCheck(void) { if (!card.errorCode()) return; PgmPrint("\r\nSD I/O error: "); Serial.print(card.errorCode(), HEX); PgmPrint(", "); Serial.println(card.errorData(), HEX); while(1); }
void error_P(const char* str) { PgmPrint("error: "); SerialPrintln_P(str); if (card.errorCode()) { PgmPrint("SD error: "); Serial.print(card.errorCode(), HEX); Serial.print(','); Serial.println(card.errorData(), HEX); } while(1); }
void setup() { //Serial.begin(9600); PgmPrint("Free RAM: "); //Serial.println(FreeRam()); // initialize the SD card at SPI_HALF_SPEED to avoid bus errors with // breadboards. use SPI_FULL_SPEED for better performance. pinMode(10, OUTPUT); // set the SS pin as an output (necessary!) digitalWrite(10, HIGH); // but turn off the W5100 chip! if (!card.init(SPI_HALF_SPEED, 4)) error("card.init failed!"); // initialize a FAT volume if (!volume.init(&card)) error("vol.init failed!"); PgmPrint("Volume is FAT"); //Serial.println(volume.fatType(),DEC); //Serial.println(); if (!root.openRoot(&volume)) error("openRoot failed"); // list file in root with date and size PgmPrintln("Files found in root:"); root.ls(LS_DATE | LS_SIZE); //Serial.println(); // Recursive list of all directories PgmPrintln("Files found in all dirs:"); root.ls(LS_R); //Serial.println(); PgmPrintln("Done"); // Debugging complete, we start the server! Ethernet.begin(mac, ip); server.begin(); // Start up the temperature library sensorsa.begin(); sensorsb.begin(); sensorsc.begin(); sensorsd.begin(); setTime(0); // start the clock time33mins = time60mins = now(); }
/* * print error message and halt */ void error_P(const char *str) { PgmPrint("Error: "); SerialPrint_P(str); sdErrorCheck(); while(1); }
/* * print error message and halt */ void Jukebox2::error_P(const char *str) { PgmPrint("Error: "); SerialPrint_P(str); sdErrorCheck(); //while(1); }
/* * remove all files in dir. */ void deleteFiles(SdFile &dir) { char name[13]; SdFile file; // open and delete files for (uint16_t n = 0; ; n++){ sprintf(name, "%u.TXT", n); // open start time uint32_t t0 = millis(); // assume done if open fails if (!file.open(&dir, name, O_WRITE)) return; // open end time and remove start time uint32_t t1 = millis(); if (!file.remove()) error("file.remove failed"); // remove end time uint32_t t2 = millis(); PgmPrint("RM "); Serial.print(n); Serial.print(' '); // open time Serial.print(t1 - t0); Serial.print(' '); // remove time Serial.println(t2 - t1); } }
void setup() { Serial.begin(9600); pinMode(greenLEDandBEEP, OUTPUT); pinMode(redLEDpin, OUTPUT); PgmPrint("Free RAM: "); Serial.println(FreeRam()); pinMode(10, OUTPUT); digitalWrite(10, HIGH); if (!card.init(SPI_HALF_SPEED, 4)) error("card.init failed!"); if (!volume.init(&card)) error("vol.init failed!"); PgmPrint("Volume is FAT"); Serial.println(volume.fatType(),DEC); Serial.println(); if (!root.openRoot(&volume)) error("openRoot failed"); PgmPrintln("Files found in root:"); root.ls(LS_DATE | LS_SIZE); Serial.println(); PgmPrintln("Files found in all dirs:"); root.ls(LS_R); Serial.println(); PgmPrintln("Done"); Ethernet.begin(mac, ip); server.begin(); }
void setup(void) { Serial.begin(BPS_115200); Serial.println(); PgmPrintln("Type any character to start"); while (!Serial.available()); //PgmPrint("FreeRam: "); //Serial.println(FreeRam()); // initialize the SD card at SPI_HALF_SPEED to avoid bus errors with // breadboards. use SPI_FULL_SPEED for better performance. if (!card.init(SPI_HALF_SPEED)) error("card.init failed"); // initialize a FAT volume if (!volume.init(&card)) error("volume.init failed"); // open the root directory if (!root.openRoot(&volume)) error("openRoot failed"); strcpy_P(buf, PSTR("APPEND.TXT")); // open for read if (!from.open(&root, buf, O_READ)) { PgmPrint("Can't open "); Serial.println(buf); PgmPrintln("Run the append example to create the file."); error("from.open failed"); } strcpy_P(buf, PSTR("ACOPY.TXT")); // create if needed, truncate to zero length, open for write if (!copy.open(&root, buf, O_CREAT | O_TRUNC | O_WRITE)) { error("copy.open failed"); } // count for printing periods uint16_t p = 0; int16_t n; while ((n = from.read(buf, sizeof(buf))) > 0) { if (copy.write(buf, n) != n) error("write failed"); // print progress periods if (!(p++ % 25)) Serial.print('.'); if (!(p % 500)) Serial.println(); } Serial.println(); if (n != 0) error ("read"); // force write of directory entry and last data if (!copy.close()) error("copy.close failed"); PgmPrintln("Copy done."); }
/* * Open and start playing a WAV file */ void playfile(char *name) { if (wave.isplaying) {// already playing something, so stop it! wave.stop(); // stop it } if (!file.open(root, name)) { PgmPrint("Couldn't open file "); Serial.print(name); return; } if (!wave.create(file)) { PgmPrintln("Not a valid WAV"); return; } // ok time to play! wave.play(); }
/* * create enough files to force a cluster to be allocated to dir. */ void dirAllocTest(SdFile &dir) { char buf[13], name[13]; SdFile file; uint16_t n; uint32_t size = dir.fileSize(); // create files and write name to file for (n = 0; ; n++){ // make file name sprintf(name, "%u.TXT", n); // open start time uint32_t t0 = millis(); if (!file.open(&dir, name, O_WRITE | O_CREAT | O_EXCL)) { error("open for write failed"); } // open end time and write start time uint32_t t1 = millis(); // write file name to file file.print(name); if (!file.close()) error("close write"); // write end time uint32_t t2 = millis(); PgmPrint("WR "); Serial.print(n); Serial.print(' '); // print time to create file Serial.print(t1 - t0); Serial.print(' '); // print time to write file Serial.println(t2 - t1); // directory size will change when a cluster is added if (dir.fileSize() != size) break; } // read files and check content for (uint16_t i = 0; i <= n; i++) { sprintf(name, "%u.TXT", i); // open start time uint32_t t0 = millis(); if (!file.open(&dir, name, O_READ)) { error("open for read failed"); } // open end time and read start time uint32_t t1 = millis(); int16_t nr = file.read(buf, 13); if (nr < 5) error("file.read failed"); // read end time uint32_t t2 = millis(); // check file content if (strlen(name) != (uint16_t)nr || strncmp(name, buf, nr)) { error("content compare failed"); } if (!file.close()) error("close read failed"); PgmPrint("RD "); Serial.print(i); Serial.print(' '); // print open time Serial.print(t1 - t0); Serial.print(' '); // print read time Serial.println(t2 - t1); } }
void setup() { Serial.begin(BPS_115200); PgmPrintln("Type any character to start"); while (!Serial.available()); // PgmPrint("Free RAM: "); /// Serial.println(FreeRam()); // initialize the SD card at SPI_FULL_SPEED for best performance. // try SPI_HALF_SPEED if bus errors occur. if (!card.init(SPI_FULL_SPEED)) error("card.init failed"); // initialize a FAT volume if (!volume.init(&card)) error("volume.init failed!"); PgmPrint("Type is FAT"); Serial.println(volume.fatType(), DEC); if (!root.openRoot(&volume)) error("openRoot failed"); // open or create file - truncate existing file. if (!file.open(&root, "BENCH.DAT", O_CREAT | O_TRUNC | O_RDWR)) { error("open failed"); } // fill buf with known data for (uint16_t i = 0; i < (BUF_SIZE-2); i++) { buf[i] = 'A' + (i % 26); } buf[BUF_SIZE-2] = '\r'; buf[BUF_SIZE-1] = '\n'; PgmPrint("File size "); Serial.print(FILE_SIZE_MB); PgmPrintln(" MB"); PgmPrintln("Starting write test. Please wait up to a minute"); // do write test uint32_t n = FILE_SIZE/sizeof(buf); uint32_t t = millis(); for (uint32_t i = 0; i < n; i++) { if (file.write(buf, sizeof(buf)) != sizeof(buf)) { error("write failed"); } } t = millis() - t; file.sync(); double r = (double)file.fileSize()/t; PgmPrint("Write "); Serial.print(r); PgmPrintln(" KB/sec"); Serial.println(); PgmPrintln("Starting read test. Please wait up to a minute"); // do read test file.rewind(); t = millis(); for (uint32_t i = 0; i < n; i++) { if (file.read(buf, sizeof(buf)) != sizeof(buf)) { error("read failed"); } } t = millis() - t; r = (double)file.fileSize()/t; PgmPrint("Read "); Serial.print(r); PgmPrintln(" KB/sec"); PgmPrintln("Done"); }
/** %Print msg, any SD error code. * * \param[in] msg Message to print. */ void SdFat::errorPrint(char const* msg) { PgmPrint("error: "); Serial.println(msg); errorPrint(); }
/** %Print any SD error code. */ void SdFat::errorPrint() { if (!card_.errorCode()) return; PgmPrint("SD errorCode: "); Serial.print(card_.errorCode(), HEX); Serial.println(); }
/** %Print msg, any SD error code. * * \param[in] msg Message in program space (flash memory) to print. */ void SdFat::errorPrint_P(PGM_P msg) { PgmPrint("error: "); SerialPrintln_P(msg); errorPrint(); }