How to display more pages on 20x4 LCD

Hi to all, this is my firs post here :wink:
How to display more than 4 lines or one page on lcd_pcf8574?
I made this piece of code but I can’t insert delay between those two block of display. Result is that all is visible on LCD but too fast.

display:
  - platform: lcd_pcf8574
    dimensions: 20x4
    address: 0x27
    id: lcd
    lambda: |-
        it.printf(5, 1, "%.1f", id(tempindoor).state);
        it.printf(5, 3, "%.1f", id(moistindoor).state);
        it.print(0,0, "Temperatura unutra:");
        it.print(2,2, "Relativna vlaga:");
 
  - platform: lcd_pcf8574
    dimensions: 20x4
    address: 0x27
    id: lcd2
    lambda: |-
        it.printf(5, 1, "%.1f", id(absolutehumidity).state);
        it.printf(5, 3, "%.1f", id(dewpoint).state);
        it.print(0,0, "Apsolutna vlaga:");
        it.print(2,2, "Temp.kondenzacije:");

Take a look here

1 Like

I have looked there before posting here. Unfortunately it seems that Pcf8574 can’t use “pages” :frowning_face:

You only need the platform: lcd_pfcf8576 once, remove the second one and use the update_interval to show the pages the right number of seconds, for instance 3 seconds.
So change your code to:

display:
  - platform: lcd_pcf8574
    dimensions: 20x4
    address: 0x27
    id: lcd
    update_interval: 3s
    lambda: |-
        static bool page1 = true;

        if (page1 ) {
          it.printf(5, 1, "%.1f", id(tempindoor).state);
          it.printf(5, 3, "%.1f", id(moistindoor).state);
          it.print(0,0, "Temperatura unutra:");
          it.print(2,2, "Relativna vlaga:");
        } else {
          it.printf(5, 1, "%.1f", id(absolutehumidity).state);
          it.printf(5, 3, "%.1f", id(dewpoint).state);
          it.print(0,0, "Apsolutna vlaga:");
          it.print(2,2, "Temp.kondenzacije:");
        }
        page1 = !page1;
2 Likes

Thanks a lot @jsuanet ! It works like I want it to!
Where I can learn to code lambda like your example?

I’m happy for you it works and you want it.

That depends on your programming experience. Lambda’s are programmed in C++, so if you have experience with other program languages it is not so difficult, otherwise I could be a steep learning curve. There are a lot of example’s on the internet, so Google is your best friend. You can also find a lot of information in the ESPHome docs and sometimes looking at the ESPHome code on github can also be very helpful.

1 Like

Do you know how to get ° sign on display? It is easy to do in Arduino but in EspHome… :blush:

You need a font that has the degree symbol.

Here’s some code I use:

font:
  - file: 'fonts/GoogleSans-Medium.ttf'
    id: myfont
    size: 13
    glyphs:
      ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D',
       'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
       'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', ' ', 'a', 'b', 'c', 'd', 'e',
       'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
       't', 'u', 'v', 'w', 'x', 'y', 'z', '°', ':', '-']

display:
  - platform: ssd1306_i2c
    model: "SSD1306 128x64"
    reset_pin: GPIO16
    brightness: 0.1
    address: 0x3C
    lambda: |-
      it.line(0, 20, 127, 20);
      it.line(0, 63, 127, 63);
      it.line(0, 20, 0, 63);
      it.line(127, 20, 127, 63);

      it.print(13, 0, id(myfont), "- CV MONITOR -");

      it.printf(3, 29, id(myfont), "AANVOER:");
      it.printf(it.get_width() - 3, 21, id(myfont), TextAlign::TOP_RIGHT, "%.f°C", id(cv_aanvoer).state);

      it.printf(3, 43, id(myfont), "RETOUR:");
      it.printf(it.get_width() - 3, 35, id(myfont), TextAlign::TOP_RIGHT, "%.f°C", id(cv_retour).state);

      it.printf(3, 57, id(myfont), "ELGA PWR:");
      it.printf(it.get_width() - 3, 49, id(myfont), TextAlign::TOP_RIGHT, "%.fW", id(elga_vermogen).state);

How to use external fonts is explained here. The use of glyphs is entirely optional, it limits the characters you can use in return for a smaller binary file.

LCD display have only one font and it is burned in its firmware. You can’t use other font like in graphics displays.
In Arduino any character can be printed with simple chr(number) and display will show it.

Use a ~ for that :thermometer:

Oh duh, of course :frowning:

With the help of my friend Google I found this : ESPHome LCD Screen lcd_pcf8574 draw / print degree symbol · GitHub

So if your temperatue is in degrees Celsius, the line for tempindoor would be:

it.printf(5, 1, "%.1f %cC", id(tempindoor).state, 0xDF);
2 Likes

Thank again @jsuanet!

I always used

It worked perfectly since ever for me to get the degree symbol printed :tada:

Where you put ~ ? I tried but get - on display

Like that for example:

it.printf(0, "%.0f~C", id(tempindoor).state);

Dude, fantastic your help, I’ve been looking for this for a long time.
Let me abuse your goodwill!
Is there a way to implement more pages, three or even four, for example?

Again thank you very much for the support.

You can make as many pages as you want, if you change the structure a little bit, that would be something like this (not tested)

display:
  - platform: lcd_pcf8574
    dimensions: 20x4
    address: 0x27
    id: lcd
    update_interval: 3s
    lambda: |-
        static int current_page_num = 1;
        int number_of_pages = 4;

        switch (current_page_num) {

          case 1:
          it.print(0,0, "this is page 1 line 1");
          break;
          
          case 2:
          it.print(0,0, "this is page 2 line 1");
          break;

          case 3:
          it.print(0,0, "this is page 3 line 1");
          break;
          
          case 4:
          it.print(0,0, "this is page 4 line 1");
          break;

          default:
          break;         
        }
         
        current_page_num += 1;
        if (current_page_num > number_of_pages) {
          current_page_num = 1;
        }