All,
I have a arduino nano (from Gravitech) and a uSD shield (from Sparkfun). I am trying to scan all 8 analog inputs as fast as possible and dump that data to the uSD card. I have a loop that gets the time, scans all 8 channels, and writes all of this to the card. The problem is if I do this loop 2000 times it works well; however, if I try to do this 3000 times it slows down a whole bunch and never writes anything to the file. I am using the SDFat library to perform the uSD stuff
Is this some internal memory (EEPROM) getting full??? If so, can I purge it??? My board has 30000 B of free memory. Which tells me that I can scan all 8 channels 3000 times to fill it up, coincidence??? (30000B=240000b=24000S=3000 loops of 8 channels)
Is it some limitation on file size???
I may try running different amounts of channel to see if it is based on the number of samples or channels or...
Thanks,
w102acd
Here is my sketch:
//THIS SKETCH IS USED TO BLINK AN LED (FOR STATUS),
//SCAN ANALOG INPUTS, AND WRITE THE DATA TO A
//MICROSD CARD AS FAST AS POSSIBLE.
//
//DATE : JUN 30 2010
//
#include <SdFat.h>
#include <SdFatUtil.h>
//
Sd2Card card;
SdVolume volume;
SdFile root;
SdFile file;
//
//**************************************************
void writeCRLF(SdFile &f)
{
f.write((uint8_t )"\r\n", 2);
}
//*************************************************
void writeNumber(SdFile &f, uint32_t n)
{
uint8_t buf[10];
uint8_t i = 0;
do {
i++;
buf[sizeof(buf) - i] = n%10 + '0';
n /= 10;
} while (n);
f.write(&buf[sizeof(buf) - i], i);
}
//**************************************************
void writeString(SdFile &f, char str)
{
uint8_t n;
for (n = 0; str[n]; n++);
f.write((uint8_t )str, n);
}
//************************************************
void setup(void)
{
Serial.begin(9600);
delay(2000);
//
pinMode(2, OUTPUT);
digitalWrite(2, HIGH);
//
int j = 0;
for (j = 0; j < 21; j++) {
delay(250);
digitalWrite(2, LOW);
delay(250);
digitalWrite(2, HIGH);
}
//
Serial.print(!card.init());
Serial.print(!volume.init(card));
Serial.print(!root.openRoot(volume));
//
char name[] = "DATA00.CSV";
for (uint8_t i = 0; i < 100; i++) {
name[4] = i/10 + '0';
name[5] = i%10 + '0';
if (file.open(root, name, O_CREAT | O_EXCL | O_WRITE)) break;
}
Serial.println(!file.isOpen());
//
delay(2000);
digitalWrite(2, LOW);
delay(2000);
digitalWrite(2, HIGH);
//
writeString(file, "Microseconds,AI0,AI1,AI2,AI3,AI4,AI5,AI6,AI7");
writeCRLF(file);
//
for (j = 0; j < 3001; j++) {
writeNumber(file, micros());
writeString(file, ",");
writeNumber(file, analogRead(0));
writeString(file, ",");
writeNumber(file, analogRead(1));
writeString(file, ",");
writeNumber(file, analogRead(2));
writeString(file, ",");
writeNumber(file, analogRead(3));
writeString(file, ",");
writeNumber(file, analogRead(4));
writeString(file, ",");
writeNumber(file, analogRead(5));
writeString(file, ",");
writeNumber(file, analogRead(6));
writeString(file, ",");
writeNumber(file, analogRead(7));
writeString(file, ",");
writeCRLF(file);
//
Serial.println(j);
}
file.close();
digitalWrite(2, LOW);
}
//**************************************************
void loop(void) {}
//**************************************************