Arduino Forum

Products => MKR Boards => MKRGSM1400 => Topic started by: smgs on Sep 11, 2018, 04:10 am

Title: "dtostrf" function available for MKR GSM 1400
Post by: smgs on Sep 11, 2018, 04:10 am
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]

#include<stdlib.h>

void setup() {
  Serial.begin(115200);
 
  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.

Thanks
Title: Re: "dtostrf" function available for MKR GSM 1400
Post by: pert on Sep 11, 2018, 06:47 am
Add this line to your sketch:
Code: [Select]
#include <avr/dtostrf.h>
Title: Solved - Re: "dtostrf" function available for MKR GSM 1400
Post by: smgs on Sep 11, 2018, 07:36 am
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.

Cheers

SMG