UKHeliBob:
If you are planning only to write data to the file each hour then think very carefully about how it will be stored until written to the file as memory is limited on the Arduino.
How would you program it if we'd say we'll use the millis() function? The file name is "datalog.txt" on the SD-card at the moment. So the name file should be "datalog1.txt", an hour later it would have to be "datalog2.txt".
This is our program atm:
String text;
#include <SPI.h>
#include <SD.h>
const int chipSelect = 4;
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.print("Initializing SD card...");
// 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:
return;
}
Serial.println("card initialized.");
}
// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue0 = analogRead(A0);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float druk0 = (sensorValue0 * (5 / 1023.0) - 0.5) *(160/4);
//print out the value you read:
//Serial.println(druk0);
delay (0);
// read the input on analog pin 1:
int sensorValue1 = analogRead(A1);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float druk1 = (sensorValue1 * (5 / 1023.0) - 0.5) *(160/4);
// print out the value you read:
//Serial.println(druk1);
delay (0);
// read the input on analog pin 2:
int sensorValue2 = analogRead(A2);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float druk2 = (sensorValue2 * (5 / 1023.0) - 1) *(250/4);
// print out the value you read:
//Serial.println(druk2);
delay (0);
// read the input on analog pin 3:
int sensorValue3 = analogRead(A3);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float druk3 = (sensorValue3 * (5 / 1023.0) - 1) *(250/4);
// print out the value you read:
//Serial.println(druk3);
delay (0);
// read the input on analog pin 4:
int sensorValue4 = analogRead(A4);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float druk4 = (sensorValue4 * (5 / 1023.0) - 1) *(250/4);
//print out the value you read:
//Serial.println(druk4);
delay (0);
// read the input on analog pin 5:
int sensorValue5 = analogRead(A5);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float druk5 = (sensorValue5 * (5 / 1023.0) - 1) *(250/4);
//print out the value you read:
//Serial.println(druk5);
text = String(druk0)+ "\t"+String (druk1)+ "\t"+ String (druk2)+ "\t"+ String (druk3)+ "\t"+ String (druk4)+ "\t"+ String (druk5);
Serial.println(text);
delay (100);
File dataFile = SD.open("datalog.txt", FILE_WRITE);
// if the file is available, write to it:
if (dataFile) {
dataFile.println(text);
dataFile.close();
// print to the serial port too:
Serial.println(text);
}
// if the file isn't open, pop up an error:
else {
Serial.println("error opening datalog.txt");
}
}
void printDirectory(File dir, int numTabs) {
while (true) {
File entry = dir.openNextFile();
if (! entry) {
// no more files
break;
}
for (uint8_t i = 0; i < numTabs; i++) {
Serial.print('\t');
}
Serial.print(entry.name());
if (entry.isDirectory()) {
Serial.println("/");
printDirectory(entry, numTabs + 1);
} else {
// files have sizes, directories do not
Serial.print("\t\t");
Serial.println(entry.size(), DEC);
}
entry.close();
}
}