Accessing an array in PROGMEM

Hello,

I was thinking to use the array as well, because I have a small aniimation of several pictures going on, and I would like to speed up the reading... so, the idea was to use the simple array to and go thru quicker, however, this is obviously not possible to do with the PROGMEM, any other ides how to approach this? I have around 10 monochrome pictures that I am playing... wondering what would be best way to manipulate that ...

Thanks in advance!

it's not obvious that you have been able to read the array in order to measure how "quick" it can be accessed

consider

const uint16_t icon[] PROGMEM = { 0x0123, 0x4567, 0x89AB, 0xdead, 0xbeef, };

void setup() {
  Serial.begin(9600);

  for (byte k = 0; k < 5; k++)
    Serial.println (pgm_read_word_near (& icon [k]) , HEX);
}

void loop() {
}

Your problem is more likely caused by the speed at which the display can be updated, and not the slight additional time it takes to read PROGMEM vs ram. We need a lot more information, such as the type display and the actual code, to get an idea what the problem is.

Your problem is unrelated to the OP's problem, that was caused by not properly accessing the PROGMEM.

Thanks for your reply.

Let me share you what I am doing:

const unsigned char epd_bitmap_frame_00_delay_0 [] PROGMEM = { ... 
const unsigned char epd_bitmap_frame_01_delay_0 [] PROGMEM = { ...
const unsigned char epd_bitmap_frame_03_delay_0 [] PROGMEM = { ...

// and so on ... till 20 or someting.

Afterwards, these "frames" are simply read out with the gfx_library

// pass number of loops, max 3
void testAni() {
  display.clearDisplay();
  display.drawBitmap(0, 0, epd_bitmap_frame_00_delay_0, 128, 64, WHITE);

  display.display();
display.clearDisplay();
  display.drawBitmap(0, 0, epd_bitmap_frame_01_delay_0, 128, 64, WHITE);

  display.display();

//and so on

I am using a simple Adafruit gfx lib and the #include <Adafruit_SSD1306.h> display driver ...

Will have a go with the above example of reading the frames, it will be at least easier to manipulate the code...

Best.

if you need to pass the data from your array in progmem to a function that expects the argument data to be in RAM, the code needs to first copy the data from the array value(s) from progmem to ram variable(s) and pass the ram variable to the sub-function

What frame rate are you trying to achieve?
Is your display using I2C or SPI? Definitely do not use the software implementation of either.

There are overloaded versions of drawBitmap(). If the array is declared const the data is assumed to be in PROGMEM, if not const the array is assumed to be in ram.
Copying the data from PROGMEM to ram, then displaying from ram, is unlikely to speed things up, and will likely be slightly slower, than letting the library read directly from PROGMEM.
< edit >
You may be able to speed things up a bit by eliminating the clearDisplay() and instead copying directly from PROGMEM to the display buffer (you can get the location of the buffer with getBuffer() ), bypassing the displayBitmap function entirely.

@mu234

Topic split from another topic. Please do not add your own questions to the end of other people's topics.

Could you take a few moments to Learn How To Use The Forum

It will help you get the best out of the forum in the future.

Thank you.

Sorry and thank you for the split!

Best.

Thanks for this info, but I cannot get it to work, let me show you what I am doing.
I have 24 of such frames, stored into progmem:

const unsigned char epd_bitmap_frame_00_delay_0 [] PROGMEM = {
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x18, 0x18, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x08, 0x10, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x08, 0x10, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x08, 0x10, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x08, 0x10, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x08, 0x10, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3a, 0x08, 0x10, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, 0x08, 0x10, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0x08, 0x10, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0x08, 0x10, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0x08, 0x10, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0x08, 0x10, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0x08, 0x10, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0x08, 0x10, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0x00, 0x00, 0x41, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0x00, 0x00, 0x46, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0x00, 0x00, 0x4c, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x48, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x70, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x60, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x40, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x03, 0xc0, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x0c, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x18, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x20, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x20, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x20, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

Indeed there is 24 of those frames ... and then the idea is to "print" them out, like you have suggested? But first the array is created-which is where I gett the first warning!

/Users/imac/Documents/Arduino/At_Tiny_3216/Display_Project_QT_2/animated_pic.ino:2143:1: warning: invalid conversion from 'const unsigned char*' to 'unsigned char' [-fpermissive]

Anyway, the array is created like that, not sure what is there a problem with converting the file? In adition, you have suggested to use the uint16?

const unsigned char icons[24] = {
  epd_bitmap_frame_00_delay_0,
  epd_bitmap_frame_01_delay_0,
  epd_bitmap_frame_02_delay_0,
...
};

So, should the frames be stored as "uint6_t" rather than "unsigned char" as it is now? BTW this compiles, however, this is not compiling:

  for (byte k = 0; k < 5; k++){
    Serial.println(k);
    Serial.println(" ");
    Serial.println (pgm_read_word_near(&icons[k]), HEX);
  }

namely the error is in the Serial.println (pgm_read_word_near(&icons[k]), HEX);
the error is supposed to be in not declared array named icons which is strange?

...

'icons' was not declared in this scope
java.lang.NoSuchMethodError: accessibilityHitTest

...

Am I declaring the array not properly ?

Best.

this is a common warning. the warning is on line 2143 of the code? can you post that code?

Here you go?

const unsigned char icons[24] = {
  epd_bitmap_frame_00_delay_0,
  epd_bitmap_frame_01_delay_0,
  epd_bitmap_frame_02_delay_0,
  epd_bitmap_frame_03_delay_0,
  epd_bitmap_frame_04_delay_0,
  epd_bitmap_frame_05_delay_0,
  epd_bitmap_frame_06_delay_0,
  epd_bitmap_frame_07_delay_0,
  epd_bitmap_frame_08_delay_0,
  epd_bitmap_frame_09_delay_0,
  epd_bitmap_frame_10_delay_0,
  epd_bitmap_frame_11_delay_0,
  epd_bitmap_frame_12_delay_0,
  epd_bitmap_frame_13_delay_0,
  epd_bitmap_frame_14_delay_0,
  epd_bitmap_frame_15_delay_0,
  epd_bitmap_frame_16_delay_0,
  epd_bitmap_frame_17_delay_0,
  epd_bitmap_frame_18_delay_0,
  epd_bitmap_frame_19_delay_0,
  epd_bitmap_frame_20_delay_0,
  epd_bitmap_frame_21_delay_0,
  epd_bitmap_frame_22_delay_0,
  epd_bitmap_frame_23_delay_0,
};

OK, it seems that the comma was too much, anyway, the array is still not found :grey_question:

You need to declare icons as const, and change it to an array of pointers to other arrays.

const unsigned char*  const icons[24] = {

< edit >
Declaring icons as const is not necessary, I was thinking you wanted to store the array of pointers in PROGMEM, but non-const is ok in ram.

have you tried removing the "const"?

where is that error?

It does not matter, both compile, if it is used in this way:

const unsigned char* icons[24] = { ...

or

const unsigned char* const icons[24] = { ...

BUT

if this is used within the main loop it does not compile:

for (byte k = 0; k < 5; k++){
    Serial.println(k);
    Serial.println(" ");
    Serial.println(pgm_read_word_near(&icons[k]), HEX);
  }

either with const or no const. The error :grey_question:

exit status 1
'icons' was not declared in this scope

while, if I am using the table :grey_question:

const PROGMEM byte table[] = {
  2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, ...

this can be easily used, for example:

analogWrite(ledPin, pgm_read_byte(&table[brightness]));

Wondering what is the problem?

Alrighty, I have found the problem, the point is in fact that the whole PROGMEM data must be before the setup(); For example , I had that code in a separate windows in Arduino...

So, how to organise this, I have quite a lot of code, hence I have put this away. So, how to make the Arduino IDE read the code properly?

Anyway, although the code of storing the pics into the PROGMEM now compiles ,
I am still stuck here:

void loop() {   
  for (byte k = 0; k < 5; k++){
    Serial.println(k);
    Serial.println(" ");
    //Serial.println(pgm_read_byte(&table[k]));
    Serial.println(pgm_read_word_near(&icons[k]));
  }
}

pgm_read does not want to compile and here is the error:

exit status 1
Error compiling for board ATtiny3226/3216/1626/1616/1606/826/816/806/426/416/406.

Best.

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