Println returning weird values

Whenever I try to analogue read and print the values to serial it does not display the expected data. Please see the attached screenshot

This is because (for reasons beyond my comprehension) Mbed uses a printf library without floating point support enabled by default. Create an mbed_app.json with this content:

{
    "target_overrides": {
        "*": {
            "target.printf_lib": "std",
        }
    }
}

to get a standards-compliant printf back.

1 Like

Another alternative is to keep the default minimal printf library. Although it doesn’t provide fancy formatting options, it supports both printf and snprintf in only around 1300 bytes of flash as opposed to several kilobytes used by the std printf library.
You can enable floating point print (occupies some additional bytes in flash but still much less than the std printf) for example with the following mbed_app.json:

{
    "target_overrides": {
        "*": {
            "target.printf_lib": "minimal-printf",
            "platform.minimal-printf-enable-floating-point": true,
            "platform.minimal-printf-set-floating-point-max-decimals": 2
        }
    }
}

If needed you can change the number of max-decimals.

1 Like