Problems with converting float to string and printing it to ssd1306

For a few weeks now i've been trying to fix a problem printing variables to oled with lcdgfx and ssd1306 libraries, idk why this isn't already implemented in them, so the developer said to convert float to string and print it on the display

    display.setTextCursor(85, 0);
    snprintf(StrT, sizeof(StrT), "%F", currentTemperature);
    display.write(StrT);

This just outputs a question mark
Then after some more research i found out that arduino doesn't support this function but this

    display.setTextCursor(85, 0);
    String StrT = String(currentTemperature, 2);
    display.write(StrT);

But with this i just get an error

error: no matching function
for call to 'DisplaySSD1306_128x64_I2C::write(String&)'

So does anyone know what's the problem, any possible fixes and if not at least recommend me a library for ssd1306 that can print variables and uses max 8kB flash and 500B ram?

Best regards

dtostrf usually works fine.
(I've never seen a capital F used in a sprintf - what does it do?)

Did you mean to use display.print?

I don't think you want that ", 2"

It appears your library does not support String objects directly. Pass it the underlying string instead.

display.write(StrT.c_str());

Thanks it finally works with this function, idk how i didn't come across this after all the searching for solution, thanks a lot :slight_smile:

Was this really a problem, or is it just improper use? You need to be more forthcoming about what you really want to do, as this might all be down to the wrong choice of library.

Yes, I'd look for a library that inherits from the Print class. Any class that inherits from Print already knows how to print pretty much all data types required -- i.e. just like HardwareSerial, SoftwareSerial, most LCD libraries, etc.