PIO doesn't build Teensy Floating point support?

I’m using Teensy’s Serial.printf functionality (Teensy 3.2). When I build using the Arduino IDE, everything works fine. When I build using PIO (in Atom), floating point support disappears.

Minimal repro:

void setup() {
  // put your setup code here, to run once:
  Serial.printf("'%s' - This is a string.\n", "Hello world");
  Serial.printf("'%d' - This is an integer.\n", 12345);
  Serial.printf("'%.2f' - This is a float.\n", 1234.56);
  Serial.printf("'%.2f' - This is a rounded float.\n", 1234.56789);
}

void loop() {
  // put your main code here, to run repeatedly:
}

Built from Arduino, this outputs the following:

'Hello world' - This is a string.
'12345' - This is an integer.
'1234.56' - This is a float.
'1234.57' - This is a rounded float.

Built from PlatformIO, it outputs the following:

'Hello world' - This is a string.
'12345' - This is an integer.
'' - This is a float.
'' - This is a rounded float.

Has anyone seen this before? Is there some way to make it work with PIO?

Add this somewhere in your sketch:

  // this is the magic trick for printf to support float
  asm(".global _printf_float");

And this if you need scanf to support float:

  // this is the magic trick for scanf to support float
   asm(".global _scanf_float");
1 Like

fantastic!! For my own future reference, is this magic trick documented anywhere? And is this magic trick specific to Teensy? Or Specific to PIO, or specific to something else?

I had the same problem and asked over on the Teensy forums a while back.

Not sure why it works in Arduino but not via platformio for you. My memory was that it was necessary to add those lines in both environments.

This is a bug and was fixed in

The final release is coming soon.