Display percent

HI,

I’m using lcd_pcf8574 and I would like to display a progress in %

display:
  - platform: lcd_pcf8574
    dimensions: 20x4

I’m experimenting two “challenges”

  1. I’m not able to display % symbols (I think because % char requires some kind of escape char)
    it.printf(19, 0, "%");

  2. When I display the progress I would like to keep the digit close to the right, but as it goes from 0 to 100, I will have some space between the start position and the % char

0  %
10 %
100%

how I can align the digit to the right based of the range (0-9,10-99,100)?

regards

Did you add the glyphs?
Display Component — ESPHome

It should be there by default but perhaps you have a different list that does not include it?

Thank you @Hellis81, I didn’t. There is a way to add it without define the font?

Don’t know for sure.

from reading the linked page, %7 alaigns the test to the right, but, i dont know where that would be entered, maybe like this?

it.printf(%7 19, 0, "%");

Try:

it.printf(19, 0, TextAlign::TOP_RIGHT, "%%");

@zoogara , I still get an error

/config/esphome/sprinkler.yaml: In lambda function:
/config/esphome/sprinkler.yaml:50:52: error: invalid conversion from 'int' to 'const char*' [-fpermissive]
           it.printf(19, 0, TextAlign::TOP_RIGHT, "%%");
                                                    ^
In file included from src/esphome.h:35:0,
                 from src/main.cpp:3:
src/esphome/components/lcd_base/lcd_display.h:44:8: note:   initializing argument 1 of 'void esphome::lcd_base::LCDDisplay::printf(const char*, ...)'
   void printf(const char *format, ...) __attribute__((format(printf, 2, 3)));

Bummer - its still looks like it’s treating it as a formatting string. That’s what I get for not testing.

Try this:

it.printf(19, 0, TextAlign::TOP_RIGHT, "%s", "%");

i didn’t but no improvements :frowning:

/config/esphome/sprinkler.yaml: In lambda function:
/config/esphome/sprinkler.yaml:58:57: error: invalid conversion from 'int' to 'const char*' [-fpermissive]
           it.printf(19, 0, TextAlign::TOP_RIGHT, "%s", "%");
                                                         ^
In file included from src/esphome.h:35:0,
                 from src/main.cpp:3:
src/esphome/components/lcd_base/lcd_display.h:44:8: note:   initializing argument 1 of 'void esphome::lcd_base::LCDDisplay::printf(const char*, ...)'
   void printf(const char *format, ...) __attribute__((format(printf, 2, 3)));
        ^
*** [/data/sprinkler/.pioenvs/sprinkler/src/main.cpp.o] Error 1

Apologies - I tested another format and it worked, then I assumed this would work as well.

I tested various formats and I cannot get any printf statement to compile formatted like yours - In all case I need to include the font pointer.

e.g this works:

          it.printf(120, 10, id(calibri_25), TextAlign::TOP_RIGHT, "%s %%", "");

Produces:

%

As does this:

          it.printf(120, 10, id(calibri_25), TextAlign::TOP_RIGHT, "%3i%%", y);

Where y is an integer variable with value 100 it produces

100%

So have a play with a font included and including your value in the printf statement.

@zoogara thank you so much
I was able to make iyt working with

it.printf(18, 0,  "%s%%", "");

I’m not able to use the font, it can be because LCD display can’t use fonts?

1 Like

Ah - I was using a graphics lcd - which is why mine insisted I use a font. Glad you got it working.