Buffer and PROGMEM

Hello, I'm working with an 128x64 LCD screen and am using the Adafruit library Adafruit_SSD1306

In the code, it initialized the screen with the Adafruit splash screen. It's a pretty hefty burden on memory, but I like having this on start up. Below is how the byte array is stored in the library:

static uint8_t buffer[SSD1306_LCDHEIGHT * SSD1306_LCDWIDTH / 8] = { 
0x00, 0x00, Blah Blah lots of Hex codes,  0x00
};

void Adafruit_SSD1306::display(void) {

    for (uint16_t i=0; i<(SSD1306_LCDWIDTH*SSD1306_LCDHEIGHT/8); i++) {
      fastSPIwrite(buffer[i]);
      //ssd1306_data(buffer[i]);
    }
}

My question is, can the byte array of the buffer, all those bytes, be moved into PROGMEM for better storage? Would this at all save dynamic memory?

I tried using

const uint8_t intro[SSD1306_LCDHEIGHT * SSD1306_LCDWIDTH / 8] PROGMEM = { 0x00 etc};
static uint8_t buffer[SSD1306_LCDHEIGHT * SSD1306_LCDWIDTH / 8] = {intro};

but it didn't save any memory at all. It's also giving me an "invalid conversion" warning

TGGeko:
Hello, I'm working with an 128x64 LCD screen and am using the Adafruit library Adafruit_SSD1306

In the code, it initialized the screen with the Adafruit splash screen. It's a pretty hefty burden on memory, but I like having this on start up. Below is how the byte array is stored in the library:

Here's a snippet from a program of mine. This is an array of infrared remote codes stored in PROGMEM, but it will show you how to do it for any other type of data:

///////////////////////////////////////////////////////////////////////////////
// Sony camera shutter release code 0xB4B8F (focus and shoot)
///////////////////////////////////////////////////////////////////////////////
static const uint16_t shutter[] PROGMEM = {
    // header
    0x8060, 0x0018,
    // data
    0x8030, 0x0018, 0x8018, 0x0018, 0x8030, 0x0018, 0x8030, 0x0018, // B
    0x8018, 0x0018, 0x8030, 0x0018, 0x8018, 0x0018, 0x8018, 0x0018, // 4
    0x8030, 0x0018, 0x8018, 0x0018, 0x8030, 0x0018, 0x8030, 0x0018, // B
    0x8030, 0x0018, 0x8018, 0x0018, 0x8018, 0x0018, 0x8018, 0x0018, // 8
    0x8030, 0x0018, 0x8030, 0x0018, 0x8030, 0x0018, 0x8030, 0x01C8, // F
    // end of data block
    0x0000
};

Note that I am storing UINT16_T values, whereas you need UINT8_T... just change it.

Also note that you will have to read this data using "pgm_read_byte (pointer + index)" instead of just accessing the array directly as you do from SRAM:

uint8_t array_size = sizeof (array) / sizeof (*array); // uint16_t if array > 255 elements
uint8_t index; // uint16_t if array > 255 elements
uint16_t data; // same type as data in array

for (index = 0; index < array_size; index++) {
    data = pgm_read_word(array + index); // pgm_read_byte for 8 bit data!
    // send data wherever
}

Hope this helps.

You cannot put buffer into progmem. It is not constant - every method to change what is shown on the display makes changes to it.

DrAzzy:
You cannot put buffer into progmem. It is not constant - every method to change what is shown on the display makes changes to it.

Right, I figured that bit out. I was wondering if theres a way to write the splash screen data to PROGMEM then move it to the buffer when needed and save memory.

I tried that in the second code at top, but it used up just as much dynamic memory.