Garbled bitmap on sh1106 display

Hi everyone, I am having a bit of trouble drawing a bitmap on a 128x64 sh1106 display. I am using with the Adafruit gfx library and the SH1106 Adafruit compatible library. I am trying to display a cross which is 7x6 pixels. I used the image2cpp utility online, but the display only shows giberish in the 7x6 area where the bitmap should be. The code for this is quite long since it is part of a large project, but everything else displays correctly on the display, only the bitmap doesn't work. I have included the code relevant to drawing the bitmap below.

I declare the bitmap like this:

static const unsigned char cross [] PROGMEM = {
  0xbb, 0xaf, 0xbe, 0xbb, 0xb7, 0x7
};

Then I initialize the display, do other things, and try to draw the bitmap.

display.drawBitmap(17, 56, cross, 7, 6, WHITE); //draw cross at x=17 y=56

Does anyone have an idea why the image doesn't display correctly? Thanks!

Go on. Write your data as a sequence of binary constants. One on each line.

The image does not look like a cross to me. Edit the values to match the shape that you want displayed. Try it.

I am not at a PC. From memory, the GFX drawBitmap() methods are aligned on 8-bit boundaries. e.g. a 7x6 will use 6 bytes. A 8x6 will use 6 bytes. A 4x6 will use 6 bytes.

FreeFonts are packed as bits. Very difficult to edit by hand. e.g. a 5x6 = 30 bits = 4 bytes.

David.

david_prentice: Go on. Write your data as a sequence of binary constants. One on each line.

The image does not look like a cross to me. Edit the values to match the shape that you want displayed. Try it.

I am not at a PC. From memory, the GFX drawBitmap() methods are aligned on 8-bit boundaries. e.g. a 7x6 will use 6 bytes. A 8x6 will use 6 bytes. A 4x6 will use 6 bytes.

FreeFonts are packed as bits. Very difficult to edit by hand. e.g. a 5x6 = 30 bits = 4 bytes.

David.

Yeah, the image is actually a X, not really a cross. In the past, I have manually typed the binary in to display a bitmap, but I cant remember how to format the binary . Thanks for the help though!

Here is an example of how to write a bitmap by hand.

#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;

#define BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF

static const unsigned char cross [] PROGMEM = {
    0xbb, 0xaf, 0xbe, 0xbb, 0xb7, 0x7
};

static const unsigned char EXX [] PROGMEM = {
    0b10000010,
    0b01000100,
    0b00101000,
    0b00101000,
    0b01000100,
    0b10000010,
};

void setup()
{
    uint16_t ID = tft.readID();
    tft.begin(ID);
    tft.fillScreen(BLACK);
    tft.drawBitmap(17, 56, cross, 7, 6, WHITE); //draw cross at x=17 y=56
    tft.drawBitmap(17, 26, EXX, 7, 6, WHITE); //draw cross at x=17 y=56
}

void loop()
{
}

Ok, that is written for a TFT. But it uses the same GFX methods.

David.

Wow, than you so much for that! Sorry for the very late reply, I had kinda given up on drawing the bitmap. Using the method you use to do the manual binary bitmap works great! It is quite weird becuase I made another image that was bigger at 64x64 pixels to test with, and using the image2cpp tool worked fine, and the image displayed. It seems like the image2cpp tool just doesn't work for me on small images. Either way, thank you very much!