Adafruit 16x32 RGB LED Matrix

what is the best way to clear the matrix, so that I can print new data on top, without going to a flicker inducing

  matrix.fillScreen(0);

?

my code is:

RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, false);

void setup() {
  Time.zone(0);
  matrix.begin();

  matrix.setTextSize(1);    // size 1 == 8 pixels high

  // print each letter with a rainbow color
  matrix.setTextColor(matrix.Color333(7,0,0));

}

void loop() {
int sec=Time.second();
int min=Time.minute();
int hour=Time.hour();
  matrix.setCursor(1, 0);   // start at top left, with one pixel of spacin

  matrix.print(hour);
  matrix.print(":");
  matrix.print(min);
  matrix.setCursor(8,8);
  matrix.print(sec);
  matrix.swapBuffers(false);
  
}

@Julian, @ScruffR is dead on (as usual) regarding the fonts. As for the fillscreen, that is the correct way to reset the screen prior to painting. So in loop(), do a matrix.fillscreen(0) then draw everything you need drawn with the ā€œbottomā€ layer being the first to draw and so on. Each successive draws will overwrite parts of the previous draws. When you’ve drawn everthing, you do the swapBuffers(false) to redraw the screen in its entirety. :smile:

1 Like

And in addition to @peekay123 's tips you may also use double buffering by doing this

RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, true); // instead of false

This way you do the drawing off ā€œscreenā€ and only make the new screen visible, once you are done by swapping buffers - as Paul said.

To be able to do double buffering you need enough RAM to store both displays. The Core has usually enough for two 16x32 or one 32x32 panel, unless you do have other code concurently demanding big chunks of RAM too.


As for fillScreen() there are some colors that can be used way faster than others. At the moment Paul only allows the fast memset() approach for black and white, but there are a few other colors possible too.
Actually any color where the low byte sattisfies these criteria:

  • Plane 0 bits (0 & 1) have to be 0b00 or 0b11
  • Bits 2, 3 & 4 have to match bits 5, 6 & 7

e.g. 0b10110100 is a valid ā€œmemsetableā€ color.

The resulting colors may not resemble the color you have in mind when passing in an int color, but an overload for fillScreen that takes an enumed (named) color this might become useful.

At the moment I’m looking if there is a way to speed up fillScreen for any color (e.g. via ASM stosb or something similar).

1 Like

@ScruffR just a reminder that the original library was written by Limor Fried/Ladyada & Phil Burgess/PaintYourDragon. I just did the porting :wink:

2 Likes

Thanks for the reminder, @peekay123.
It’s just that I got the impression, that you are the one who has the best insight of the ins and outs of this library.

So you are my GFX & RGB matrix hero :wink:

3 Likes

@ScruffR, I have to agree with you there we are lucky to have @peekay123 and others to help.

I have solved the flicker ( by just doing what you said). my false is now true (in the initial statement / matrix declaration ) and my final swapbuffer is false.

Totally flicker free now.

Thank you.

:smiley:

2 Likes

@Julian, @ScruffR you make me blush :blush: Truth is, myself and the other Elites do this because of the great members we have in this community. However I end up helping, all I ask is that members pay it forward :smile:

4 Likes

@peekay123, @ScruffR, I am just thinking of how I can use my display and to connect up a sensor I seem to be running out of pins. As a way to get round this is there a way to use spark publish to publish a variable, say temperature, from one core and then for another core to ā€œcollectā€ that variable and display it on the LED matrix?

@Julian, you can use Spark.publish() on the sensing Core and Spark.subscribe() on the display Core to wait for the published event. :smile:

1 Like

@Julian, sure you can use Spark.publish() as @peekay123 has pointed out, but may I also ask what sensors you’d like to use and how many more pins you’d be needing for your idea?

As for my setup I still got D0, D1, A0, A1 and A7 free to use, so I2C sensors or Serial2and three analog inputs would still be possible.
And if required some already used pins could be shifted about.

@ScruffR, in the ā€œfastā€ version of the library, I have A4 (for 16x32 matrix only) A5, A7, D5, D6 and D7 available. I guess you reworked the whole-port I/O to other pins? I like that you free up the I2C bus so if you feel it’s just as fast, it would be great if you did a pull request! :smile:

1 Like

I’ll try to push it to my repo and file a PR on yours, but I’m an utter failure with GitHub. I can just do the minimum and don’t even know if I’m doing it right :blush:

I’m pretty certain ā€œmy wayā€ is at least as quick as yours (although I haven’t measured/proven it - I hope not to be wrong :wink:) and on the 16x32 panel I’d also have A6 free - I do use RX/TX tho’.

1 Like

@peekay123, since I don’t know how long my battle with GitHub will take I’ll just do it the lazy way for now

https://dl.dropboxusercontent.com/u/60050879/RGBmatrixPanel.zip

@ScruffR, nice stuff dude! I love open source - you write something, someone looks at it, gets inspired, makes it better and shares - while(true)! :smile:

Did you measure the ISR service time so set the dur[] array values? Was that the worst case (two panel) time (20us per plane)?

1 Like

Sorry, I haven’t timed it at all, yet. The 20µs were more a optimistic guess and are definetly not worst case, I’d even say they weren’t even average :blush:

But I still only have one of those olde 15kg Oscillographs which I didn’t cart down from the atic :wink: And at the moment I’m even on a mountain hut holiday.

If I have to be honest - I don’t even completely understand what would happen, if these settings were completely wrong :thought_balloon: :question:

But since I’m in the middle of sucking in the STM32 ASM manual to see if there might be some other options for tweaking, I didn’t expect that anybody would be interested in this already.

But if you’d get round to measuring, I’d love to hear if this actually did bring some measurable improvement - I would be disappointed if it didn’t :worried:


Just succeeded in creating a pull-request

@ScruffR, I have a logic analyzer (DSLogic) for measuring the ISR entry-to-exit time. I only have a single 16x32 panel so I will let you know what I discover. :smile:

1 Like

I was going to add a adafruithermocouple breakoutboard MAX31855. Looks like I need these pins

int thermoCLK = A3;
int thermoCS = A2;
int thermoDO = A4;

Could I just reassign the above to A3,A5 and A7, which are the pins I have free?

It might be nice to use a second core to collect the data though because 1) I have an excuse to buy another core, 2) I can have my display remote (at home) from the thermocouple (at work).

Also I don’t have to worry about the libraries playing nicely together.

By the way, merry Christmas, thank you all for your help this year. I look forward to more adventures in electronics next year!

1 Like

If you want to use the hardware SPI of the Core, you would need to use the pins you said, loosing the speed gain of @peekay123 's or my fast lib, but there is also a very good SoftSPI which allows the use of any other three pins on the Core.
So you could do it - but I’ll promise to tell noone, not to rob you of any excuse to get another Core :wink: :no_mouth:

1 Like

Hi @Dave and @peekay123 ! Many thanks for your work on the Adafruit library!

I have an Adafruit 32x32 panel, I’m sure it’s connected correctly and the panel works fine but I can only get half the pixels to work, with two dark bands in it, and it’s clearly D that’s not working.

I’m essentially just trying to run /display-firmware-32 as-is from here:

but changing the constructor to be
RGBmatrixPanel matrix(A, B, C, D, CLK, LAT, OE, false, 2);

I’m also sure the panel works fine, as it works fine with an Arduino.

Am I missing something really obvious?

Hi @danield,

My display-firmware-32 was tested on a few 16x32s I had strung together, and I was having problems with that firmware, so it’s definitely not ready for use. I ported some chunks as best as I could, but @peekay123 is way better at display firmware than myself :).

Thanks,
David

1 Like