void setup() { Serial.begin(BPS_115200); PgmPrintln("Type any character to start"); while (!Serial.available()); // 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"); // open the root directory if (!root.openRoot(&volume)) error("openRoot failed"); // write files to root if FAT32 if (volume.fatType() == 32) { PgmPrintln("Writing files to root"); dirAllocTest(root); } // create sub1 and write files SdFile sub1; if (!sub1.makeDir(&root, "SUB1")) error("makdeDir SUB1 failed"); PgmPrintln("Writing files to SUB1"); dirAllocTest(sub1); // create sub2 and write files SdFile sub2; if (!sub2.makeDir(&sub1, "SUB2")) error("makeDir SUB2 failed"); PgmPrintln("Writing files to SUB2"); dirAllocTest(sub2); PgmPrintln("Done"); }
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(); }
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."); }
void setup() { // set up Serial library at 9600 bps Serial.begin(9600); if (!card.init()) { error("Card init. failed!"); } if (!vol.init(card)) { error("No partition!"); } if (!root.openRoot(vol)) { error("Couldn't open dir"); } PgmPrintln("Files found:"); root.ls(); // declare the Pins pinMode(readyLEDPin, OUTPUT); // pinMode(blowLEDPin, OUTPUT); // pinMode(waitLEDPin, OUTPUT); pinMode(level0LEDPin, OUTPUT); pinMode(level1LEDPin, OUTPUT); pinMode(level2LEDPin, OUTPUT); pinMode(level3LEDPin, OUTPUT); pinMode(buttonPin, INPUT); initialButtonState = digitalRead(buttonPin); Serial.println("initial switch value= " + initialButtonState); ///***** set the char mode based on the pot position initialPot = analogRead(PotPin); Serial.println("initial pot value= " + initialPot); range = map(initialPot, 0, 1024, 0, 3); Serial.println("initial pot range is: " + range); switch (range) { case 0: // your hand is on the sensor mode = 0; Serial.println("initial mode set to 0: princess"); break; case 1: // your hand is close to the sensor mode = 1; Serial.println("initial mode set to 1: pirate"); break; case 2: // your hand is a few inches from the sensor mode = 2; Serial.println("initial mode set to 2: halloween"); break; case 3: // your hand is nowhere near the sensor mode = 3; Serial.println("initial mode set to 3: insult"); break; } }
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(); }
/* * 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(); }
void setup() { Serial.begin(BPS_115200); PgmPrintln("Type any character to start"); while (!Serial.available()); // 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"); // open the root directory if (!root.openRoot(&volume)) error("openRoot failed"); // delete files in root if FAT32 if (volume.fatType() == 32) { PgmPrintln("Remove files in root"); deleteFiles(root); } // open SUB1 and delete files SdFile sub1; if (!sub1.open(&root, "SUB1", O_READ)) error("open SUB1 failed"); PgmPrintln("Remove files in SUB1"); deleteFiles(sub1); // open SUB2 and delete files SdFile sub2; if (!sub2.open(&sub1, "SUB2", O_READ)) error("open SUB2 failed"); PgmPrintln("Remove files in SUB2"); deleteFiles(sub2); // remove SUB2 if (!sub2.rmDir()) error("sub2.rmDir failed"); PgmPrintln("SUB2 removed"); // remove SUB1 if (!sub1.rmDir()) error("sub1.rmDir failed"); PgmPrintln("SUB1 removed"); PgmPrintln("Done"); }
/** Print error details after SdFat::init() fails. */ void SdFat::initErrorPrint() { if (card_.errorCode()) { PgmPrintln("Can't access SD card. Do not reformat."); errorPrint(); if (card_.errorCode() == SD_CARD_ERROR_CMD0) { PgmPrintln("No card or SPI problem?"); } } else if (vol_.fatType() == 0) { PgmPrintln("Invalid format, reformat SD."); } else if (vol_.fatType() == 12 && !FAT12_SUPPORT) { PgmPrintln("Card is formatted FAT12."); } else if (!cwd_.isOpen()) { PgmPrintln("Can't open root directory."); } else { PgmPrintln("No init error found."); } }
void setup() { Serial.begin(BPS_115200); PgmPrintln("Type any character to start"); while (!Serial.available()); Serial.print("\nInitializing 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(10, OUTPUT); // change this to 53 on a mega // we'll use the initialization code from the utility libraries // since we're just testing if the card is working! if (!card.init(SPI_HALF_SPEED, chipSelect)) { Serial.println("initialization failed. Things to check:"); Serial.println("* is a card is inserted?"); Serial.println("* Is your wiring correct?"); Serial.println("* did you change the chipSelect pin to match your shield or module?"); return; } else { Serial.println("Wiring is correct and a card is present."); } // print the type of card Serial.print("\nCard type: "); switch(card.type()) { case SD_CARD_TYPE_SD1: Serial.println("SD1"); break; case SD_CARD_TYPE_SD2: Serial.println("SD2"); break; case SD_CARD_TYPE_SDHC: Serial.println("SDHC"); break; default: Serial.println("Unknown"); } // Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32 if (!volume.init(card)) { Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card"); return; } // print the type and size of the first FAT-type volume uint32_t volumesize; Serial.print("\nVolume type is FAT"); Serial.println(volume.fatType(), DEC); Serial.println(); volumesize = volume.blocksPerCluster(); // clusters are collections of blocks volumesize *= volume.clusterCount(); // we'll have a lot of clusters volumesize *= 512; // SD card blocks are always 512 bytes Serial.print("Volume size (bytes): "); Serial.println(volumesize); Serial.print("Volume size (Kbytes): "); volumesize /= 1024; Serial.println(volumesize); Serial.print("Volume size (Mbytes): "); volumesize /= 1024; Serial.println(volumesize); Serial.println("\nFiles found on the card (name, date and size in bytes): "); root.openRoot(volume); // list all files in the card with date and size root.ls(LS_R | LS_DATE | LS_SIZE); }
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"); }