Summary:
While running the datalogger example, the SD card is erased and multiple files appear. The filenames basically consist of the sensor data. All of those files are corrupt.
My Setup:
- Arduino Leonardo
- Samsung 4GB microSD card, formatted to FAT16 with gparted (Ubuntu Partition Editor)
- Arduino 1.0.4, Ubuntu
Code: Select all
Initializing SD card...
Card type: SDHC
Volume type is FAT16
Volume size (bytes): 3940220928
Volume size (Kbytes): 3847872
Volume size (Mbytes): 3757
Files found on the card (name, date and size in bytes):
Code: Select all
Initializing SD card...
Card type: SDHC
Volume type is FAT16
Volume size (bytes): 3940220928
Volume size (Kbytes): 3847872
Volume size (Mbytes): 3757
Files found on the card (name, date and size in bytes):
DATALOG.TXT 2014-03-12 12:16:06 0
Code: Select all
Initializing SD card...card initialized.
196,136,110
100,97,87
89,85,76
89,84,77
123,118,109
130,126,116
116,111,102
114,110,101
122,117,108
133,129,118
...and so on
In a terminal, 'ls' gives me:
Code: Select all
computer /media/116A-DD02 % ls
0,179??1.97, ,151??16.8,1 202,189?.?20 ,226,214.??2 4,223,21.5??
0,200,18.8?? 156??173.,16 ,203??21.6,2 ??226,21.5,2 5,121??1.22,
0,209,19.5?? ?166,158.,15 ?207,197.,18 ??229,21.9,2 5??126,1.28,
1,164??1.54, 169,159?.?17 213??238.,22 232,223?.?24 5,221??2.31,
,123,120.??1 ??170,16.2,1 ,214,201.??2 ,233,223.??2 5,259??2.53,
,123??12.9,1 ,171,162.??1 ,214??22.1,2 ?238,230.,22 8,168??1.87,
124??121.,12 ,171,162.??1 ,216??23.8,2 ??269,25.8,2 9??171,1.64,
?124,125.,12 ??176,16.8,1 2,165,15.7?? 3,124,12.0?? 9??195,1.85,
,127,123.??1 ,178??18.5,1 217,206?.?22 3,154??1.61, 9??268,2.58,
??128,13.0,1 189??200.,19 2??183,1.75, 3,212??2.40,
129,124?.?12 ?191,182.,17 2??183,1.75, 3??228,2.17,
?142,143.,13 ,197,184.??2 2??226,2.15, 3,232,21.9??
Thanks for taking the time to read my post and for helping me with that issue!
==================================
CardInfo.ino:
Code: Select all
/*
SD card test
This example shows how use the utility libraries on which the'
SD library is based in order to get info about your SD card.
Very useful for testing a card when you're not sure whether its working or not.
The circuit:
* SD card attached to SPI bus as follows:
** UNO: MOSI - pin 11, MISO - pin 12, CLK - pin 13, CS - pin 4 (CS pin can be changed)
and pin #10 (SS) must be an output
** Mega: MOSI - pin 51, MISO - pin 50, CLK - pin 52, CS - pin 4 (CS pin can be changed)
and pin #52 (SS) must be an output
** Leonardo: Connect to hardware SPI via the ICSP header
Pin 4 used here for consistency with other Arduino examples
created 28 Mar 2011 by Limor Fried
modified 9 Apr 2012 by Tom Igoe
*/
// include the SD library:
#include <SPI.h>
#include <SD.h>
// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;
// change this to match your SD shield or module;
// Arduino Ethernet shield: pin 4
// Adafruit SD shields and modules: pin 10
// Sparkfun SD shield: pin 8
const int chipSelect = 5;
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
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(SS, OUTPUT);
// we'll use the initialization code from the utility libraries
// since we're just testing if the card is working!
while (!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?");
}
// 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 loop(void) {
}
Code: Select all
/*
SD card datalogger
This example shows how to log data from three analog sensors
to an SD card using the SD library.
The circuit:
* SD card attached to SPI bus as follows:
** UNO: MOSI - pin 11, MISO - pin 12, CLK - pin 13, CS - pin 4 (CS pin can be changed)
and pin #10 (SS) must be an output
** Mega: MOSI - pin 51, MISO - pin 50, CLK - pin 52, CS - pin 4 (CS pin can be changed)
and pin #52 (SS) must be an output
** Leonardo: Connect to hardware SPI via the ICSP header
Pin 4 used here for consistency with other Arduino examples
created 24 Nov 2010
modified 9 Apr 2012 by Tom Igoe
This example code is in the public domain.
*/
#include <SPI.h>
#include <SD.h>
// On the Ethernet Shield, CS is pin 4. Note that even if it's not
// used as the CS pin, the hardware CS pin (10 on most Arduino boards,
// 53 on the Mega) must be left as an output or the SD library
// functions will not work.
const int chipSelect = 5;
File dataFile;
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.print("Initializing SD card...");
// make sure that the default chip select pin is set to
// output, even if you don't use it:
pinMode(SS, OUTPUT);
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
while (1) ;
}
Serial.println("card initialized.");
// Open up the file we're going to log to!
dataFile = SD.open("datalog.txt", FILE_WRITE);
if (! dataFile) {
Serial.println("error opening datalog.txt");
// Wait forever since we cant write data
while (1) ;
}
}
void loop()
{
// make a string for assembling the data to log:
String dataString = "";
// read three sensors and append to the string:
for (int analogPin = 0; analogPin < 3; analogPin++) {
int sensor = analogRead(analogPin);
dataString += String(sensor);
if (analogPin < 2) {
dataString += ",";
}
}
dataFile.println(dataString);
// print to the serial port too:
Serial.println(dataString);
// The following line will 'save' the file to the SD card after every
// line of data - this will use more power and slow down how much data
// you can read but it's safer!
// If you want to speed up the system, remove the call to flush() and it
// will save the file only every 512 bytes - every time a sector on the
// SD card is filled with data.
dataFile.flush();
// Take 1 measurement every 500 milliseconds
delay(500);
}