0

I2C Mini Matrix (PID: 870) Random Data
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

I2C Mini Matrix (PID: 870) Random Data

by vader7071 on Tue Sep 10, 2019 12:55 pm

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?

Thank you in advance for your help.

vader7071
 
Posts: 73
Joined: Mon Sep 11, 2017 12:45 pm

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

by adafruit_support_bill on Tue Sep 10, 2019 1:40 pm

The GFX library has a drawPixel() function for drawing individual pixels.
https://learn.adafruit.com/adafruit-gfx ... points-3-1

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.

adafruit_support_bill
 
Posts: 74337
Joined: Sat Feb 07, 2009 10:11 am

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

by vader7071 on Wed Sep 11, 2019 8:54 am

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();
  }
}


vader7071
 
Posts: 73
Joined: Mon Sep 11, 2017 12:45 pm

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

by adafruit_support_bill on Wed Sep 11, 2019 9:09 am

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.

adafruit_support_bill
 
Posts: 74337
Joined: Sat Feb 07, 2009 10:11 am

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

by vader7071 on Wed Sep 11, 2019 3:09 pm

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.

vader7071
 
Posts: 73
Joined: Mon Sep 11, 2017 12:45 pm

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

by vader7071 on Wed Sep 11, 2019 3:13 pm

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

https://www.facebook.com/vader7071/videos/10201096871616365/?t=0

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

vader7071
 
Posts: 73
Joined: Mon Sep 11, 2017 12:45 pm

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

by adafruit_support_bill on Wed Sep 11, 2019 3:26 pm

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();
}

adafruit_support_bill
 
Posts: 74337
Joined: Sat Feb 07, 2009 10:11 am

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

by vader7071 on Wed Sep 11, 2019 3:41 pm

https://www.youtube.com/watch?v=SB-kVblAhTI

That link may work better.

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.

vader7071
 
Posts: 73
Joined: Mon Sep 11, 2017 12:45 pm

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

by adafruit_support_bill on Wed Sep 11, 2019 3:53 pm

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().

adafruit_support_bill
 
Posts: 74337
Joined: Sat Feb 07, 2009 10:11 am

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

by vader7071 on Wed Sep 11, 2019 6:04 pm

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

vader7071
 
Posts: 73
Joined: Mon Sep 11, 2017 12:45 pm

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

by vader7071 on Thu Sep 12, 2019 8:59 am

adafruit_support_bill wrote:
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();
  }
}

vader7071
 
Posts: 73
Joined: Mon Sep 11, 2017 12:45 pm

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

by adafruit_support_bill on Thu Sep 12, 2019 9:30 am

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

adafruit_support_bill
 
Posts: 74337
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.