Go Down

Topic: Extending RGBMatrix.cpp for the SparkFun RGB Matrix with backpack. (Read 1 time) previous topic - next topic

YeahNo

Hi.

I've been working on a project that uses an Uno, the Arduino Ethernet board and a SparkFun 8 x 8 RGB Matrix with serial backpack.

Didn't take me long to figure out that the RGB.h file only contains A-Z, no numbers, no common punctuation.  So I went about the business of adding those characters.

Two hours later, I'd bashed a flat spot on my forehead - my program didn't work and it was because of the additional SRAM storage required by those characters.  When I removed them, everything was fine. 

That led me to using PROGMEM, but my programming skills are somewhat limited and I could use a little help, which is what brings me here.

That said, here's the issue:

RGBMatrix.cpp contains:

Code: [Select]
extern const char letters[]; //Get access to the 8X8 font to display letters on the matrix (located in RGB.h)

RGB.h contains:
Code: [Select]
const char letters[]  = {
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, //0/ --> ' '
    ...
    0x00,0x61,0x51,0x49,0x45,0x43,0x00,0x00, //90/ --> Z
};


letters[] is called exactly once in RGBMatrix.cpp, in RGBMatrix.fillChar()

Code: [Select]
//Strange looking algorithm converts rows to columns and vice versa.
if(letters[letter_offset+(7-column)] & (1<<row))
screenBuffer[screen].pixel[row*8+column]=color;
            else screenBuffer[screen].pixel[row*8+column]=BLACK;


So, in order to use PROGMEM, did the following:

In RGB.h:
Code: [Select]
const prog_char letters[] PROGMEM = {
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, //0/ --> ' '

and in

In RGBMatrix.cpp
Code: [Select]
//Strange looking algorithm converts rows to columns and vice versa.
if(pgm_read_byte_near(letters[letter_offset+(7-column)]) & (1<<row))
screenBuffer[screen].pixel[row*8+column]=color;
            else screenBuffer[screen].pixel[row*8+column]=BLACK;

and updated the lines pertaining to letter_offset:
Code: [Select]

letter_offset = letter - '0'+1;

and
Code: [Select]
if(!isalnum(letter))letter_offset=0;

It compiles, but I get garbage.  Font colours are being correctly transmitted, so I know that the RGBMatrix.scroll() is functioning.

My bet is that I'm not using pgm_read_byte_near correctly.

Can anyone point me in the right direction?

YeahNo

Bingo.

Code: [Select]


extern const PROGMEM prog_char letters[]; //Get access to the 8X8 font to display letters on the matrix (located in RGB.h)
...
const PROGMEM prog_char letters[] = {
...
//Strange looking algorithm converts rows to columns and vice versa.
if(pgm_read_byte(&letters[letter_offset+(7-column)]) & (1<<row))
  screenBuffer[screen].pixel[row*8+column]=color;
else screenBuffer[screen].pixel[row*8+column]=BLACK;

bradwood

#2
Feb 23, 2013, 10:34 pm Last Edit: Feb 24, 2013, 10:58 am by bradwood Reason: 1
I'm doing *exactly* the same exercise,

Here are some bitmaps for numbers if anyone needs them -- I also have a spreadsheet for working the hex out, if anyone needs it let me know.

Code: [Select]

0x00,0x3E,0x51,0x49,0x45,0x3E,0x00,0x00,//48/ --> 0
0x00,0x00,0x42,0x7F,0x40,0x00,0x00,0x00,//49/ --> 1
0x00,0x42,0x61,0x51,0x49,0x46,0x00,0x00,//50/ --> 2
0x00,0x22,0x49,0x49,0x49,0x36,0x00,0x00,//51/ --> 3
0x00,0x18,0x14,0x12,0x7F,0x10,0x00,0x00,//52/ --> 4
0x00,0x2F,0x49,0x49,0x49,0x31,0x00,0x00,//53/ --> 5
0x00,0x3E,0x49,0x49,0x49,0x32,0x00,0x00,//54/ --> 6
0x00,0x01,0x01,0x79,0x05,0x03,0x00,0x00,//55/ --> 7
0x00,0x36,0x49,0x49,0x49,0x36,0x00,0x00,//56/ --> 8
0x00,0x26,0x49,0x49,0x49,0x3E,0x00,0x00,//57/ --> 9
0x00,0x00,0x00,0x66,0x00,0x00,0x00,0x00,//58/ --> :


Go Up