Hi :)
I want to use sscanf to parse a formated serial input into different variables.
Something like "sscanf(SerString, "%s %d %f", SerCmd, &SerInt, &SerFloat);". But SerFloat is always 0.0.
Does anyone have an idea what may be the reason or how to work around it?
Tanks a lot! :)
sscanf doesn't work (Arduino IDE)
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- adafruit_support_bill
- Posts: 88097
- Joined: Sat Feb 07, 2009 10:11 am
Re: sscanf doesn't work (Arduino IDE)
What processor are you using? %f is not supported on some microcontrollers due to space limitations.
https://arduino.stackexchange.com/quest ... ing-sscanf
https://arduino.stackexchange.com/quest ... ing-sscanf
- Mandel
- Posts: 11
- Joined: Wed Oct 26, 2022 10:25 am
Re: sscanf doesn't work (Arduino IDE)
I use a ItsyBitsy M0 Express. So it should be a SAMD 21
- Mandel
- Posts: 11
- Joined: Wed Oct 26, 2022 10:25 am
Re: sscanf doesn't work (Arduino IDE)
I found a solution for the problem.
Putting asm(".global _printf_float"); and asm(".global _scanf_float"); in the setup and including #include <avr/dtostrf.h>
Putting asm(".global _printf_float"); and asm(".global _scanf_float"); in the setup and including #include <avr/dtostrf.h>
- adafruit_support_bill
- Posts: 88097
- Joined: Sat Feb 07, 2009 10:11 am
Re: sscanf doesn't work (Arduino IDE)
The M0 probably has enough flash memory to handle the added library overhead. And enough RAM for the necessary buffering. Though you should keep an eye on run-time memory utilization as these functions can lead to fragmentation.
You would need to enable floating point parsing explicitly in the compiler/linker command line as described here: https://forum.arduino.cc/t/floating-poi ... nfo/361737
For questions regarding modifications to the IDE, the Arduino forum is your best resource.
The other approach is to use atof() for parsing floating point. That is more efficient and better behaved than sscanf.
You would need to enable floating point parsing explicitly in the compiler/linker command line as described here: https://forum.arduino.cc/t/floating-poi ... nfo/361737
For questions regarding modifications to the IDE, the Arduino forum is your best resource.
The other approach is to use atof() for parsing floating point. That is more efficient and better behaved than sscanf.
Please be positive and constructive with your questions and comments.