I have a project where I want to store individual data from five analog inputs in separate files -- i.e. one file per analog input. I also want to map the time for each data point (I'll be logging continuously for 3 months). I'm using IR diode pairs to record rotations of a clear object. The object has one opaque band on it. Each time the band passes the diode pair, I can record a voltage change.
My problem is that I'm new to Arduino code and the logging aspect is beyond me at my current skill. I have no idea how to code in reading and writing functionality.
Here is what my code looks like: (Note: some of the serial.print commands are there for when I use PLX DAQ in conjunction with the Arduino)
void setup() {
Serial.begin(9600);
Serial.println("CLEARSHEET");
Serial.println("LABEL, CageOneVoltage, CageTwoVoltage, CageThreeVoltage");
}
void loop() {
// put your main code here, to run repeatedly:
//int aVal = analogRead(A0);
//FOR CAGE ONE
unsigned int CageOneVoltage; //A0
double Voltage;
double Vcc;
Vcc = readVcc()/1000.0;
CageOneVoltage = analogRead(A0);
delay(10);
CageOneVoltage = analogRead(A0);
Voltage = (CageOneVoltage / 1024.0) * Vcc;
//FOR CAGE TWO
unsigned int CageTwoVoltage; //A1
Vcc = readVcc()/1000.0;
CageTwoVoltage = analogRead(A1);
delay(10);
CageTwoVoltage = analogRead(A1);
Voltage = (CageTwoVoltage / 1024.0) * Vcc;
//FOR CAGE THREE
unsigned int CageThreeVoltage; //A2
Vcc = readVcc()/1000.0;
CageThreeVoltage = analogRead(A2);
delay(10);
CageThreeVoltage = analogRead(A2);
Voltage = (CageThreeVoltage / 1024.0) * Vcc;
//FOR CAGE FOUR
unsigned int CageFourVoltage; //A3
Vcc = readVcc()/1000.0;
CageFourVoltage = analogRead(A3);
Voltage = (CageFourVoltage / 1024.0) * Vcc;
//FOR CAGE FIVE
unsigned int CageFiveVoltage; //A4
Vcc = readVcc()/1000.0;
CageFiveVoltage = analogRead(A4);
Voltage = (CageFiveVoltage / 1024.0) * Vcc;
//CAGE ONE PRINT
Serial.print("CAGEONE"); //Readout for A0
Serial.print(",");
Serial.println(CageOneVoltage);
//CAGE TWO PRINT
Serial.print("CAGETWO"); //Readout for A1
Serial.print(",");
Serial.println(CageTwoVoltage);
//CAGE THREE PRINT
Serial.print("CAGETHREE"); //Readout for A2
Serial.print(",");
Serial.println(CageThreeVoltage);
//CAGE FOUR PRINT
Serial.print("CAGEFOUR"); //Readout for A3
Serial.print(",");
Serial.println(CageFourVoltage);
//CAGE FIVE PRINT
Serial.print("CAGEFIVE"); //Readout for A4
Serial.print(",");
Serial.println(CageFiveVoltage);
}
long readVcc() {
long result;
// Read 1.1V reference against AVcc
ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
delay(2); // Wait for Vref to settle
ADCSRA |= _BV(ADSC); // Convert
while (bit_is_set(ADCSRA,ADSC));
result = ADCL;
result |= ADCH<<8;
result =1135200L / result; //1149852L / result; // Back-calculate AVcc in mV
return result;
}
I don't need anything complicated, I just need to ensure that I can record all of my data without any crashes. By the way once I have the data, I'll determine the average threshold and convert all values within a certain standard deviation of the threshold to 0's and the rest to 1's. I'll then just sum up all the ones and determine how many rotations over a period of time.
One last question, for how long do you think a 16GB micro SD could record this data? I plan to remove the micro SD cards weekly to compile the data. Perhaps daily if that would be recommended.
Thanks in advance!