Issues Displaying Bitmap on 128x64 OLED with U8g2 Library

Hi everyone,

I'm using an ESP8266 with a 128x64 OLED display and the U8g2 library. Despite following the documentation, my bitmap isn't displaying correctly. Here's my setup:

  • Pins: SCL - GPIO 5 (D1), SDA - GPIO 4 (D2)
  • Code Snippet:
#include <Arduino.h>
#include <U8g2lib.h>

// Declarar el constructor para la pantalla OLED
U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ 14, /* data=*/ 12, /* reset=*/ U8X8_PIN_NONE);

// Array de la imagen del gato
const unsigned char epd_bitmap_images [] PROGMEM = {
  0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0xE0, 0x00, 
  0x80, 0x0F, 0x00, 0x00, 0xF0, 0x01, 0xC0, 0x3D, 0x00, 0x00, 0xBC, 0x03, 
  0xC0, 0x70, 0x00, 0x00, 0x0E, 0x03, 0x60, 0xE0, 0x00, 0x00, 0x07, 0x06, 
  0x60, 0xC0, 0x01, 0x80, 0x03, 0x06, 0x30, 0x80, 0x03, 0xC0, 0x01, 0x0C, 
  0x30, 0x00, 0x07, 0xE0, 0x00, 0x0C, 0x18, 0x00, 0x06, 0x60, 0x00, 0x18, 
  0x18, 0x00, 0x0C, 0x30, 0x00, 0x18, 0x18, 0x00, 0xFC, 0x3F, 0x00, 0x18, 
  0x0C, 0x00, 0xFC, 0x3F, 0x00, 0x30, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x30, 
  0x0C, 0x00, 0x00, 0x00, 0x00, 0x30, 0x06, 0x00, 0x00, 0x00, 0x00, 0x60, 
  0x06, 0x00, 0x00, 0x00, 0x00, 0x60, 0x06, 0x00, 0x00, 0x00, 0x00, 0x60, 
  0x06, 0x00, 0x00, 0x00, 0x00, 0x60, 0x06, 0x00, 0x00, 0x00, 0x00, 0x60, 
  0x06, 0x00, 0x00, 0x00, 0x00, 0x60, 0x03, 0xE0, 0x01, 0xC0, 0x03, 0xC0, 
  0x03, 0xE0, 0x03, 0xC0, 0x07, 0xC0, 0x03, 0x30, 0x03, 0x60, 0x06, 0xC0, 
  0x03, 0x70, 0x03, 0xE0, 0x06, 0xC0, 0x03, 0xE0, 0x03, 0xC0, 0x07, 0xC0, 
  0x03, 0xC0, 0x01, 0x80, 0x03, 0xC0, 0x03, 0x00, 0x00, 0x00, 0x00, 0xC0, 
  0x03, 0x00, 0xFC, 0x0F, 0x00, 0xC0, 0xC3, 0x03, 0xFC, 0x0F, 0xF0, 0xC0, 
  0x83, 0xFF, 0x18, 0xC6, 0xFF, 0xC0, 0x03, 0xFC, 0x37, 0xFB, 0x0F, 0xC0, 
  0x03, 0x00, 0xF7, 0x33, 0x00, 0xC0, 0xC3, 0x03, 0xE0, 0x01, 0xF0, 0xC0, 
  0xC6, 0x7F, 0xC0, 0x80, 0xFF, 0x60, 0x06, 0xFC, 0xC7, 0xF8, 0x0F, 0x60, 
  0x0E, 0x80, 0xC7, 0x78, 0x00, 0x70, 0x0C, 0x00, 0xC0, 0x00, 0x00, 0x30, 
  0x1C, 0x00, 0xC0, 0x00, 0x00, 0x38, 0x38, 0x00, 0xC0, 0x00, 0x00, 0x1C, 
  0x70, 0x00, 0x40, 0x00, 0x00, 0x0E, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x07, 
  0xC0, 0x03, 0x00, 0x00, 0xC0, 0x03, 0x00, 0x0F, 0x00, 0x00, 0xF0, 0x00, 
  0x00, 0x7E, 0x00, 0x00, 0x7E, 0x00, 0x00, 0xF8, 0x0F, 0xF0, 0x0F, 0x00, 
  0x00, 0xC0, 0xFF, 0xFF, 0x03, 0x00, 0x00, 0x00, 0xF0, 0x0F, 0x00, 0x00, 
};

void setup(void) {
  u8g2.begin();
}

void loop(void) {
  u8g2.clearBuffer();					// Limpiar el buffer de la pantalla
  u8g2.drawXBMP(0, 0, 128, 64, epd_bitmap_images); // Dibujar la imagen en la pantalla
  u8g2.sendBuffer();					// Enviar el buffer a la pantalla
  delay(1000);  
}

Despite this, the image appears corrupted. Any advice on what might be wrong? Thanks!

********EDIT ************

I was able to resolve the issue, it was my stupidity, i had the wrong settings on the image2cpp....

The canvas size I selected did not match my actual size.

Your bitmat is not 128 x 64 bits, it is 96 x 24.

    OLED.drawXBMP(0, 0, 96, 24, epd_bitmap_water_level);

< edit >
Now that I look a bit more, its more likely 48 x 48, but only you know what the original bitmap looks like.

    OLED.drawXBMP(0, 0, 48, 48, epd_bitmap_water_level);

According to vendor its supposed to be a 128x64 :frowning:

Trying with the resolutions you recommended did not work either though

The display is 128x64, the size I am referring to is the bitmap itself, which is 48x48 pixels.

Ohhh, well, that was it then, thanks a lot :slight_smile:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.