Go Down

Topic: Matrix problem (Read 2970 times) previous topic - next topic

PaulRB

Try this:

Code: [Select]
#include <SPI.h>

#define LATCH 10
#define MULTIPLEX_PERIOD 1000

SPISettings shiftRegister(10000000UL, MSBFIRST, SPI_MODE0);

void setup() {
  SPI.begin(); //Start up the SPI hardware
  SPI.beginTransaction(shiftRegister); //Prepare to send data to shift registers
  pinMode(LATCH, OUTPUT);
}

void multiplexDisplay() {
  //"static" means these variables does not loose their value when multiplexDisplay() ends
  static byte currRow; //the row, 0 to 7, of the matrix that is currently lit
  static unsigned long lastUpdate; //time when this row was lit
  unsigned long millisNow = millis(); //Get time now
  if (millisNow - lastUpdate >= MULTIPLEX_PERIOD) { //Is it time to light next row of matrix?
    lastUpdate = millisNow; //Record time this row was lit
    SPI.transfer(1 << currRow); //Send a byte indicating which row to light
    SPI.transfer(0b10101010); //Send the required pattern for this row of the matrix
    SPI.transfer(0b10101010);
    digitalWrite(LATCH, LOW);
    digitalWrite(LATCH, HIGH); //Latch the data into the shift register outputs
    if (currRow++ > 7) currRow = 0; //Get ready to light next row of matrix
  }
}

void loop() {
  multiplexDisplay();
}


Please describe what happens when the sketch runs. It compiles but I cannot test it.

bogdan666

i am prepared to learn every line of the code, thank you

"SPISettings shiftRegister(10000000UL, MSBFIRST, SPI_MODE0);"
i get an eror at this line saying SPISettings does not name a type"

PaulRB

#47
Apr 04, 2019, 09:13 pm Last Edit: Apr 04, 2019, 11:15 pm by PaulRB
That's odd. Compiled fine for me. What version of IDE are you using?

I'm on 1.6.11.

bogdan666

my bad, after updating the app it works perfectly, the matrix behaves like this:
-starting from top row, the leds light up, 1.3.5.7.9.11.13.15
-and it descends down troughout all the columns with 1 second break

PaulRB

-and it descends down troughout all the columns
You mean "rows"?

Now change MULTIPLEX_PERIOD from 1000 to 2.

How does the display look? any flickering?

bogdan666

yes, i meant rows, sorry. Only the last row is flickering, but only if you really really watch for the flicker

PaulRB

Can you replace the shift register driving the rows? Does that cure the flicker?

bogdan666

i changed it, it still flickers, but it is barely noticeable.

PaulRB

That's strange, there is no reason for the last row to flicker more than any other row. Can you re-wire the shift register so that the rows are connected to different pins? Does the flickering stay with the last row or does it move to another row?

bogdan666

the flicker stays with that row. i have a suggestion, when the matrix is going slow, after the last row lights up, it goes off for a second, can't it go straight to row 1 again ? maybe that is the cause, i know that they have the same on and off time, but as i said, it is just an idea.

PaulRB

#55
Apr 06, 2019, 11:32 am Last Edit: Apr 06, 2019, 11:45 am by PaulRB
Code: [Select]
    if (currRow++ > 7) currRow = 0; //Get ready to light next row of matrix
The time to go back to row 0 after row 7 is extremely small, it cannot be the cause of flicker. Also, if that was the problem, the flickering row would move when you re-wired the shift register. But it is good that you are thinking logically about the cause of the flickering.

If the delays between lighting rows of the matrix was not identical, the result would be that the rows would have different brightness. Rows that were lit for slightly longer would be slightly brighter.

Flickering can be caused by delays that are not steady, not always the same length. If the code was the problem, all rows have steady and identical timing except the last row, where the timing is not steady. I can't think how that would happen in this sketch.

I think the problem is more likely to be hardware, perhaps a soldering fault? This might reduce the voltage to the point where it is on or near the limit of what is needed to light the LEDs, causing them to flicker, for example.

bogdan666

could be, everything is made on a perfboard, i will check all the connections, meanwhile we can move on if u want.

bogdan666

I tried changing the 0s and 1s, but i don't understand anything.

PaulRB

If you change the pattern to all 1s, every led should light up. Does that look ok? Any flickering, other than the flickering you already noticed on the last line?

bogdan666

#59
Apr 12, 2019, 09:38 am Last Edit: Apr 12, 2019, 09:39 am by bogdan666
actually, when everything is 0 the matrix is on., i already tried it, and if i change the first 0 into 1, the last column turns off.
LE:no more flickering.

Go Up