I am trying to use dtostrf to print out values to a Nokia 5110 LCD.
Here's a snippet of my code:
/* Get distance to the destination */
double distance_meters = TinyGPSPlus::distanceBetween(tinygps.location.lat(), tinygps.location.lng(), DEST_LATITUDE, DEST_LONGITUDE);
/* get bearing to destination */
double bearing = TinyGPSPlus::courseTo(tinygps.location.lat(), tinygps.location.lng(), DEST_LATITUDE, DEST_LONGITUDE);
Serial.print("Distance to dest: ");
Serial.println(distance_meters);
// generate chars for easy printing
int dist_m_int = (int)distance_meters;
float dist_km = distance_meters / 1000.0;
int dist_km_int = (int)dist_km;
int bearing_int = (int)bearing;
// generate char arrays for printing to LCD screen
char m_buffer[sizeof(dist_m_int)+1];
char km_buffer[sizeof(dist_km_int)+1];
char brng_buffer[sizeof(bearing_int)+1];
dtostrf(distance_meters, 1, 0, m_buffer);
dtostrf(dist_km, 1, 0, km_buffer);
dtostrf(bearing, 1, 0, brng_buffer);
What I'm seeing (and can verify in the serial monitor) is that the distance_meters value coming out of the GPS function is reasonable (say, ~2017 kilometres), but then m_buffer seems to get a value of ~20137. I've tried this for several different locations (i.e. different distances) and I am consistently getting values in the char buffer that are off by a factor of 10.
However, brng_buffer content, however, is exactly as expected. Which seems ridiculous to me since the instructions processing the distance_meters and bearing values look to be exactly the same.
Any ideas? I've been stuck on this for a couple of days. Thanks in advance.