Pages: [1]   Go Down
Author Topic: Extending RGBMatrix.cpp for the SparkFun RGB Matrix with backpack.  (Read 1665 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
extern const char letters[]; //Get access to the 8X8 font to display letters on the matrix (located in RGB.h)

RGB.h contains:
Code:
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:
//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:
const prog_char letters[] PROGMEM = {
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, //0/ --> ' '
and in

In RGBMatrix.cpp
Code:
//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:
letter_offset = letter - '0'+1;
and
Code:
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?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Bingo.

Code:

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;
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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/ --> :

« Last Edit: February 24, 2013, 04:58:36 am by bradwood » Logged

Pages: [1]   Go Up
Jump to: