Bitmap output from class field

Have you cracked open the library's source code yet as I suggested WAY back in Post #6??? It seems there there must be a difference in the data passed to the function.

Yes, I opened the source code of the library, but still can't figure out what's wrong

What did the serial debug prints that you put into the library code reveal?

Code:

void printBitmap(unsigned char arr[]) {
  for (int i = 0; i < 8; ++i) {
    Serial.println(arr[i], BIN);
  }
}

Result:

image

The bitmap is displayed correctly in serial

But, did you put that debug printing directly inside the library code?

I will try

I finally found a solution. All that had to be done was to remove the const from the field where the bitmap is stored

#ifndef SOMECLASS_H
#define SOMECLASS_H
#include <Adafruit_SSD1306.h>

class SomeClass {
  public:
    void drawBitmap(Adafruit_SSD1306* display) {
      display->drawBitmap(10, 10, bitmap, 8, 8, SSD1306_WHITE);
    }
    unsigned char bitmap[8] = {
      B11111111, 
      B10000001, 
      B10000001, 
      B10000001, 
      B10000001, 
      B10000001,  
      B10000001,  
      B11111111
};
};

#endif

Many thanks to everyone who responded

If it were my project, I'd dig in deeper to figure out why that is the case. As it is, you have a "solution" that you don't understand.

Here is the code for an overload of the drawBitmap() function that accepts a bitmap from RAM:

void Adafruit_GFX::drawBitmap(int16_t x, int16_t y, uint8_t *bitmap, int16_t w,
                              int16_t h, uint16_t color) {

  int16_t byteWidth = (w + 7) / 8; // Bitmap scanline pad = whole byte
  uint8_t b = 0;

  startWrite();
  for (int16_t j = 0; j < h; j++, y++) {
    for (int16_t i = 0; i < w; i++) {
      if (i & 7)
        b <<= 1;
      else
        b = bitmap[j * byteWidth + i / 8];
      if (b & 0x80)
        writePixel(x + i, y, color);
    }
  }
  endWrite();
}

Given that it has a non-const bitmap parameter, it expects a non-const bitmap to be passed. But why the bitmap is displayed incorrectly, if, at first glance, there is no editing of the bitmap, I cannot understand. I lack knowledge

If that were the case, you would have gotten a compiler warning at the very least. When compiling for some platforms it would have caused a compiler error. Do you have the IDE's compiler warnings set to "All".

Also, there's an overload that take a constant array that the compiler would have picket (Adafruit_GFX.h):

  void drawBitmap(int16_t x, int16_t y, const uint8_t bitmap[], int16_t w,
                  int16_t h, uint16_t color);

Maybe because of overloading with a const, the compiler was choosing the one you sent. But because this overload was expecting a bitmap from progmem, it outputted badly.
As for the warnings, if I'm not mistaken, I didn't get any.

Good point. That could make a difference when working with an AVR processor. This is a long thread, I'm not sure if you ever told us which Arduino board you're using.

Nano

So, an ATmega328. Your analysis was correct, nice. The pgm_read_byte() function really means something specific on an AVR processor like that. It's more or less nothing on an ARM or ESP.