Datasheet
Floating Point Conversion
Like the AVR Arduinos, the M0 library does not have full support for converting floating point numbers to ASCII
strings. Functions like sprintf will not convert floating point. Fortunately, the standard AVR-LIBC library includes the
dtostrf function which can handle the conversion for you.
Unfortunately, the M0 run-time library does not have dtostrf. You may see some references to using #include
<avr/dtostrf.h> to get dtostrf in your code. And while it will compile, it does not work.
Instead, check out this thread to find a working dtostrf function you can include in your code:
http://forum.arduino.cc/index.php?topic=368720.0 (http://adafru.it/lFS)
How Much RAM Available?
The ATSAMD21G18 has 32K of RAM, but you still might need to track it for some reason. You can do so with this
handy function:
extern "C" char *sbrk(int i);
int FreeRam () {
char stack_dummy = 0;
return &stack_dummy - sbrk(0);
}
Thx to http://forum.arduino.cc/index.php?topic=365830.msg2542879#msg2542879 (http://adafru.it/m6D) for the tip!
Storing data in FLASH
If you're used to AVR, you've probably used PROGMEM to let the compiler know you'd like to put a variable or
string in flash memory to save on RAM. On the ARM, its a little easier, simply add const before the variable name:
const char str[] = "My very long string";
That string is now in FLASH. You can manipulate the string just like RAM data, the compiler will automatically read
from FLASH so you dont need special progmem-knowledgeable functions.
You can verify where data is stored by printing out the address:
Serial.print("Address of str $"); Serial.println((int)&str, HEX);
If the address is $2000000 or larger, its in SRAM. If the address is between $0000 and $3FFFF Then it is in FLASH
© Adafruit Industries https://learn.adafruit.com/adafruit-feather-m0-adalogger Page 45 of 47










