I2C Mini Matrix (PID: 870) Random Data

I have a few of the 8x8 mini matrices. I use them for scrolling messages, however, I want to be able to show just random data. Just random LEDs popping on and off.

The overall system will be (6) of the 8x8 mini's (https://www.adafruit.com/product/870) tied together (yes, I am aware that the mini only has 4 addressable slots, so there will be some that show the same thing) and I will have (2) of the 16x8 minis (https://www.adafruit.com/product/3152) on the same data chain showing random data as well.

I can make the 870's and 3152's scroll messages no problem, but what would be the best way to display random LEDs?

Posts: 95
Joined: Mon Sep 11, 2017 12:45 pm

Re: I2C Mini Matrix (PID: 870) Random Data

The GFX library has a drawPixel() function for drawing individual pixels.

And the Arduino library has a random() function for generating pseudorandom numbers:
https://www.arduino.cc/reference/en/lan ... rs/random/
You can specify the maximum range of the numbers to match the dimensions of your array.

Posts: 76128
Joined: Sat Feb 07, 2009 10:11 am

Re: I2C Mini Matrix (PID: 870) Random Data

I think that can help.

But I was wondering if I could just write a random number between 0-2040 to each 8x8 and 0-4080 for the 16x8. I am getting the max value of 2040 by multiplying 255 by 8 columns. (1 column has 8 LEDs, 8 bit Bin to Dec = 255, 255 per column times 8 columns).

My hardware will be (4) of the 8x8 addressed to 0x70-0x73 and (3) of the 16x8 addressed to 0x74-0x76.

I know this code isn't exact, but it shows my idea (it assumes already setting up the various includes and declares for libraries for the matrices).

Code: Select all | TOGGLE FULL SIZE
`void loop() {// -- For the 8x8 Matrices --  for (int i = 0; i < 4, i++) {    int data = random(0,2040);    matrix8[i].clear;    matrix8[i],print(data);    matrix8[i].writeDisplay();  }// -- For the 16x8 Matrices --  for (int i = 4; i < 7, i++) {    int data = random(0,4080);    matrix16[i].clear;    matrix16[i],print(data);    matrix16[i].writeDisplay();  }}`

Posts: 95
Joined: Mon Sep 11, 2017 12:45 pm

Re: I2C Mini Matrix (PID: 870) Random Data

The 'print()' command is going to try to print characters. To set random pixels you would either need to use the drawPixel function, or do low-level register operations directly to the HT16K33 chip. Writing to registers would allow you to set up to 8 pixels at a time.

Posts: 76128
Joined: Sat Feb 07, 2009 10:11 am

Re: I2C Mini Matrix (PID: 870) Random Data

If I used the matrix[i].drawPixel(uint16_t x, uint16_t y, uint16_t color), (is that the proper syntax?) my "x" would be from 0-7 and my "y" would be from 0-7 as well?

So it would look like this:

Code: Select all | TOGGLE FULL SIZE
`void loop() {// -- For the 8x8 Matrices --  for (int i = 0; i < 4, i++) {    int x_pos = random(0,7);    int y_pos = random(0,7);    matrix8[i].clear;    matrix8[i].drawPixel(x_pos, y_pos),    matrix8[i].writeDisplay();  }}`

But I would have to create a bunch of those to get a lot of LEDs on at the same time. Otherwise I am looking at 1 LED per matrix.

Posts: 95
Joined: Mon Sep 11, 2017 12:45 pm

Re: I2C Mini Matrix (PID: 870) Random Data

To give an idea of the end result I am looking for, here is a link to a video of the desired result.

I am trying to replicate the 2 LED matrices in the R2 dome.

Posts: 95
Joined: Mon Sep 11, 2017 12:45 pm

Re: I2C Mini Matrix (PID: 870) Random Data

Your video link is blocked for some reason. But you can call drawPixel as many times as you want per matrix. There is nothing that limits you to 1 pixel.

Coded as below, it should set every pixel on every matrix to either ON or OFF
Code: Select all | TOGGLE FULL SIZE
`for (int i = 0; i < 4, i++){    matrix8[i].clear;    for int(row = 0, row < 8, row++)    {        for (int col = 0, col < 8, col++)        {            matrix8[i].drawPixel(row, col, random(0,2));        }    }    matrix8[i].writeDisplay();}`

Posts: 76128
Joined: Sat Feb 07, 2009 10:11 am

Re: I2C Mini Matrix (PID: 870) Random Data

So, if I am following your code correctly. you are going to each matrix one at the time.

On a single matrix, you are going to each column, one at the time, and then going to each LED on that column, and using the random generator t determine if that single LED is to be on or off.

So instead of generating a random value of, let's say 673, and writing that whole value to the entire matrix, you are scrolling each and every LED and randomizing on or off.

Interesting.

Posts: 95
Joined: Mon Sep 11, 2017 12:45 pm

Re: I2C Mini Matrix (PID: 870) Random Data

If you wanted to dig into the library code, you could write 8 at a time directly to the HT16K33 registers. But it is not likely to be any faster. As it is, drawPixel is writing to a memory buffer. That gets flushed to the matrix at the end when you call writeDisplay().

Posts: 76128
Joined: Sat Feb 07, 2009 10:11 am

Re: I2C Mini Matrix (PID: 870) Random Data

Thank you for your help. I'll be testing this tomorrow.

Posts: 95
Joined: Mon Sep 11, 2017 12:45 pm

Re: I2C Mini Matrix (PID: 870) Random Data

Code: Select all | TOGGLE FULL SIZE
`for (int i = 0; i < 4, i++){    matrix8[i].clear;    for int(row = 0, row < 8, row++)    {        for (int col = 0, col < 8, col++)        {            matrix8[i].drawPixel(row, col, random(0,2));        }    }    matrix8[i].writeDisplay();}`

Bill, this code worked perfectly. I am currently testing with some of the 8x8 matrices. I will be adding the 16x8 soon.

This is my final code. I call it as a subroutine, and the "millis() - prev_milli[2] >= data_port_delay" is to allow me to slow down or speed up the rate without affecting any of the other sub routines.
Code: Select all | TOGGLE FULL SIZE
`void dataDisplay() {  if (millis() - prev_milli[2] >= data_port_delay){    // --- 8x8 Matrix ---    for (int i = 0; i < 4; i++) {      matrix8[i].clear();      for (int row8 = 0; row8 < 8; row8++) {        for (int col8 = 0; col8 < 8; col8++) {          matrix8[i].drawPixel(row8, col8, random(0,2));        }      }      matrix8[i].writeDisplay();    }    // --- 16x8 Matrix ---    for (int c = 4; c < 7; c++) {      matrix16[c].clear();      for (int row16 = 0; row16 < 8; row16++) {        for (int col16 = 0; col16 < 16; col16++) {          matrix16[c].drawPixel(row16, col16, random(0,2));        }      }      matrix16[c].writeDisplay();    }    prev_milli[2] = millis();  }}`

Posts: 95
Joined: Mon Sep 11, 2017 12:45 pm

Re: I2C Mini Matrix (PID: 870) Random Data

Good to hear that worked for you. Thanks for the update.