How can I display custom icons from a .h file

I've been working on a weather station, using the ESP32, along with a MH-ET live 2.9" 296x128 e-paper display. I'm using openweathermap to get my data and I've successfully managed to display that on my screen, using the GxEPD2 library, together with U8g2_for_Adafruit_GFX so I can use different kinds of fonts.

Support for this display was added to the GxEPD2 library only recently. I've used the example sketch named "GxEPD2_MinimalExample" and set it up for the display named "GDEW029M06" for the ESP32.

My display is initialized with the following code:

void setup()
{
  display.init();
  //uint16_t bg = GxEPD_WHITE;              // These are declared outside of the setup
  //uint16_t fg = GxEPD_BLACK;
  u8g2Fonts.setFontMode(1);                 // use u8g2 transparent mode (this is default)
  u8g2Fonts.setFontDirection(0);            // left to right (this is default)
  u8g2Fonts.setForegroundColor(fg);         // apply Adafruit GFX color
  u8g2Fonts.setBackgroundColor(bg);         // apply Adafruit GFX color
  u8g2Fonts.begin(display);
  display.setRotation(3);
  u8g2Fonts.setFont(u8g2_font_9x18_mr);
}

After gathering my data, I can then use

u8g2Fonts.print("Type your text here");

to display that code on the e-paper screen.

Now I'm trying to use some icons to show the different weather types. I would like to do this, because it saves me from having to individually format every possible weather scenario to fit on the screen and because it looks much better.

I've included the following file (weathericons.h), which has the weather icons I need:

I've done the inclusion right, because the IDE does recognise the file, but I've not been able to display any of these icons on the e-paper display yet. That's where my question comes in.

How can I display the custom icons, stored in the weathericons.h file, on my e-paper display?

@thebattlecat,

I think the file your link points to contains copyrighted material. But I don't see any copyright notice.
Did you remove the copyright notice?
You can do that for your copy, but re-publish is then not allowed.

Unless you don't clarify the copyright situation, I can't help you.

Jean-Marc

Oh my apologies, I failed to notice that. I found the file on github here:

and it seems that it's licensed indeed, under the MIT license. I'll add the copyright notice in the code I'm using and I'll edit the pastebin

@thebattlecat, you are welcome. I will post my findings.

Wonderful, thank you kindly!

Did I implement the copyright notice correctly by the way? Just making sure it's all right ^^

@thebattlecat,

yes, I think your copyright notice is ok.

I see there is no copyright notice in the original file, therefore a link to the original file might be enough.

My findings are as follows:

The RoundBox_bits icon seems to be a normal in-memory bitmap of depth 1, but with reverse bit order.
You can draw it by buffered drawing:

  display.firstPage();
  do
  {
    display.fillScreen(GxEPD_WHITE);
    display.drawBitmap(0, 0, (uint8_t*) RoundBox_bits, 50, 50, GxEPD_BLACK);
  }
  while (display.nextPage());

or by direct drawing:

  display.drawImage((uint8_t*) RoundBox_bits, 0, 0, 50, 50, true); // invert

direct drawing has an artifact on the right, as width is not a multiple of 8.
On the rounded corners you can see that the bitorder is wrong for Adafruit_GFX and GxEPD2.

The other Icons have 6 header bytes that could be skipped.
But depth is 2 which is not supported by Adafruit_GFX and GxEPD2 for in-memory bitmaps.

You could analyze the ThingPulse code, to find out how to draw these icons. I don't have time for this.

Jean-Marc

Thank you kindly for helping me get my code to work. The image now shows up, but as you mentioned, the bitorder is wrong. I'll check how I can fix that.

This topic was automatically closed after 120 days. New replies are no longer allowed.