sscanf doesn't work (Arduino IDE)

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Mandel
 
Posts: 11
Joined: Wed Oct 26, 2022 10:25 am

sscanf doesn't work (Arduino IDE)

Post by Mandel »

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! :)

User avatar
adafruit_support_bill
 
Posts: 88086
Joined: Sat Feb 07, 2009 10:11 am

Re: sscanf doesn't work (Arduino IDE)

Post by adafruit_support_bill »

What processor are you using? %f is not supported on some microcontrollers due to space limitations.
https://arduino.stackexchange.com/quest ... ing-sscanf

User avatar
Mandel
 
Posts: 11
Joined: Wed Oct 26, 2022 10:25 am

Re: sscanf doesn't work (Arduino IDE)

Post by Mandel »

I use a ItsyBitsy M0 Express. So it should be a SAMD 21

User avatar
Mandel
 
Posts: 11
Joined: Wed Oct 26, 2022 10:25 am

Re: sscanf doesn't work (Arduino IDE)

Post by Mandel »

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>

User avatar
adafruit_support_bill
 
Posts: 88086
Joined: Sat Feb 07, 2009 10:11 am

Re: sscanf doesn't work (Arduino IDE)

Post by adafruit_support_bill »

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.

Locked
Please be positive and constructive with your questions and comments.

Return to “Itsy Bitsy Boards”