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?
8x8 Small LED Matrix - PROGMEM Alternative?
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: 8x8 Small LED Matrix - PROGMEM Alternative?
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"
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"
-
- Posts: 12
- Joined: Thu Nov 08, 2012 3:49 am
Re: 8x8 Small LED Matrix - PROGMEM Alternative?
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:
My modified code is:
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?
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);
}
}
}
}
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);
}
}
}
}
Any idea what I'm missing?
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: 8x8 Small LED Matrix - PROGMEM Alternative?
Code: Select all
if((*bitmap
-
- Posts: 12
- Joined: Thu Nov 08, 2012 3:49 am
Re: 8x8 Small LED Matrix - PROGMEM Alternative?
I did try that first (the exact same code listed above, minus the asterisk) and got this error for that line:
I ended up adding it when I was doing searches on similar causes of the error.
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.
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: 8x8 Small LED Matrix - PROGMEM Alternative?
Oh, right. It was late night yesterday...
Try this:
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 '*'
Try this:
Code: Select all
if((*(bitmap + j * byteWidth + i / 8)) & (128 >> (i & 7))) {
matrix.drawPixel(x+i, y+j, color);
-
- Posts: 12
- Joined: Thu Nov 08, 2012 3:49 am
Re: 8x8 Small LED Matrix - PROGMEM Alternative?
That makes sense, and now my code works great.
Thank you for all your help
Thank you for all your help
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: 8x8 Small LED Matrix - PROGMEM Alternative?
Cool!
I'll make sure I'm awake the next time I answer one of your posts!
I'll make sure I'm awake the next time I answer one of your posts!
Please be positive and constructive with your questions and comments.