LowPowerLab Forum

Hardware support => Moteino M0 => Topic started by: kwalkerk on August 28, 2018, 11:54:26 AM

Title: Moteino M0 / SAMD21 dtostrf compile error [solution]
Post by: kwalkerk on August 28, 2018, 11:54:26 AM
When compiling a weather shield sketch for the M0 I get an error on any line with dtostrf(....) which says "'dtostrf' was not declared in this scope".  I'm assuming that's supposed to be in stdlib.h.  Exact same code compiles just fine for "regular" Moteino.

So it appears that the stdlib.h included with the M0 does not have that function defined?

If that is correct any suggestions for a workaround?

Thanks!
Title: Re: stdlib.h
Post by: Felix on August 28, 2018, 03:28:10 PM
I need to update that sketch,
In the interim, can you please try adding this to your sketch and see if it resolves it:

#if defined(__SAMD21__)
  #include <avr/dtostrf.h>
#endif
Title: Re: stdlib.h
Post by: kwalkerk on August 28, 2018, 04:13:43 PM
Thanks Felix!  That did the trick.
Title: Re: stdlib.h
Post by: NickL on February 04, 2020, 03:17:08 PM
Quote from: Felix on August 28, 2018, 03:28:10 PM
I need to update that sketch,
In the interim, can you please try adding this to your sketch and see if it resolves it:

#if defined(__SAMD21__)
  #include <avr/dtostrf.h>
#endif


Just received Moteino M0 boards, soldered BME280 breakouts on, and run your example to check my soldering and to get some grip on calibration.
The code
#if defined(__SAMD21__)
  #include <avr/dtostrf.h>
#endif

didn't work for me for some reason, but adding
#include <avr/dtostrf.h>
to packages/Moteino/hardware/samd/1.3.0/cores/arduino/WString.h as a last include did the trick.

Another change I've made is replacing Serial with SerialUSB. Maybe it's worth adding M0 to the note on https://lowpowerlab.com/guide/moteino/programming-libraries listing the boards where FTDI adapter isn't necessary?

I guess I need to change
#define BATT_MONITOR  A7
to
#define BATT_MONITOR  A5
and possibly the voltage formula in that sketch to the one in "Example reading the VIN" on https://lowpowerlab.com/guide/moteino/moteinom0 too, right?
Title: Re: Moteino M0 / SAMD21 dtostrf compile error [solution]
Post by: Felix on February 04, 2020, 03:36:10 PM
NickL,

The WeatherNode sketch does contain this header:

#if defined (MOTEINO_M0)
  #if defined(SERIAL_PORT_USBVIRTUAL)
    #define Serial SERIAL_PORT_USBVIRTUAL // Required for Serial on Zero based boards
  #endif
  #include <avr/dtostrf.h>
  #define BATT_MONITOR  A5   //through 1Meg+1Megohm and 0.1uF cap from battery VCC - this ratio divides the voltage to bring it below 3.3V where it is scaled to a readable range


Nonetheless adding the dtostrf include to WString.h does remove the need to include it in the sketch. So I will add this in the next Moteino SAMD boards release.
Title: Re: Moteino M0 / SAMD21 dtostrf compile error [solution]
Post by: NickL on February 04, 2020, 04:08:13 PM
Quote from: Felix on February 04, 2020, 03:36:10 PM
NickL,

The WeatherNode sketch does contain this header:

#if defined (MOTEINO_M0)
  #if defined(SERIAL_PORT_USBVIRTUAL)
    #define Serial SERIAL_PORT_USBVIRTUAL // Required for Serial on Zero based boards
  #endif
  #include <avr/dtostrf.h>
  #define BATT_MONITOR  A5   //through 1Meg+1Megohm and 0.1uF cap from battery VCC - this ratio divides the voltage to bring it below 3.3V where it is scaled to a readable range


Ah, I'm not there yet, as I have LoRA version and need to first understand how to adapt the sketch. I was referring to https://lowpowerlab.com/guide/moteino/m0-sensor-shields which, in turn, first refers to "a simple sketch" on https://lowpowerlab.com/guide/weathershield/simple-weather-node - that's what I completed.

Thank you for the pointer.