Compile Errors - SSD1306 128x32 OLED Display

I’m adding an SSD1306 to an INA 219 - based sensor and I’m hitting a brick wall with compile errors.

I want to display the actual current (in Amps) from the sensor on my display. The INA219 is reporting just fine and the display works with a simple “Hello World” static string test.

I then modified the yaml to print the value for current on the display. Here’s the relevant chunk of code for that:

font:
  - file: "fonts/Kanit-Medium.ttf"
    id: OLED_font
    size: 12
  

# Read Vcc Rail and current
sensor:
  - platform: ina219
    address: 0x40
    shunt_resistance: 0.1 ohm
    current:
      id: Measured_Current
      name: "Current"
    power:
      name: "Power"
    bus_voltage:
      name: "Bus Voltage"
    max_voltage: 32.0V
    max_current: 3.2A


# Local current display
display:
  - platform: ssd1306_i2c
    model: "SSD1306 128x32"
    reset_pin: D0
    address: 0x3C
    lambda: |-
      // Print current value
      it.print(0, 0, id(OLED_font), "Amps: %.1f", id(Measured_Current).state);

The code validates fine, but I get the following errors when compiling:

src/main.cpp: In lambda function:
src/main.cpp:369:70: error: no matching function for call to 'esphome::display::DisplayBuffer::print(int, int, esphome::display::Font*&, const char [11], float&)'
       it.print(0, 0, OLED_font, "Amps: %.1f", Measured_Current->state);
                                                                      ^
src/main.cpp:369:70: note: candidates are:
In file included from src/esphome.h:3:0,
                 from src/main.cpp:3:
src/esphome/components/display/display_buffer.h:139:8: note: void esphome::display::DisplayBuffer::print(int, int, esphome::display::Font*, esphome::Color, esphome::display::TextAlign, const char*)
   void print(int x, int y, Font *font, Color color, TextAlign align, const char *text);
        ^
src/esphome/components/display/display_buffer.h:139:8: note:   candidate expects 6 arguments, 5 provided
src/esphome/components/display/display_buffer.h:149:8: note: void esphome::display::DisplayBuffer::print(int, int, esphome::display::Font*, esphome::Color, const char*)
   void print(int x, int y, Font *font, Color color, const char *text);
        ^
src/esphome/components/display/display_buffer.h:149:8: note:   no known conversion for argument 5 from 'float' to 'const char*'
src/esphome/components/display/display_buffer.h:159:8: note: void esphome::display::DisplayBuffer::print(int, int, esphome::display::Font*, esphome::display::TextAlign, const char*)
   void print(int x, int y, Font *font, TextAlign align, const char *text);
        ^
src/esphome/components/display/display_buffer.h:159:8: note:   no known conversion for argument 4 from 'const char [11]' to 'esphome::display::TextAlign'
src/esphome/components/display/display_buffer.h:168:8: note: void esphome::display::DisplayBuffer::print(int, int, esphome::display::Font*, const char*)
   void print(int x, int y, Font *font, const char *text);
        ^
src/esphome/components/display/display_buffer.h:168:8: note:   candidate expects 4 arguments, 5 provided
*** [/data/watchdog_sandbox/.pioenvs/watchdog_sandbox/src/main.cpp.o] Error 1

I feel like I am running around in circles with this one, can anyone suggest some possible debug ideas?

Just an idea, try lowercase for the id

oled_font not OLED_font

Thanks for the suggestion, but I got the same error.

To me, it seems the compiler trips over the “%.1f” for some reason, but I’m baffled as to why.

I had the same compiling error recently with my Oled display. In the end I just removed "Amps: %.1f" and used "Amps: %s"

It may be that the value you are printing is a string, not a float.

1 Like

You have to use printf instead of print for formated text with additional values.

So obvious, I think we all missed that!

I am an idiot. I missed that too. Works perfectly now with printf.

Thanks @nickrout and @danielw for pointing that out.

Now to go R the rest of the FM …

@danielw gets the credit.

1 Like