I've got an Adafruit Feather M0 Adalogger. As explained here, floating point to string conversion does not work, but the page refers to a discussion where someone has re-implemented the dtostrf function.
Unfortunately, when I compile it I get the following error:
C:\Users\titus\Documents\src\arduino_trials\04_keyence_distance_sensor\04_keyence_distance_sensor.ino: In function 'char* dtostrf(double, int, unsigned int, char*)':
04_keyence_distance_sensor:73:7: error: 'fcvt' was not declared in this scope
73 | s = fcvt(val, prec, &decpt, &sign);
| ^~~~
It seems that the fcvt function is not implemented in AVR-LibC. I would expect it to be in stdlib.h, but it's not there.
Can anybody give me some pointers on where to find it, or on how to convert floating point values to strings?
Adafruit Feather M0 Adalogger: https://www.adafruit.com/product/2796
That is a ATSAMD21G, just like the Arduino MKR Zero. It is not part of the AVR family.
Can you give a small sketch that shows the problem ?
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:
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:
I therefore tried the "working dtostf" example but it didn't compile. It can't find the fcvt function in stdlib.h, which I assume it the stdlib.h from AVR.