Im making a simple program to read values from serial port and save them to file on sd card, also show them in 4x20 lcd. String what im reading looks like this:
2014/10/11;15:44;25,4;26,4;#;99,0;#;2,4;2,4;#;2,4;2,4;0,0;0,0;29,3;0;E;1;1;0;30,8;15014,3;0,1;119,5;0
They are semicolon separated so can be putted to csv file.
So my problem: i cant read correct values, i have in csv file and on lcd values like 104, 52,53,52 but not orginal vaules recived from serial port. I think they must be converted to chars but i don't know how to do this. Can anyone can help me pls ?
Once you know that there is data to read, why are you pissing away time doing nothing?
lcd.print(Serial1.read());
Read an int. Convert that to a string and print it. Does THAT seem reasonable? Or would
char c = Serial.read();
lcd.print(c);
seem more reasonable?
Does it really make sense to read and print one value and then read and save the next value, over and over? Or, would reading one value and printing and saving that value make more sense?
I must read in loop and wait for any string on serial port, i have this data strings in random time values, eg,
can be one by one or even one per minute, i want to collect this data and analyse it later or watch them on 4x20 lcd. It's from solar charge controller made by Steca. I have made an app in Delphi to collect this data but pc working only for collecting this values have no sense, i want make a low power consumption device to do this
Also :
char recived = Serial1.read();
inData += recived;
This gives me wrong values , when i send for example "d" i have on lcd value = 100
You might try something like below where the ; is used to delimit the incomming individual data parts. After printing to the LCD and other stuff, write the data part to the file adding the ; back in.
//zoomkat 3-5-12 simple delimited ';' string
//from serial port input (via serial monitor)
//and print result out serial port
String readString;
void setup() {
Serial.begin(9600);
Serial.println("serial delimit test 1.0"); // so I can keep track of what is loaded
}
void loop() {
//expect a string like
//2014/10/11;15:44;25,4;26,4;#;99,0;#;2,4;2,4;#;2,4;2,4;0,0;0,0;29,3;0;E;1;1;0;30,8;15014,3;0,1;119,5;0;
if (Serial.available()) {
char c = Serial.read(); //gets one byte from serial buffer
if (c == ';') {
//do stuff
Serial.print(readString); //prints string to serial port out
Serial.println(';');
readString=""; //clears variable for new input
}
else {
readString += c; //makes the string readString
}
}
}