Access 2D Array using PROGMEM: Compiling error in void loop

Hello Folks,

I am quite new in the field of Arduino and hope to get some help from you professionals in the field of programming using PROGMEM. That is my goal: I want to program a sequential light (mini-movie) using a 10x10 LED-matrix. Therefore I use a lot of binary 10x10 arrays like this:

const byte j1[10][10] PROGMEM = {
  {0, 0, 0, 1, 1, 1, 1, 0, 0, 0},
  {0, 0, 1, 0, 0, 0, 0, 1, 0, 0},
  {0, 1, 0, 0, 0, 0, 0, 0, 1, 0},
  {1, 0, 0, 1, 0, 0, 1, 0, 0, 1},
  {1, 0, 0, 0, 0, 0, 0, 0, 0, 1},
  {1, 0, 1, 0, 0, 0, 0, 1, 0, 1},
  {1, 0, 0, 1, 1, 1, 1, 0, 0, 1},
  {0, 1, 0, 0, 0, 0, 0, 0, 1, 0},
  {0, 0, 1, 0, 0, 0, 0, 1, 0, 0},
  {0, 0, 0, 1, 1, 1, 1, 0, 0, 0},
};

For this mini-movie I need something about 200 frames, means j1 to j200, each 10x10 arrays. That is why I need to use flash-memory instead of RAM. Using the Atmega328P-PU of the Arduino, the following code works:

#include <avr/pgmspace.h>
const byte j1[10][10] PROGMEM = {{0,0,0,1,1,1,1,0,0,0}, {1,1,0,1,1,1,1,0,0,0}, ...
const byte j2... //and so on


void loop() {
led_10x10(j1); //using millis() for the illumination-time for each frame, dosen't matter here... 
led_10x10(j2)... //and so on

}

void led_10x10(byte matrix[10][10]) { //subfunction for led actuation
//some for-loops for multiplex , important part is this:
digitalWrite(z, pgm_read_byte( &matrix[i_z][i_s]) ); //z=number of current row; i_z, i_s are continuous variables
}

Now you might thinking: Why do I ask you although the quoted code works? The thing is, that I have to use a DIP40 Atmega324PA, because the DIP28 328PU has not enough pins. Therefore I use the Arduino as ISP using Mighty-Core bootloader for the 324PA. That works fine. However: The compiling of the code above doesn't work anymore. The error:

exit status 1
invalid conversion from 'const byte ()[10] {aka const unsigned char ()[10]}' to 'byte ()[10] {aka unsigned char ()[10]}' [-fpermissive]

The same error occurs with the 328PU using the arduino version 1.6.11 and older. Version 1.6.12 to 1.6.17 works fine. I really think the main problem has something to do with the middle part in void loop. I guess this syntax is not correct... I also tried to use Flash5 but i doesnt work at all. Reading a lot of threads concerning PROGMEM & arrays and their access in the main code didn't help either.

Please, can you help?

Please, can you help?

The error message also told you exactly which line it didn't like. You can use an explicit cast to get around the problem.

I'd show you how, but I don't know which line the compiler doesn't like, and I don't have any of the versions of the IDE installed that you mention.

On closer examination, it appears that you don't know what you are doing. The array that you are passing to the function is NOT of type byte[][].

Hello Paul, thank you for your reply.

Sorry, I forgot to tell the line. It is exactly the line with the function led_10x10 as you can see here:

I use the standard arduino-software IDE version 1.8.1. Maybe my last post was not accurate. The "version" I told have to be installed via the board-manager. 1.6.17 is the newest AVR-Boards Arduino version, which works with the code. Using 1.6.11 and older with Atmega328P-PU results to the same error as using MightyCore with the Atmega324PA.

On closer examination, it appears that you don't know what you are doing

Unfortunately, our are right :confused:
I know how to code some loops and simple algorithms. But this part with different storages/declarations/adresses etc. are very new for me...

Therefore I need some help and I would be very happy if we could solve the problem anyway...

led_10x10(j1);

Here, you call the function. You KNOW what type you are passing to the function, because you are the one that defined the variable being passed:

const byte j1[10][10] PROGMEM =...

So, it is not difficult to declare the function properly:

void led_10x10(const byte matrix[10][10] PROGMEM)

At least, that's what I'd try.

HANDS UP!
It works! Thank you very much PaulS!!

dotwinx:
HANDS UP!
It works! Thank you very much PaulS!!

I know it's been a long time but you could map each 10x10 byte array to 10 ints (as 10 rows of 10 bits) to keep it simple (13 bytes to not). You would be able to store 5+ times as many frames in the same space.