Sensor values from the DHT22 on OLED display

Hello, I’m desperate!

I’ve tried and learned so many things now.
I have an Oled display ssd1351 on an ESP32, which also runs. I also see a DHT22 and its values.

How do I get this sensor data on the display?

I suspect the sensor outputs need to be converted to float. But no matter what I try, it doesn’t work.

captive_portal:

sensor:

  - platform: dht

    model: DHT22

    pin: GPIO26

    temperature:

      id: "temp"

      name: "dhttemp"

#    update_interval: 5s

spi:

  clk_pin: GPIO18

  mosi_pin: GPIO23

color:

  - id: farbe

    red: 3%

    green: 100%

    blue: 5%

font:

  - file: "gfonts://Roboto"

    id: form

    size: 20

display:

  - platform: ssd1351_spi

    model: "SSD1351 128x128"

    reset_pin: GPIO0

    cs_pin: GPIO5

    dc_pin: GPIO15

    lambda: |-

      it.printf(10, 10, id(farbe), id(temp).state);

#      it.print(20, 10, id(form), id(farbe), "!!TEST!!");

#      it.rectangle(0,  0, it.get_width(), it.get_height(), id(farbe));

output

/config/esphome/esphome-web-916f2c.yaml: In lambda function:
/config/esphome/esphome-web-916f2c.yaml:63:43: error: no matching function for call to 'esphome::display::Display::printf(int, int, esphome::Color&, float&)'
       it.printf(10, 10, id(farbe), id(temp).state);
                                           ^
In file included from src/esphome.h:18,
                 from src/main.cpp:3:
src/esphome/components/display/display.h:256:8: note: candidate: 'void esphome::display::Display::printf(int, int, esphome::display::BaseFont*, esphome::Color, esphome::display::TextAlign, const char*, ...)'
   void printf(int x, int y, BaseFont *font, Color color, TextAlign align, const char *format, ...)
        ^~~~~~
src/esphome/components/display/display.h:256:8: note:   candidate expects 6 arguments, 4 provided
src/esphome/components/display/display.h:268:8: note: candidate: 'void esphome::display::Display::printf(int, int, esphome::display::BaseFont*, esphome::Color, const char*, ...)'
   void printf(int x, int y, BaseFont *font, Color color, const char *format, ...) __attribute__((format(printf, 6, 7)));
        ^~~~~~
src/esphome/components/display/display.h:268:8: note:   candidate expects 5 arguments, 4 provided
src/esphome/components/display/display.h:279:8: note: candidate: 'void esphome::display::Display::printf(int, int, esphome::display::BaseFont*, esphome::display::TextAlign, const char*, ...)'
   void printf(int x, int y, BaseFont *font, TextAlign align, const char *format, ...)
        ^~~~~~
src/esphome/components/display/display.h:279:8: note:   candidate expects 5 arguments, 4 provided
src/esphome/components/display/display.h:290:8: note: candidate: 'void esphome::display::Display::printf(int, int, esphome::display::BaseFont*, const char*, ...)'
   void printf(int x, int y, BaseFont *font, const char *format, ...) __attribute__((format(printf, 5, 6)));
        ^~~~~~
src/esphome/components/display/display.h:290:8: note:   no known conversion for argument 3 from 'esphome::Color' to 'esphome::display::BaseFont*'
*** [.pioenvs/esphome-web-916f2c/src/main.cpp.o] Error 1

The error message is telling you that the font is mandatory. Also if you use it.printf a format is required - otherwise use it.print e.g:

      it.print(10, 10, id(form), id(farbe), id(temp).state);

Hello

it.print(10, 10, id(shape), id(color), id(temp).state);

brings no success.
What would formatting look like?

No matter what I test or copy, it just doesn’t work to show the sensor output of the DHT22 directly on the SSD1351.

Your original yaml doesn’t have a font called shape, I assume you have added one?

What is the error message now?

      it.printf(10, 10, id(form), id(farbe), "%f °C", id(temp).state); 

And I haven’t used color the way you have - I define them in lambda so I am not 100% sure the way you are doing works. For example:

      auto farbe = Color(7, 255, 12);
      it.printf(10, 10, id(form), farbe, "%f °C", id(temp).state); 

The way you are doing it may work however - just haven’t tried it myself.

es läuft, es läuft, es läuft!!!

it.printf(10, 10, id(form), id(farbe), "%f °C", id(temp).state);

You are my hero!
Man man man…

The display now shows 23,00000°C.
Do you perhaps have a quick command for rounding to “0” decimal places?

Have a read about formatting in printf:

And something like:

it.printf(10, 10, id(form), id(farbe), "%.0f °C", id(temp).state);

Thanks,

good page. I will make.

There is simply too much being offered as “the solution” online. And at some point you get lost.

Thanks for your help.