I am working on serial communication between two MCU's particularly teensy(similar to Arduino) for generating fake GPS data. I have been able to write GPS data and read from the other MCU fine but if u look closely, the data that is printed has some ambiguity. The last values are changed somehow and I don't understand why is this because of sprintf command or conversion of float to string or what?
Some help will be appreciated.
Below are the working code and snippet of the serial terminal.
Thank you
float lat = 37.4980608;
char str1[21];
void setup()
{
Serial3.begin(115200);
Serial.begin(115200); // Config serial port (USB)
while(!Serial);
while(!Serial3);
Serial.println("Sending gps data");
}
void loop()
{
sprintf(str1, "%.7f%.7f", lon, lat);
Serial.println(str1);
Serial3.write(str1);
Serial3.flush();
delay(500);
}