Author Topic: Moteino M0 / SAMD21 dtostrf compile error [solution]  (Read 2210 times)

kwalkerk

  • NewMember
  • *
  • Posts: 36
  • Country: us
Moteino M0 / SAMD21 dtostrf compile error [solution]
« 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!
« Last Edit: August 28, 2018, 04:20:06 PM by Felix »

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6867
  • Country: us
    • LowPowerLab
Re: stdlib.h
« Reply #1 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:

Code: [Select]
#if defined(__SAMD21__)
  #include <avr/dtostrf.h>
#endif

kwalkerk

  • NewMember
  • *
  • Posts: 36
  • Country: us
Re: stdlib.h
« Reply #2 on: August 28, 2018, 04:13:43 PM »
Thanks Felix!  That did the trick.

NickL

  • NewMember
  • *
  • Posts: 9
Re: stdlib.h
« Reply #3 on: February 04, 2020, 03:17:08 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:

Code: [Select]
#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
Code: [Select]
#if defined(__SAMD21__)
  #include <avr/dtostrf.h>
#endif
didn't work for me for some reason, but adding
Code: [Select]
#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
Code: [Select]
#define BATT_MONITOR  A7
to
Code: [Select]
#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?

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6867
  • Country: us
    • LowPowerLab
Re: Moteino M0 / SAMD21 dtostrf compile error [solution]
« Reply #4 on: February 04, 2020, 03:36:10 PM »
NickL,

The WeatherNode sketch does contain this header:

Code: [Select]
#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.

NickL

  • NewMember
  • *
  • Posts: 9
Re: Moteino M0 / SAMD21 dtostrf compile error [solution]
« Reply #5 on: February 04, 2020, 04:08:13 PM »
NickL,

The WeatherNode sketch does contain this header:

Code: [Select]
#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.