Dear all,
Let me explain my project to let you better know what i want.
I create a datalogger with multiple ds18b20 sensors connected to 5 different pins of the arduino. The number of sensor in each pin in originally unkonw, because it could change. The code i have works perfectly, but now i want to go a little bit deeper, allowing to include offset values for each sensor.
What i have on mind is to save the values of the offset in a txt file in the SD ard already connected to the device. The during the settings, what i want to do is to read the list of offsets in the txt file and (for the moment), store them into arrays (in the future i will save this values into an external eeprom).
The file could have this content:
A32.12;-5.32;6.32;
B0.00;-0.05;
C4.23;1.03;-4.45;
D
E0.34;
each letter correspond to a different pin in the datalogger.Values are random, do to take ccare about them, but the number of sensors in each channel could be different.
I was fightinng about how to read the values and move them to 5 different arrays of floats (one per channel). But i am completly lost. This is the code i was fighting with, based on the SD readwrite example:
#include <SPI.h>
#include <SD.h>
File myFile;
float myOffsets[5] = {Offset1, Offset2, Offset3, Offset4, Offset5};
void setup(){
Serial.begin(9600);
while (!Serial) {
;
}
Serial.print("Initializing SD card...");
pinMode(10, OUTPUT);
if (!SD.begin(10)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
myFile = SD.open("offsets.txt");
if (myFile) {
byte a = 0;
byte b = 0;
byte i = 0;
byte pos = 0;
char digit;
char letters[6];
Serial.println("offsets.txt:");
// read from the file until there's nothing else in it:
while (myFile.available()) {
digit = myFile.read();
Serial.write(digit);
switch(digit){
case 'A':
a = 0;
break;
case 'B':
a = 1;
break;
case 'C':
a = 2;
break;
case 'D':
a = 3;
break;
case 'E':
a = 4;
break;
case ';':
myOffsets[a][b] = atof(letters);
for (byte c=0; c<5;c++){
letters[c]='';
}
b++;
i = 0;
break;
case '\n':
b = 0;
break;
default:
letters[i] = digit;
i++;
break;
}
}
myFile.close();
Serial.println(Offset1[]);
Serial.println(Offset2[]);
Serial.println(Offset3[]);
Serial.println(Offset4[]);
Serial.println(Offset5[]);
} else
Serial.println("error opening test.txt");
}
void loop()
{
// nothing happens after setup
}
The list of errors is this:
Arduino: 1.5.8 (Windows 8), Placa:"Arduino Nano, ATmega328"
ReadSDvalues.ino:52:24: error: empty character constant
ReadSDvalues.ino:5:23: error: 'Offset1' was not declared in this scope
ReadSDvalues.ino:5:32: error: 'Offset2' was not declared in this scope
ReadSDvalues.ino:5:41: error: 'Offset3' was not declared in this scope
ReadSDvalues.ino:5:50: error: 'Offset4' was not declared in this scope
ReadSDvalues.ino:5:59: error: 'Offset5' was not declared in this scope
ReadSDvalues.ino: In function 'void setup()':
ReadSDvalues.ino:50:25: error: invalid types 'float[byte {aka unsigned char}]' for array subscript
ReadSDvalues.ino:67:20: error: 'Offset1' was not declared in this scope
ReadSDvalues.ino:67:28: error: expected primary-expression before ']' token
ReadSDvalues.ino:68:20: error: 'Offset2' was not declared in this scope
ReadSDvalues.ino:68:28: error: expected primary-expression before ']' token
ReadSDvalues.ino:69:20: error: 'Offset3' was not declared in this scope
ReadSDvalues.ino:69:28: error: expected primary-expression before ']' token
ReadSDvalues.ino:70:20: error: 'Offset4' was not declared in this scope
ReadSDvalues.ino:70:28: error: expected primary-expression before ']' token
ReadSDvalues.ino:71:20: error: 'Offset5' was not declared in this scope
ReadSDvalues.ino:71:28: error: expected primary-expression before ']' token
Error de compilaciónThis report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.
I know there is a different sd cards library that is able to read values from CSV filesm but i can´t add more libraries because memory limitations. I also saw other similar ases in this forum, but the people used close matrix of X rows and Y columns. I will alway have 5 rows in the file, but the number of columns in each row is undefined until the user introduce the data...
I am also worry because it seems that i am using strings to manage the readed characters, what is not the best option.
Could you give me ideas about how to solve this issue? I will really appreciate it. Thanks in advance!