How read array[] PROGMEM [SOLVED]

Hi, this is my first post, so be nice!

I’ve built an 40x8 led matrix using an Arduino Uno and some shift registers. The code works like a charm until i declare too many characters since the SRAM is pretty small. I figure i want to use PROGMEM for my character declarations, which is something i’ve never done before. I’ve been reading this post: http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=38003&postdays=0&postorder=asc about the subject, but they don’t use any examples simple enough for me (stupid :frowning: ). My problem is that i don’t know how to do a loop-search (is that the right term?) when storing in flash mem. I would very much appreciate if someone could help me with this!

My code:

#include <avr/pgmspace.h> 

const char A[8][8] PROGMEM = 
{
  {0,0,0,0,0,0,0,0},
  {0,0,0,1,1,0,0,0},
  {0,0,1,1,1,1,0,0},
  {0,1,1,0,0,1,1,0},
  {0,1,1,0,0,1,1,0},
  {0,1,1,1,1,1,1,0},
  {0,1,1,0,0,1,1,0},
  {0,1,1,0,0,1,1,0}
}; 

void loop()
{
    char msg[] = "AAA";
    //shitload of code//
    char ch = msg[sign]; //sign is the variable that select character
    switch (ch)
    {
       case 'A' :
          {
            if(A[t][place] == 1) // t and place select row and column
            {
              colSetHigh(); 
            }
            else
            {
              colSetLow();
            }
            break;
          }
}

So in the switch-case, what should i do to be able to loop through the A-matrix?

regards Klas

Declaring a byte to hold a single bit of data is extremely wasteful
You may find you have sufficient RAM anyway, if you reduce your RAM usage eight-fold.

I've changed all char to byte (if that's what you meant), but i still exceeds the SRAM alot, so i'd love some help on how to read from a PROGMEM declared array (datatype char or byte).

've changed all char to byte (if that's what you meant)

A char and a byte are both eight bits, so now, that's not what I meant.
I meant that you're wasting seven out of every eight bits, by not using them

Okay my misstake. But since 8-bit is the smallest type of data storage, and i really would like to declare characters that way because it's easy to change and for good servey, is their a better way for me to solve the SRAM-exceed-issue?

The attached code should cover the basics of what your wanting to do. It’s for the Rainbowduino so won’t work for shift registers but it shows how to store bit packed font data and a text string in PROGMEM and how to get the info out for display on an 8x8 matrix. The font also contains kerning information so you don’t get huge gaps when displaying something like !!!

ScrollTest3.ino (13.8 KB)

Riva:
The attached code should cover the basics of what your wanting to do. It’s for the Rainbowduino so won’t work for shift registers but it shows how to store bit packed font data and a text string in PROGMEM and how to get the info out for display on an 8x8 matrix. The font also contains kerning information so you don’t get huge gaps when displaying something like !!!

Thanks for the answer Riva!

i finally solved it modifying my code like this:

#include <avr/pgmspace.h> 

byte A[8][8] PROGMEM = 
{
  {0,0,0,0,0,0,0,0},
  {0,0,0,1,1,0,0,0},
  {0,0,1,1,1,1,0,0},
  {0,1,1,0,0,1,1,0},
  {0,1,1,0,0,1,1,0},
  {0,1,1,1,1,1,1,0},
  {0,1,1,0,0,1,1,0},
  {0,1,1,0,0,1,1,0}
}; 

void loop()
{
    char msg[] = "AAA";
    //shitload of code//
    char ch = msg[sign]; //sign is the variable that select character
    switch (ch)
    {
       case 'A' :
        {
          byte buffer = pgm_read_byte(&(A[t][place]));
          if(buffer == 1)
          {
            colSetHigh();
          }
          else
          {
            colSetLow();
          }
          break;
        }
}

I’m aware of that it’s not the best solution if small space is desired, but i want the code to be easily understood and modified by me and others.
The code above doesn’t make any sense since alot of for-loops are missing, but this was the solution for my probem.

Glad you got the code working to your satisfaction though as AWOL has pointed out your wasting a lot of memory defining the character data. Taking your example...

byte A[8][8] PROGMEM = 
{
  {0,0,0,0,0,0,0,0},
  {0,0,0,1,1,0,0,0},
  {0,0,1,1,1,1,0,0},
  {0,1,1,0,0,1,1,0},
  {0,1,1,0,0,1,1,0},
  {0,1,1,1,1,1,1,0},
  {0,1,1,0,0,1,1,0},
  {0,1,1,0,0,1,1,0}
};

uses 64 bytes of memory buy you can easily reduce this eight fold and still make it readable by doing this...

byte A[] PROGMEM = 
{
  B00000000,
  B00011000,
  B00111100,
  B01100110,
  B01100110,
  B01111110,
  B01100110,
  B01100110
};

Another big saving will be had by creating the entire character table as one array and indexing into it instead of separate arrays and having to duplicate switch/case code for all characters.