Go Down

Topic: "dtostrf" function available for MKR GSM 1400 (Read 1 time) previous topic - next topic


I have been working on a super simple sketch to prove a concept for how I can get the float values for latitude and longitude, then convert them into a char array so I can output them to a website.

Code: [Select]


void setup() {
  float latitude = 47.2035;
  float longitude = 15.3268;
  char latBuffer[50];
  char longBuffer[50];
  char fullBuffer[100];
  dtostrf(latitude, 0, 7, latBuffer);
  dtostrf(longitude, 0, 7, longBuffer);

  sprintf_P(fullBuffer, PSTR("Latitude: %s;Longitude: %s"), latBuffer, longBuffer);
  Serial.println(fullBuffer);    // Prints: "Latitude: 47.2035;Longitude: 15.3268"

void loop(){}

Whilst this sketch does compile if I set the board type to be Arduino Uno, when I change it to MKR GSM 1400 it fails to compile with the error:

Code: [Select]
float-to-char-array:12: error: 'dtostrf' was not declared in this scope

   dtostrf(latitude, 0, 7, latBuffer);


exit status 1
'dtostrf' was not declared in this scope

So I am just wondering if there are plans to have the "dtostrf" added to the standard library availble to the MKR GSM 1400.



Add this line to your sketch:
Code: [Select]
#include <avr/dtostrf.h>


Awesome thanks for helping with that, that'll help in passing lat and long into a char array. That's fixed up the error I was getting at compile time.



Go Up