8x8 Small LED Matrix - PROGMEM Alternative?

EL Wire/Tape/Panels, LEDs, pixels and strips, LCDs and TFTs, etc products from Adafruit

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
wlc
 
Posts: 12
Joined: Thu Nov 08, 2012 3:49 am

8x8 Small LED Matrix - PROGMEM Alternative?

Post by wlc »

I'm using one of your 8X8 Small LED Matrices along with your library.

What I'm trying to do is to pass a bitmap from a computer to the arduino via serial, and display it on the matrix. I'm all good with the serial part, but when it comes to displaying the bitmap I'm having issues since the library only supports drawing it from PROGMEM.

What kinds of workarounds should I look into?

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: 8x8 Small LED Matrix - PROGMEM Alternative?

Post by adafruit_support_rick »

The simplest thing to do might be to modify the Adafruit_GFX library.
You can either
1) Remove the reference to pgm_read_byte from the drawBitmap routine
- or -
2) Duplicate the drawBitmap routine and give it a different name like drawBitmapRAM. Remember to add a declaration of drawBitmapRAM to the Adafruit_GFX.h file.

Alternately, you could copy the drawBitmap function to your sketch. Once it's there,
1) Remove the "Adafruit_GFX::" prefix from the function name
2) take out the reference to pgm_read_byte
3) change the call to "drawPixel" to "matrix.drawPixel"

after that, you would simply call "drawBitmap" instead of "matrix.drawBitmap"

wlc
 
Posts: 12
Joined: Thu Nov 08, 2012 3:49 am

Re: 8x8 Small LED Matrix - PROGMEM Alternative?

Post by wlc »

Thanks. I like the idea of just copying an edited version to my sketch.

I'm having a bit of problems doing it, though.

The starting code is:

Code: Select all

void Adafruit_GFX::drawBitmap(int16_t x, int16_t y,
			      const uint8_t *bitmap, int16_t w, int16_t h,
			      uint16_t color) {

  int16_t i, j, byteWidth = (w + 7) / 8;

  for(j=0; j<h; j++) {
    for(i=0; i<w; i++ ) {
      if(pgm_read_byte(bitmap + j * byteWidth + i / 8) & (128 >> (i & 7))) {
	drawPixel(x+i, y+j, color);
      }
    }
  }
}
My modified code is:

Code: Select all

void drawBitmap(int16_t x, int16_t y,
			      const uint8_t *bitmap, int16_t w, int16_t h,
			      uint16_t color) {

  int16_t i, j, byteWidth = (w + 7) / 8;

  for(j=0; j<h; j++) {
    for(i=0; i<w; i++ ) {
      if((*bitmap + j * byteWidth + i / 8) & (128 >> (i & 7))) {
	matrix.drawPixel(x+i, y+j, color);
      }
    }
  }
}
It compiles fine, but when I call drawBitmap I get an odd pattern on the led (it looks to be pieces of a letter.) I made sure it wasn't my serial connection by placing a bitmap in my sketch and calling it that way.

Any idea what I'm missing?

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: 8x8 Small LED Matrix - PROGMEM Alternative?

Post by adafruit_support_rick »

Code: Select all

if((*bitmap
I don't think you want to dereference bitmap (i.e., you don't want the '*' in front of it).

wlc
 
Posts: 12
Joined: Thu Nov 08, 2012 3:49 am

Re: 8x8 Small LED Matrix - PROGMEM Alternative?

Post by wlc »

I did try that first (the exact same code listed above, minus the asterisk) and got this error for that line:

Code: Select all

Matrix_test.cpp: In function 'void drawBitmap(int16_t, int16_t, const uint8_t*, int16_t, int16_t, uint16_t)':
Matrix_test:150: error: invalid operands of types 'const uint8_t*' and 'int' to binary 'operator&'

I ended up adding it when I was doing searches on similar causes of the error.

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: 8x8 Small LED Matrix - PROGMEM Alternative?

Post by adafruit_support_rick »

Oh, right. It was late night yesterday... :roll:
Try this:

Code: Select all

      if((*(bitmap + j * byteWidth + i / 8)) & (128 >> (i & 7))) {
   matrix.drawPixel(x+i, y+j, color);
You're computing a pointer here, so you want to dereference it after the arithmetic is done. Basically, you're replacing 'pgm_read_byte' with '*'

wlc
 
Posts: 12
Joined: Thu Nov 08, 2012 3:49 am

Re: 8x8 Small LED Matrix - PROGMEM Alternative?

Post by wlc »

That makes sense, and now my code works great.

Thank you for all your help

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: 8x8 Small LED Matrix - PROGMEM Alternative?

Post by adafruit_support_rick »

Cool!
I'll make sure I'm awake the next time I answer one of your posts! :roll:

Locked
Please be positive and constructive with your questions and comments.

Return to “Glowy things (LCD, LED, TFT, EL) purchased at Adafruit”