Hi to you all.
EXTRACT:
I have this program, witch sense 6 NTC and send the temperatures to a float array, then it uses the float value to convert it, to print on an LCD display.
And for the last use the value of the float sensor value to save it on a SD file.
Analog read ------ OK
Convert to float --OK
convert to char ---OK
print on LCD ------OK
Use the same float value as before to convert it to a char and print DONT OK;
I will upload the entire file (its messy is work in progress)
But this what it bothers me;
I send to serial print the values before convert them in to chars;
if( saveToSD == true)
{
Serial.println(fechaStr );
Serial.print("1.-"); Serial.println(sensorTemp[0] );
Serial.print("2.-"); Serial.println(sensorTemp[1] );
Serial.print("3.-"); Serial.println(sensorTemp[2] );
Serial.print("4.-"); Serial.println(sensorTemp[3] );
Serial.print("5.-"); Serial.println(sensorTemp[4] );
Serial.print("6.-"); Serial.println(sensorTemp[5] );
And it prints ok;
1.-18.62
2.-18.25
3.-18.25
4.-18.62
5.-18.25
6.-18.62
Yet if I use the code below; Yields to an error
dtostrf(sensorTemp[0], 5, 1, CT1 );
dtostrf(sensorTemp[1], 5, 1, CT2 );
dtostrf(sensorTemp[2], 5, 1, CT3 );
dtostrf(sensorTemp[3], 5, 1, CT4 );
dtostrf(sensorTemp[4], 5, 1, CT5 );
dtostrf(sensorTemp[5], 5, 1, CT6 );
sprintf(line1_data, " F%s H%s 1%s 2%s 3%s 4%s 5%s 6%s", fechaStr, horaStr, CT1, CT2, CT3, CT4, CT5, CT6);
F21/03/2019 H10:53:24 1!
!* 2 3 4 18.6 5 18.3 6 18.6
This what I should have instead:
F21/03/2019 H10:53:24 1 18.7 2 18.2 3 18.7 4 18.6 5 18.3 6 18.6
So, for some reason the code is correctly reading and converting the last 3 floats but no the first 3
I made the test to changue the order of the arrays ejem:
sensorTemp[5]
sensorTemp[4]
sensorTemp[3]
sensorTemp[2]
sensorTemp[1]
sensorTemp[0]
And the result is the same; the array dont print the first 3 numbers, but the last 3 its ok.
if( saveToSD == true)
{
Serial.println(fechaStr );
Serial.print("1.-"); Serial.println(sensorTemp[0] );
Serial.print("2.-"); Serial.println(sensorTemp[1] );
Serial.print("3.-"); Serial.println(sensorTemp[2] );
Serial.print("4.-"); Serial.println(sensorTemp[3] );
Serial.print("5.-"); Serial.println(sensorTemp[4] );
Serial.print("6.-"); Serial.println(sensorTemp[5] );
if(system_type == single_compressor || double_compressor)
{
dtostrf(sensorTemp[0], 5, 1, CT1 );
dtostrf(sensorTemp[1], 5, 1, CT2 );
dtostrf(sensorTemp[2], 5, 1, CT3 );
dtostrf(sensorTemp[3], 5, 1, CT4 );
dtostrf(sensorTemp[4], 5, 1, CT5 );
dtostrf(sensorTemp[5], 5, 1, CT6 );
if(numSen == 6)
{
sprintf(line1_data, " F%s H%s 1%s 2%s 3%s 4%s 5%s 6%s", fechaStr, horaStr, CT1, CT2, CT3, CT4, CT5, CT6);
Serial.println(line1_data);
}
}
File dataFile = SD.open("datalog.txt", FILE_WRITE); //abrimos el archivo en la SD
if (dataFile) // if the file is available, write to it:
{
dataFile.println(line1_data); //save in the file the header
dataFile.close();
lcd1.setCursor(0,1); lcd1.println(" SE HAN GUARDADO ");
lcd1.setCursor(0,2); lcd1.println(" LOS DATOS ");
lcd1.setCursor(0,3); lcd1.println(" ");
}
saveToSD = false; //down flag
}
}//end save to sd dataline
I know they are snippets, the file it is in attachments;
Things I check before;
The sufficient length of the char [90] caracters is more than double.
The floats are in there, and are right
The sprintf function works in all the other uses, and works properly, but not in this case.
Any Idea of what might be ???
Thanks for the Insigths!
-Alex.
prog_prueba_promedio_sensores_CT.ino (28.8 KB)