Hi all,
please advise for below:
I am intend to send my temperature result via wireless connection.
The code is as below:
//declare variables
float tempC;
int tempPin = 0;
void setup()
{
Serial.begin(115200);
}
void loop()
{
tempC = analogRead(tempPin); //read the value from the sensor
tempC = (5.0 * tempC * 100.0)/1024.0; //convert the analog data to temperature
Serial.write("The reading: ");
Serial.write(tempC);
//Serial.write((byte)tempC);
//Serial.println("The reading: ");
//Serial.println(tempC);
delay(1000); //wait one second before sending new data
}
But there is a failure on this.
If i use Serial.println and with USB communication,
the result is displayed correctly (around 23.XX to 24.XX Celsius).
But~
Since when i use Serial.write and wireless communication (TCP),
the result displayed wrongly (character "#" or "$") ..
I am suspecting this is because the Serial.write is taking the result of temperate as the ascii code.
and thus display the corresponding character with the ascii code.
I have tried to cast the tempC to byte ... but still failed..
And did searching on casting float to string.. but
i failed to get correct result at the end...
Hereby wish to have your advise how can i fix the problem....
Many thanks!
Many thanks.