Arduino Forum

Using Arduino => LEDs and Multiplexing => Topic started by: bogdan666 on Mar 24, 2019, 08:20 am

Title: Matrix problem
Post by: bogdan666 on Mar 24, 2019, 08:20 am
Hello everyone, i am new to this forum, but I've been using arduino for a while now, however i have been using it only for small and simple stuff, but recently i found a very simple (or so it seemed) video about an led matrix with shift registers, i don't quite fully understand how they work, tho i watched a few videos. now, i have 2 problems, the project is for 8x24, but i only had leds for a 8x16 matrix,  thought that the code would still work an i would be able to use it just like this, the second problem is that in the schematic they don't show the led polarity...so i just put them with anodes on rows, plugged it in, changed my output pins, because it was easier to connect them differently on the pcb, and gave it a go...and my matrix is fully on, and only flickers a bit when i turn the speed potentiometer. here is the schematic and the code, any idea is welcome, except the idea of rebuilding the matrix :)
If i have to modify the whole code, just help me out with one character and i will do the rest
...the code is too long and i can't post it as a code
Title: Re: Matrix problem
Post by: Grumpy_Mike on Mar 24, 2019, 08:45 am
Do you know what to do to change the polarity of the multiplexing? Have a read of this:-http://www.thebox.myzen.co.uk/Workshop/LED_Matrix.html (http://www.thebox.myzen.co.uk/Workshop/LED_Matrix.html)

Most mobile devices will not cope with .ino files. Post it as a .txt file instead and then we can all read it.
Title: Re: Matrix problem
Post by: bogdan666 on Mar 24, 2019, 08:56 am
ok, i will give it a read, meanwhile here is the code in .txt
Title: Re: Matrix problem
Post by: PerryBebbington on Mar 24, 2019, 03:24 pm
(https://forum.arduino.cc/index.php?action=dlattach;topic=605589.0;attach=300751)
Title: Re: Matrix problem
Post by: PerryBebbington on Mar 24, 2019, 03:27 pm
Please post your code with code tags as per the instructions in 'how to use this forum - please read' item #7.
Title: Re: Matrix problem
Post by: PaulRB on Mar 24, 2019, 04:32 pm
That 74hc595 driving the rows is going to fry. The ones driving the columns are somewhat overloaded also. The current limit for any pin on a '595 is 35mA and 70mA for all 8 pins combined.

With your red LEDs and 100R series resistors, each led will draw around 30mA. That's probably over their maximum, but as you are multiplexing, you will probably get away with it.

Each '595 sinking current from the columns will need to sink 30x8=240mA, more than three times their limit, if LEDs in all 8 columns are lit.

Each pin of the '595 driving the rows will need to source 30x16=480mA for a 16x8 matrix or 30x24=720mA for a 24x8 matrix. That's 20 times over the limit for the pin and 10 times over the limit for the chip. And 3 times what the Arduino can provide. I'm not surprised it is flickering. Can you smell burning yet?

If you care, ask for advice how to fix these things.
Title: Re: Matrix problem
Post by: bogdan666 on Mar 24, 2019, 07:06 pm
i cannot post the code because it is too long, i have stated this in my first post
the leds in my matrix are under driven, just enough to light up, my main problem is that the code is not working.
Title: Re: Matrix problem
Post by: PaulRB on Mar 24, 2019, 08:00 pm
the leds in my matrix are under driven, just enough to light up, my main problem is that the code is not working.
"Under driven"??? Then the schematic you posted must be wrong. You may think the code is your problem, but...
Title: Re: Matrix problem
Post by: bogdan666 on Mar 24, 2019, 08:12 pm
i used 1k resistors
Title: Re: Matrix problem
Post by: Paul__B on Mar 24, 2019, 10:58 pm
Thorough and absolute waste of time.  Use the MAX7219 modules (https://www.ebay.com/itm/MAX7219-Microcontroller-4-In-1-Display-with-5P-Line-Dot-Matrix-Module-Arduino/311419881374), do it properly.  :smiley-roll:
(https://i.ebayimg.com/images/g/B3sAAOSw1ktbXBr~/s-l1600.jpg) (https://www.ebay.com/itm/MAX7219-Microcontroller-4-In-1-Display-with-5P-Line-Dot-Matrix-Module-Arduino/311419881374)


i used 1k resistors
For 24 lines, you need to use 4k7 resistors.
Title: Re: Matrix problem
Post by: Grumpy_Mike on Mar 24, 2019, 11:55 pm
Quote
i cannot post the code because it is too long,
You can if you post it as an attachment.
Title: Re: Matrix problem
Post by: PaulRB on Mar 25, 2019, 07:36 am
i used 1k resistors
Please carefully review the schematic you posted. Are there any other differences to your own circuit? No-one likes to have their time wasted.

In that case, only the pins of the 74hc595 driving the rows are overloaded. 16x3=48mA compared to their limit of 35mA. So there is still a possibility that this could cause flickering, as the chip begins to fail. And 3mA per led with 1-in-8 multiplex explains she l why your display is dim.
Title: Re: Matrix problem
Post by: bogdan666 on Mar 25, 2019, 07:56 am
i reviewed the schematic a few times, the only diference betwen that and mine are the resistors and the fact that i have only 8x16 not 8x24, wich i said this in my first post, the code i use i posted in .ino as well as .txt
I don't mind the leds being dim, when i power up my circuit the whole matrix lights up and the whole circuit, includind the atmega 328p and the 595 draws 25mA.
Title: Re: Matrix problem
Post by: PerryBebbington on Mar 25, 2019, 12:28 pm
I cannot post the code because it is too long, I have stated this in my first post
So you did! Sorry!
Title: Re: Matrix problem
Post by: PaulRB on Mar 25, 2019, 08:59 pm
I've been reviewing the code....

I think the multiplexing is done by column-by-column. That means the multiplex ratio is 1-in16 or 1-in-24 rather than 1-in-8 which I assumed. My assumptions were based on the circuit designer understanding, well, how to design circuits, such as whether to place the series resistors on the columns or rows for example.

On top of the high multiplex ratio, the code appears very inefficient, using shiftOut() rather than SPI.transfer() and implementing a "walking one" by shifting 24 bits each time rather than simply toggling the clock line.

The code is an absolutely superb example. It demonstrates so many bad practices, over-complications, uneccessary repititions, obfuscations... I don't know where to start in terms of correcting it. My gut tells me to delete it and start over.

I'm really sorry if this all sounds so negative. I now have a deeper insight into why the matrix is so dim and flickers so badly. I take my hat off to the coder. Knowing so little, to have battled doggedly on to get anything working at all shows impressive determination. Bravo!
Title: Re: Matrix problem
Post by: Paul__B on Mar 25, 2019, 10:04 pm
I've been reviewing the code....
Now that in itself shows great enthusiasm!  :smiley-lol:

I think the multiplexing is done by column-by-column.
In which case, no risk of damage.  :smiley-roll:

I take my hat off to the coder. Knowing so little, to have battled doggedly on to get anything working at all shows impressive determination. Bravo!
Have to agree.

Now if the rows were the cathodes, then substituting the right-hand 74HC595 with a TPIC6A595 and multiplexing by row using the 1k resistors could produce a workable display.

But only as an exercise.  For any serious purpose, I have advised in #9.
Title: Re: Matrix problem
Post by: bogdan666 on Mar 26, 2019, 07:35 am
so i have to start from scratch... great, can you help me make at least one character so at least i have a foundation ?
Title: Re: Matrix problem
Post by: PaulRB on Mar 26, 2019, 06:08 pm
You do not want to alter your matrix. I guess a lot of time went into building it. Would you consider cutting your matrix in half, so 2 x 8x8? Then you could use max7219 chips and one of the popular Arduino libraries for use with the max chip such as LEDControl or Parola.

If you truly want to continue with your current design, you could remove the series resistors on the columns and instead have 8 x 750R series resistors on the rows. But this would always be dim, as only 4mA will flow through each led with a duty cycle of 1/16, or 1/24 if you extend your matrix.

A better solution would be to scan the matrix row-by-row instead of the column-by-column used now. This would be brighter because the duty cycle would be only 1/8. Also, you could use a UDN2980 chip to boost the current available from the '595 driving the rows. You would keep the series resistors on the columns but you could reduce them to 750R.
Title: Re: Matrix problem
Post by: bogdan666 on Mar 27, 2019, 07:23 am
Well, the easiest solution for me is to put resistors on the rows, and we can modify the code for row scanning, i will not extend the matrix, besides i have some red leds, even at 4mA they are bright enough for the experiment, i will keep the 1k for now and do some measurements after this is working properly.
Title: Re: Matrix problem
Post by: PaulRB on Mar 27, 2019, 08:14 am
No. For row scanning, the resistors should be on the columns. For column scanning, the resistors should be on the rows. This is one of the problems with your current circuit: you are column scanning but the resistors are on the columns.

Whenever LEDs are connected in parallel, each led should have it's own series resistor. When scanning the matrix column-by-column, you are lighting a column of up to 8 LEDs at a time, so for each led to have its own series resistor, those resistors must be on the rows. When scanning the matrix by row-by-row, a row of up to 16 LEDs could be lit in parallel, so the resistors must be on the columns.

In terms of brightness, it will make no difference whether you scan by row or by column. You hit the same limitation either way: the 35mA limit of a '595 pin. If scanning by column, that 35mA can be shared between 8 LEDs, so around 4mA each. But the duty cycle is 1/16, so the average led current is 0.25mA. if scanning by row, the 35mA is shared by up to 16 LEDs, so only around 2mA per led. But the duty cycle is 1/8, so the average current is also 0.25mA.
Title: Re: Matrix problem
Post by: bogdan666 on Mar 27, 2019, 09:35 am
ooh, now i understand, so i leave the matrix just like it is, with the resistors on each column,  and we modify the code so we can do row scanning.
le: i was wondering why people choose different position for their resistors, now i know, thank you.
Title: Re: Matrix problem
Post by: PaulRB on Mar 27, 2019, 10:18 am
One change to the circuit I would suggest would be to chain the '595 driving the rows to the other two '595s. i.e. the Serial Out of the second '595 driving the columns is connected to the Serial In of the '595 driving the rows. All three '595s can share the same clock and latch lines. Then, you can connect all three '595s to the SPI pins on the Arduino. This should make the circuit less likely to flicker and make the best of the inevitably low brightness.
Title: Re: Matrix problem
Post by: bogdan666 on Mar 27, 2019, 11:11 am
ok, that is an easy change i can make, only 2 wires to move, so after this the 3rd 595 will be the one driving my rows, consider it done, since it takes 5 minutes.
Title: Re: Matrix problem
Post by: Grumpy_Mike on Mar 27, 2019, 11:14 am
i was wondering why people choose different position for their resistors, now i know
You would have known sooner if you would have read the link in reply#1
Title: Re: Matrix problem
Post by: bogdan666 on Mar 27, 2019, 11:20 am
i did read it

"The other point is that current through the LED must be limited some how. The simplest way of doing this is with a series resistor. However, the resistor must be in the line that only takes the  current for one LED"

this is what they say, it got me a bit confused, i did not understood this at first, English is not my first language, maybe that played a part in there as well, sorry, i am still on the learning path of all this.
Title: Re: Matrix problem
Post by: PaulRB on Mar 27, 2019, 05:08 pm
only 2 wires to move, so after this the 3rd 595 will be the one driving my rows
But do you understand what I meant when I said the SPI pins? They are particular pins on the Arduino. Which pins depends on which type of Arduino. But they are almost always marked "MOSI" and "SCK". You can't just use any pins. This is because the Arduino has a dedicated circuit on the chip itself which is designed to send data at high speed to chips like the '595, and that circuit is connected to only those pins.
Title: Re: Matrix problem
Post by: PaulRB on Mar 27, 2019, 05:13 pm
i did not understood this at first, English is not my first language
In my opinion, you English is very good. Using "understood" instead of "understand" there was the first mistake I have noticed.
Title: Re: Matrix problem
Post by: bogdan666 on Mar 27, 2019, 10:18 pm
mosi 11 miso 12 and sck 13 yes, however i don't know what they stand for, or if it makes any difference which i connect to which.
Title: Re: Matrix problem
Post by: Grumpy_Mike on Mar 27, 2019, 10:42 pm
Quote
mosi 11 miso 12 and sck 13 yes, however i don't know what they stand for
Master out slave in
Master in slave out
Serial clock

They tell you what direction the data goes in.
So MOSI is an output pin for an Arduino acting as a master device and an input for a shift register acting as a slave device.

They tell you what way round things should be wired.
Title: Re: Matrix problem
Post by: bogdan666 on Mar 28, 2019, 06:29 am
ok,that makes sense, except for the latch pin of the 595, does that has a special output as well ?
Title: Re: Matrix problem
Post by: PaulRB on Mar 28, 2019, 07:35 am
When using the SPI feature on Arduino, its important to make sure that the "SS" pin is an output not an input. This tells the Arduino that it is the SPI master not a slave. So you might as well use that pin for the '595 latch pins.
Title: Re: Matrix problem
Post by: Grumpy_Mike on Mar 28, 2019, 10:54 am
ok,that makes sense, except for the latch pin of the 595, does that has a special output as well ?
The latch pin has nothing to do with the SPI protocol, you add it as an extra pulse after you have shifted data into the shift register.
Title: Re: Matrix problem
Post by: bogdan666 on Mar 28, 2019, 12:44 pm
ok, i understand.
Title: Re: Matrix problem
Post by: bogdan666 on Mar 31, 2019, 08:25 am
ok, final rewiring
-data digital pin 11
-clock digital pin 13
-latch digital pin 10
Title: Re: Matrix problem
Post by: PaulRB on Mar 31, 2019, 10:19 am
Next I would suggest writing a new, very simple sketch to light all LEDs using the SPI library.
Title: Re: Matrix problem
Post by: bogdan666 on Apr 01, 2019, 03:01 pm
well, since i never used a library before, i will do some research about it.
Title: Re: Matrix problem
Post by: PaulRB on Apr 01, 2019, 08:01 pm
It's a standard Arduino library, comes with the IDE, so you won't need to download it or use the library manager.
Title: Re: Matrix problem
Post by: bogdan666 on Apr 02, 2019, 08:27 pm
yeah, i found that out, but that doesn't make it any more easier to me. I still don't quite understand this shift register thing.
Title: Re: Matrix problem
Post by: PaulRB on Apr 02, 2019, 09:56 pm
What don't you understand?
Title: Re: Matrix problem
Post by: Grumpy_Mike on Apr 03, 2019, 04:09 am
Try reading this:-
https://circuitdigest.com/tutorial/what-is-shift-register-types-applications (https://circuitdigest.com/tutorial/what-is-shift-register-types-applications)
Title: Re: Matrix problem
Post by: bogdan666 on Apr 03, 2019, 08:48 pm
That is way too complicated for me...the closest thing to understanding how shift registers work, was a youtube tutorial with a guy which put 595 with push buttons, that made it clear, so i don't understand how this library thing works, if it was after me i would put every pin high and low manually, and i would still scratch my head because multiplexing is missing, i tried finding other codes for matrix with spi, but i didn't find any.
Title: Re: Matrix problem
Post by: PaulRB on Apr 03, 2019, 09:21 pm
The SPI library does the same thing as when the YouTube guy used switches and pushbuttons. But much, much faster

I think you jumped into the deep end of the pool when you cannot swim. You must start with more basic projects and tutorials and build up your knowledge and experience at a pace that suits you.
Title: Re: Matrix problem
Post by: Paul__B on Apr 03, 2019, 11:16 pm
And I think I addressed it adequately in #9.
Title: Re: Matrix problem
Post by: bogdan666 on Apr 04, 2019, 03:05 pm
Everything i learned was trough experimenting, jumping into a big pool, i will get there, it's going to be harder but i will get there faster. You helped me a lot in this project, and i thank you for that. i am only one code away from the end, this is my hobby, i don't know any programming, and the electronics part i learned also along the way, mistakes were made, lessons were learned.
first time i saw an arduino i didn't understand a thing, but by looking at the code it makes sense somehow.
if you want to help me out further i will be very thankful, if not, i am thankful so far and i will continue to learn stuff as always.
Title: Re: Matrix problem
Post by: PaulRB on Apr 04, 2019, 05:59 pm
+1 Karma for your patience and determination.

I will continue to help. If you want, I can suggest some code lines. But I must be careful that you understand each line of that code, and you don't just accept it without questioning it.
Title: Re: Matrix problem
Post by: PaulRB on Apr 04, 2019, 07:46 pm
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.
Title: Re: Matrix problem
Post by: bogdan666 on Apr 04, 2019, 08:51 pm
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"
Title: Re: Matrix problem
Post by: PaulRB on Apr 04, 2019, 09:13 pm
That's odd. Compiled fine for me. What version of IDE are you using?

I'm on 1.6.11.
Title: Re: Matrix problem
Post by: bogdan666 on Apr 05, 2019, 02:50 pm
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
Title: Re: Matrix problem
Post by: PaulRB on Apr 05, 2019, 05:45 pm
-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?
Title: Re: Matrix problem
Post by: bogdan666 on Apr 05, 2019, 08:45 pm
yes, i meant rows, sorry. Only the last row is flickering, but only if you really really watch for the flicker
Title: Re: Matrix problem
Post by: PaulRB on Apr 05, 2019, 11:47 pm
Can you replace the shift register driving the rows? Does that cure the flicker?
Title: Re: Matrix problem
Post by: bogdan666 on Apr 06, 2019, 09:15 am
i changed it, it still flickers, but it is barely noticeable.
Title: Re: Matrix problem
Post by: PaulRB on Apr 06, 2019, 09:34 am
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?
Title: Re: Matrix problem
Post by: bogdan666 on Apr 06, 2019, 10:38 am
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.
Title: Re: Matrix problem
Post by: PaulRB on Apr 06, 2019, 11:32 am
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.
Title: Re: Matrix problem
Post by: bogdan666 on Apr 06, 2019, 11:43 am
could be, everything is made on a perfboard, i will check all the connections, meanwhile we can move on if u want.
Title: Re: Matrix problem
Post by: bogdan666 on Apr 11, 2019, 09:12 pm
I tried changing the 0s and 1s, but i don't understand anything.
Title: Re: Matrix problem
Post by: PaulRB on Apr 11, 2019, 11:59 pm
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?
Title: Re: Matrix problem
Post by: bogdan666 on Apr 12, 2019, 09:38 am
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.
Title: Re: Matrix problem
Post by: PaulRB on Apr 12, 2019, 02:52 pm
actually, when everything is 0 the matrix is on
Oh, yeah.

The evening or this weekend, will try to get you another step forward. Maybe we can display a fixed image.
Title: Re: Matrix problem
Post by: bogdan666 on Apr 12, 2019, 04:11 pm
no problem, i appreciate it.
Title: Re: Matrix problem
Post by: PaulRB on Apr 12, 2019, 05:16 pm
i am prepared to learn every line of the code
For the code that is working now, are there any lines you do not understand or have questions about?
Title: Re: Matrix problem
Post by: bogdan666 on Apr 12, 2019, 06:01 pm
no, it was very clear because you started with a big delay between the rows, so i saw each change with "my own eyes"
Title: Re: Matrix problem
Post by: PaulRB on Apr 13, 2019, 11:46 am
OK, lets add a few more lines of code:
Code: [Select]
#include <SPI.h>

#define LATCH 10
#define MULTIPLEX_PERIOD 2

SPISettings shiftRegister(10000000UL, LSBFIRST, SPI_MODE0);

unsigned int image[8] = {
  0b0000000000001000,
  0b0000000000001100,
  0b0000000000001110,
  0b1111111111111111,
  0b0000000000001110,
  0b0000000000001100,
  0b0000000000001000,
  0b0000000000000000
};

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 do 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(~lowByte(image[currRow])); //Send the required pattern for this row of the matrix
    SPI.transfer(~highByte(image[currRow]));
    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();
}
Title: Re: Matrix problem
Post by: bogdan666 on Apr 13, 2019, 04:24 pm
The arrow pointing to the left is displaying correctly, no flickering, and also, now because you change to lsbfirst the leds light up at 1 instead of 0 ?
Title: Re: Matrix problem
Post by: PaulRB on Apr 13, 2019, 05:36 pm
Ah. The arrow was supposed to point right, as it looks in the code. Change the LSBFIRST back to MSBFIRST and swap the highByte() and lowByte() functions.

What changed the LEDs to light up with a 1 is the "~" operator. It means "binary not" and reverses 0s & 1s.
Title: Re: Matrix problem
Post by: bogdan666 on Apr 13, 2019, 06:20 pm
wait, it's pointing right, i just mixed them up sorry.

LE: in my excitement of seeing an arrow on my matrix, after confusing right and left, i noticed another thing, the code starts from first row, but my first row is off, so i think that the arrow is up side down.
Title: Re: Matrix problem
Post by: PaulRB on Apr 13, 2019, 07:53 pm
Try this change:
Code: [Select]
    SPI.transfer(128 >> currRow); //Send a byte indicating which row to light
Title: Re: Matrix problem
Post by: bogdan666 on Apr 13, 2019, 08:22 pm
yes, it works, the leds are on for every 1 in the code, but you have to explain what happened and the changes with lsb msb and the last change.
Title: Re: Matrix problem
Post by: PaulRB on Apr 13, 2019, 09:09 pm
This page (https://www.arduino.cc/reference/en/) will tell you about the << and >> operators.

This page (https://www.arduino.cc/en/Reference/SPI) will tell you about MSBFIRST and LSBFIRST.
Title: Re: Matrix problem
Post by: bogdan666 on Apr 14, 2019, 09:25 am
so in a very short way, both of these problems tell you the "direction" from where the bits are being read, right ?
Title: Re: Matrix problem
Post by: PaulRB on Apr 14, 2019, 10:33 am
so in a very short way, both of these problems tell you the "direction" from where the bits are being read, right ?
LSBFIRST & MSBFIRST do, yes.

The << & >> operators move bits around inside a variable by shifting them right or left by one or more places.
Title: Re: Matrix problem
Post by: bogdan666 on Apr 14, 2019, 10:42 am
ok, i got it now.
Title: Re: Matrix problem
Post by: PaulRB on Apr 14, 2019, 12:03 pm
Shall we try a little scrolling next?
Code: [Select]
#include <SPI.h>

#define LATCH 10
#define MULTIPLEX_PERIOD 2
#define SCROLL_PERIOD 200

SPISettings shiftRegister(10000000UL, MSBFIRST, SPI_MODE0);

unsigned int image[8] = {
  0b0000000000001000,
  0b0000000000001100,
  0b0000000000001110,
  0b1111111111111111,
  0b0000000000001110,
  0b0000000000001100,
  0b0000000000001000,
  0b0000000000000000
};

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(128 >> currRow); //Send a byte indicating which row to light
    SPI.transfer(~highByte(image[currRow])); //Send the required pattern for this row of the matrix
    SPI.transfer(~lowByte(image[currRow]));
    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 scrollDisplay() {
  static unsigned long lastUpdate; //time when matrix was last scrolled
  unsigned long millisNow = millis(); //Get time now
  if (millisNow - lastUpdate >= SCROLL_PERIOD) { //Is it time to scroll the matrix?
    lastUpdate = millisNow; //Record time the matrix was scrolled
    for (byte row = 0; row < 8; row++) {
      byte savedBit = bitRead(image[row], 15);
      image[row] <<= 1;
      bitWrite(image[row], 0, savedBit);
    }
  }
}

void loop() {
  multiplexDisplay();
  scrollDisplay();
}

As before, please let me know what you see, I can't test this. Also not sure which direction it will scroll! And as always, please read each line and ask about anything you don't understand.
Title: Re: Matrix problem
Post by: bogdan666 on Apr 14, 2019, 01:24 pm
The code was with MSBFIRST, so arrow was flipped, i corrected that to LSBFIRST, and the scrolling is going from right to left, you can leave it like this for text scrolling later on, also, since the arrow was going backwards, it looked funny and i turned it around, one more modify that i made was that i made it a bit shorter, since the body of the arrow was 16 leds long, i didn't understand what was going on because the 4th row was always on. One more thing that i modified, was the multiplex period, i made it 1, and the flickering to the last row when the entire matrix is on has disappeared. This is the code that i use now

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

#define LATCH 10
#define MULTIPLEX_PERIOD 1
#define SCROLL_PERIOD 200

SPISettings shiftRegister(10000000UL, LSBFIRST, SPI_MODE0);

unsigned int image[8] = {
  0b0001000000000000,
  0b0011000000000000,
  0b0111000000000000,
  0b1111111100000000,
  0b0111000000000000,
  0b0011000000000000,
  0b0001000000000000,
  0b0000000000000000
};

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(128 >> currRow); //Send a byte indicating which row to light
    SPI.transfer(~highByte(image[currRow])); //Send the required pattern for this row of the matrix
    SPI.transfer(~lowByte(image[currRow]));
    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 scrollDisplay() {
  static unsigned long lastUpdate; //time when matrix was last scrolled
  unsigned long millisNow = millis(); //Get time now
  if (millisNow - lastUpdate >= SCROLL_PERIOD) { //Is it time to scroll the matrix?
    lastUpdate = millisNow; //Record time the matrix was scrolled
    for (byte row = 0; row < 8; row++) {
      byte savedBit = bitRead(image[row], 15);
      image[row] <<= 1;
      bitWrite(image[row], 0, savedBit);
    }
  }
}

void loop() {
  multiplexDisplay();
  scrollDisplay();
}
Title: Re: Matrix problem
Post by: PaulRB on Apr 14, 2019, 03:57 pm
Ok, the next step will be a long one. We need to get the font data from your original sketch, organise it better, and get messages scrolling across the display.

To make things easier and keep the code short, I think we should try to follow the ASCII character set:
Code: [Select]
( )   32  02/00   40  20                 SPACE
(!)   33  02/01   41  21                 EXCLAMATION MARK
(")   34  02/02   42  22                 QUOTATION MARK
(#)   35  02/03   43  23                 NUMBER SIGN
($)   36  02/04   44  24                 DOLLAR SIGN
(%)   37  02/05   45  25                 PERCENT SIGN
(&)   38  02/06   46  26                 AMPERSAND
(')   39  02/07   47  27                 APOSTROPHE
(()   40  02/08   50  28                 LEFT PARENTHESIS
())   41  02/09   51  29                 RIGHT PARENTHESIS
(*)   42  02/10   52  2A                 ASTERISK
(+)   43  02/11   53  2B                 PLUS SIGN
(,)   44  02/12   54  2C                 COMMA
(-)   45  02/13   55  2D                 HYPHEN, MINUS SIGN
(.)   46  02/14   56  2E                 PERIOD, FULL STOP
(/)   47  02/15   57  2F                 SOLIDUS, SLASH
(0)   48  03/00   60  30                 DIGIT ZERO
(1)   49  03/01   61  31                 DIGIT ONE
(2)   50  03/02   62  32                 DIGIT TWO
(3)   51  03/03   63  33                 DIGIT THREE
(4)   52  03/04   64  34                 DIGIT FOUR
(5)   53  03/05   65  35                 DIGIT FIVE
(6)   54  03/06   66  36                 DIGIT SIX
(7)   55  03/07   67  37                 DIGIT SEVEN
(8)   56  03/08   70  38                 DIGIT EIGHT
(9)   57  03/09   71  39                 DIGIT NINE
(:)   58  03/10   72  3A                 COLON
(;)   59  03/11   73  3B                 SEMICOLON
(<)   60  03/12   74  3C                 LESS-THAN SIGN, LEFT ANGLE BRACKET
(=)   61  03/13   75  3D                 EQUALS SIGN
(>)   62  03/14   76  3E                 GREATER-THAN SIGN, RIGHT ANGLE BRACKET
(?)   63  03/15   77  3F                 QUESTION MARK
(@)   64  04/00  100  40                 COMMERCIAL AT SIGN
(A)   65  04/01  101  41                 CAPITAL LETTER A
(B)   66  04/02  102  42                 CAPITAL LETTER B
(C)   67  04/03  103  43                 CAPITAL LETTER C
(D)   68  04/04  104  44                 CAPITAL LETTER D
(E)   69  04/05  105  45                 CAPITAL LETTER E
(F)   70  04/06  106  46                 CAPITAL LETTER F
(G)   71  04/07  107  47                 CAPITAL LETTER G
(H)   72  04/08  110  48                 CAPITAL LETTER H
(I)   73  04/09  111  49                 CAPITAL LETTER I
(J)   74  04/10  112  4A                 CAPITAL LETTER J
(K)   75  04/11  113  4B                 CAPITAL LETTER K
(L)   76  04/12  114  4C                 CAPITAL LETTER L
(M)   77  04/13  115  4D                 CAPITAL LETTER M
(N)   78  04/14  116  4E                 CAPITAL LETTER N
(O)   79  04/15  117  4F                 CAPITAL LETTER O
(P)   80  05/00  120  50                 CAPITAL LETTER P
(Q)   81  05/01  121  51                 CAPITAL LETTER Q
(R)   82  05/02  122  52                 CAPITAL LETTER R
(S)   83  05/03  123  53                 CAPITAL LETTER S
(T)   84  05/04  124  54                 CAPITAL LETTER T
(U)   85  05/05  125  55                 CAPITAL LETTER U
(V)   86  05/06  126  56                 CAPITAL LETTER V
(W)   87  05/07  127  57                 CAPITAL LETTER W
(X)   88  05/08  130  58                 CAPITAL LETTER X
(Y)   89  05/09  131  59                 CAPITAL LETTER Y
(Z)   90  05/10  132  5A                 CAPITAL LETTER Z
([)   91  05/11  133  5B                 LEFT SQUARE BRACKET
(\)   92  05/12  134  5C                 REVERSE SOLIDUS (BACKSLASH)
(])   93  05/13  135  5D                 RIGHT SQUARE BRACKET
(^)   94  05/14  136  5E                 CIRCUMFLEX ACCENT
(_)   95  05/15  137  5F                 LOW LINE, UNDERLINE
(`)   96  06/00  140  60                 GRAVE ACCENT
(a)   97  06/01  141  61                 SMALL LETTER a
(b)   98  06/02  142  62                 SMALL LETTER b
(c)   99  06/03  143  63                 SMALL LETTER c
(d)  100  06/04  144  64                 SMALL LETTER d
(e)  101  06/05  145  65                 SMALL LETTER e
(f)  102  06/06  146  66                 SMALL LETTER f
(g)  103  06/07  147  67                 SMALL LETTER g
(h)  104  06/08  150  68                 SMALL LETTER h
(i)  105  06/09  151  69                 SMALL LETTER i
(j)  106  06/10  152  6A                 SMALL LETTER j
(k)  107  06/11  153  6B                 SMALL LETTER k
(l)  108  06/12  154  6C                 SMALL LETTER l
(m)  109  06/13  155  6D                 SMALL LETTER m
(n)  110  06/14  156  6E                 SMALL LETTER n
(o)  111  06/15  157  6F                 SMALL LETTER o
(p)  112  07/00  160  70                 SMALL LETTER p
(q)  113  07/01  161  71                 SMALL LETTER q
(r)  114  07/02  162  72                 SMALL LETTER r
(s)  115  07/03  163  73                 SMALL LETTER s
(t)  116  07/04  164  74                 SMALL LETTER t
(u)  117  07/05  165  75                 SMALL LETTER u
(v)  118  07/06  166  76                 SMALL LETTER v
(w)  119  07/07  167  77                 SMALL LETTER w
(x)  120  07/08  170  78                 SMALL LETTER x
(y)  121  07/09  171  79                 SMALL LETTER y
(z)  122  07/10  172  7A                 SMALL LETTER z
({)  123  07/11  173  7B                 LEFT CURLY BRACKET, LEFT BRACE
(|)  124  07/12  174  7C                 VERTICAL LINE, VERTICAL BAR
(})  125  07/13  175  7D                 RIGHT CURLY BRACKET, RIGHT BRACE
(~)  126  07/14  176  7E                 TILDE
Title: Re: Matrix problem
Post by: PaulRB on Apr 14, 2019, 05:08 pm
OK, I copied the font data from your old sketch and re-organised it into a single array, with the characters appearing in the exact same order as the ASCII set above.
Code: [Select]

byte font[][6] = {
  {B11111111, B11111111, B11111111, B11111111, B11111111, B11111111 },    // SPACE ' '
  {B11111111, B11111111, B00000101, B11111111, B11111111, B11111111 },    // EXCLAMATION MARK '!'
  {B11111111, B11111111, B11111111, B11111111, B11111111, B11111111 },    // QUOTATION MARK '"'
  {B11111111, B11111111, B11111111, B11111111, B11111111, B11111111 },    // NUMBER SIGN '#'
  {B11111111, B10011101, B01101101, B00000001, B01101101, B01110011 },    // DOLLER '$'
  {B11111111, B10111011, B11110111, B11101111, B11011111, B10111011 },    // PERCENT '%'
  {B11111111, B10010011, B01101101, B01100101, B10011011, B11110101 },    // AND '&'
  {B11111111, B11111111, B11111111, B11111111, B11111111, B11111111 },    // APOSTROPHE '''
  {B11111111, B11111111, B11111111, B10000011, B01111101, B11111111 },    // BRACKET START '('
  {B11111111, B11111111, B01111101, B10000011, B11111111, B11111111 },    // BRACKET END ')'
  {B11111111, B10111011, B11010111, B11101111, B11010111, B10111011 },    // MULTIPLY '*'
  {B11111111, B11101111, B11101111, B10000011, B11101111, B11101111 },    // PLUS '+'
  {B11111111, B11111111, B11111111, B11111111, B11111111, B11111111 },    // COMMA ','
  {B11111111, B11101111, B11101111, B11101111, B11101111, B11101111 },    // MINUS '-'  
  {B11111111, B11111111, B11111111, B11111111, B11111111, B11111111 },    // PERIOD '.'
  {B11111111, B11111011, B11110111, B11101111, B11011111, B10111111 },    // DIVIDE '/'
  {B11111111, B10000011, B01111101, B01111101, B01111101, B10000011 },    // NUMBER 0
  {B11111111, B11111111, B10111101, B00000001, B11111101, B11111111 },
  {B11111111, B10111001, B01110101, B01101101, B01011101, B10111101 },
  {B11111111, B10111011, B01111101, B01101101, B01101101, B10010011 },
  {B11111111, B11100111, B11010111, B10110111, B00000001, B11110111 },
  {B11111111, B00011011, B01101101, B01101101, B01101101, B01110011 },
  {B11111111, B10010011, B01101101, B01101101, B01101101, B11110011 },
  {B11111111, B01111111, B01110001, B01101111, B01011111, B00111111 },
  {B11111111, B10010011, B01101101, B01101101, B01101101, B10010011 },
  {B11111111, B10011111, B01101101, B01101101, B01101101, B10010011 },    // NUMBER 9
  {B11111111, B11111111, B11111111, B10111011, B11111111, B11111111 },    // COLON ':'
  {B11111111, B11111111, B11111111, B11111111, B11111111, B11111111 },    // SEMICOLON ';'
  {B11111111, B11111111, B11110111, B11101011, B11011101, B11111111 },    // LESS THAN '<'
  {B11111111, B11010111, B11010111, B11010111, B11010111, B11111111 },    // EQUAL '='
  {B11111111, B11111111, B11011101, B11101011, B11110111, B11111111 },    // GREATER THAN '>'
  {B11111111, B10111111, B01111111, B01110101, B01101111, B10011111 },    // QUESTION MARK '?'
  {B11111111, B11111111, B11111111, B11111111, B11111111, B11111111 },    // AT SIGN '@'
  {B11111111, B10000001, B01110111, B01110111, B01110111, B10000001 },     // LETTER A
  {B11111111, B00000001, B01101101, B01101101, B01101101, B10010011 },
  {B11111111, B10000011, B01111101, B01111101, B01111101, B10111011 },
  {B11111111, B00000001, B01111101, B01111101, B01111101, B10000011 },
  {B11111111, B00000001, B01101101, B01101101, B01101101, B01111101 },
  {B11111111, B00000001, B01101111, B01101111, B01101111, B01111111 },
  {B11111111, B10000011, B01111101, B01111101, B01110101, B10110011 },
  {B11111111, B00000001, B11101111, B11101111, B11101111, B00000001 },
  {B11111111, B11111111, B01111101, B00000001, B01111101, B11111111 },
  {B11111111, B11111011, B11111101, B01111101, B00000011, B01111111 },
  {B11111111, B00000001, B11101111, B11010111, B10111011, B01111101 },
  {B11111111, B00000001, B11111101, B11111101, B11111101, B11111101 },
  {B11111111, B00000001, B10111111, B11001111, B10111111, B00000001 },
  {B11111111, B00000001, B11011111, B11101111, B11110111, B00000001 },
  {B11111111, B10000011, B01111101, B01111101, B01111101, B10000011 },
  {B11111111, B00000001, B01101111, B01101111, B01101111, B10011111 },
  {B11111111, B10000011, B01111101, B01110101, B01111011, B10000101 },
  {B11111111, B00000001, B01101111, B01100111, B01101011, B10011101 },
  {B11111111, B10011101, B01101101, B01101101, B01101101, B01110011 },
  {B11111111, B01111111, B01111111, B00000001, B01111111, B01111111 },
  {B11111111, B00000011, B11111101, B11111101, B11111101, B00000011 },
  {B11111111, B00000111, B11111011, B11111101, B11111011, B00000111 },
  {B11111111, B00000001, B11111011, B11100111, B11111011, B00000001 },
  {B11111111, B00111001, B11010111, B11101111, B11010111, B00111001 },
  {B11111111, B00011111, B11101111, B11110001, B11101111, B00011111 },
  {B11111111, B01111001, B01110101, B01101101, B01011101, B00111101 },     // LETTER Z
  {B11111111, B11111111, B11111111, B11111111, B11111111, B11111111 },    // LEFT SQUARE BRACKET '['
  {B11111111, B11111111, B11111111, B11111111, B11111111, B11111111 },    // BACKSLASH '\'
  {B11111111, B11111111, B11111111, B11111111, B11111111, B11111111 },    // RIGHT SQUARE BRACKET ']'
  {B11111111, B11011111, B10111111, B01111111, B10111111, B11011111 },    // POWER '^'
  {B11111111, B11111111, B11111111, B11111111, B11111111, B11111111 },    // UNDERSCORE '_'
  {B11111111, B11111111, B11111111, B11111111, B11111111, B11111111 },    // GRAVE ACCENT '`'
  {B10000001, B01111111, B01000011, B11111111, B10000011, B11111111 },    // LETTER a
  {B10000001, B01111111, B01000011, B01111111, B10011111, B10111111 },
  {B11111111, B10000011, B11111111, B10000001, B01111111, B01000011 },
  {B11111111, B10000011, B11111111, B10000011, B01111111, B01111111 },
  {B10000111, B01111111, B01111111, B10000011, B11100111, B11101111 },
  {B11111111, B11101001, B11001001, B00100111, B00101111, B01111111 },
  {B00011111, B01111111, B01111111, B11111111, B10011111, B01111111 },
  {B11100111, B11101111, B11100111, B11101111, B11100111, B00001111 },
  {B01001111, B01111111, B10000001, B01111111, B01111111, B10011111 },
  {B11111111, B10000011, B11111111, B10000011, B01111111, B01111111 },
  {B10000111, B01111111, B01111111, B10000011, B11100111, B11101111 },
  {B11111111, B00000001, B11111101, B11111101, B11111101, B11111101 },
  {B11111111, B00000001, B10111111, B11001111, B10111111, B00000001 },
  {B11111111, B00000001, B11011111, B11101111, B11110111, B00000001 },
  {B11111111, B10000011, B01111101, B01111101, B01111101, B10000011 },
  {B11111111, B00000001, B01101111, B01101111, B01101111, B10011111 },
  {B11111111, B10000011, B01111101, B01110101, B01111011, B10000101 },
  {B11111111, B00000001, B01101111, B01100111, B01101011, B10011101 },
  {B11111111, B10011101, B01101101, B01101101, B01101101, B01110011 },
  {B11111111, B01111111, B01111111, B00000001, B01111111, B01111111 },
  {B11111111, B00000011, B11111101, B11111101, B11111101, B00000011 },
  {B11111111, B00000111, B11111011, B11111101, B11111011, B00000111 },
  {B11111111, B00000001, B11111011, B11100111, B11111011, B00000001 },
  {B11111111, B00111001, B11010111, B11101111, B11010111, B00111001 },
  {B11111111, B00011111, B11101111, B11110001, B11101111, B00011111 },
  {B11111111, B01111001, B01110101, B01101101, B01011101, B00111101 },    // LETTER z
  {B11111111, B11111111, B11111111, B11111111, B11111111, B11111111 },    // LEFT BRACE '{'
  {B11111111, B11111111, B11111111, B11111111, B11111111, B11111111 },    // VERTICAL LINE, '|'
  {B11111111, B11111111, B11111111, B11111111, B11111111, B11111111 },    // RIGHT BRACE '}'
  {B11111111, B11110111, B11101111, B11110111, B11111011, B11110111 },    // APPROXIMATELY '~'
  {B11111111, B11111111, B11000011, B10111101, B01010110, B01111010 },    // HAPPY FACE '[]'
  {B01111010, B01010110, B10111101, B11000011, B11111111, B11111111 },
  {B11111111, B11111111, B11000011, B10111101, B01011010, B01110110 },    // SAD FACE '{}'
  {B01110110, B01011010, B10111101, B11000011, B11111111, B11111111 },
  {B11111111, B11111111, B10001111, B00000111, B00000011, B10000001 },    // HEART ',.'
  {B10000001, B00000011, B00000111, B10001111, B11111111, B11111111 }
};

Can you check this please? Have I got the sequence exactly the same as the ASCII set, not missing or inserting any?
Title: Re: Matrix problem
Post by: bogdan666 on Apr 14, 2019, 08:18 pm
they are the same, except for happy face, sad face and the heart, which we don't care too much.
Title: Re: Matrix problem
Post by: PaulRB on Apr 14, 2019, 11:42 pm
Thanks, lets pick up again tomorrow.
Title: Re: Matrix problem
Post by: bogdan666 on Apr 17, 2019, 02:38 pm
No problem, my bench power supply is broken and i can't seem to find what's wrong with it, so i am distracted and it's kinda my priority because i feel like without hands.
Title: Re: Matrix problem
Post by: PaulRB on Apr 17, 2019, 09:39 pm
Sorry to hear that, hope you get it fixed.

I've attempted to get the text scrolling:
Code: [Select]
#include <SPI.h>
#include "font.h"

#define LATCH 10
#define MULTIPLEX_PERIOD 1
#define SCROLL_PERIOD 200

SPISettings shiftRegister(10000000UL, LSBFIRST, SPI_MODE0);

unsigned int image[8];

char message[] = "BOGODAN666   ";

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(128 >> currRow); //Send a byte indicating which row to light
    SPI.transfer(highByte(image[currRow])); //Send the required pattern for this row of the matrix
    SPI.transfer(lowByte(image[currRow]));
    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 scrollDisplay() {
  static unsigned long lastUpdate; //time when matrix was last scrolled
  static byte charPos;
  static byte dataPos;
  unsigned long millisNow = millis(); //Get time now
  if (millisNow - lastUpdate >= SCROLL_PERIOD) { //Is it time to scroll the matrix?
    lastUpdate = millisNow; //Record time the matrix was scrolled
    byte newData = font[message[charPos] - ' '][dataPos]; //Get new character pattern to be scrolled onto matrix
    for (byte row = 0; row < 8; row++) {
      image[row] <<= 1; //Scroll this line of the matrix
      bitWrite(image[row], 0, bitRead(newData, row)); //add in the bit of the character pattern to this row
    }
    if (++dataPos > 6) { //Move to next column of character pattern
      dataPos = 0;
      if (++charPos >= strlen(message)) charPos = 0; //Move to next character of message
    }
  }
}

void loop() {
  multiplexDisplay();
  scrollDisplay();
}


I put the font array from the last post into the "font.h" tab. To make the new tab in your IDE, press ctrl-shift-N and enter the name "font.h". Then paste the big array from the previous post into the new tab.
Title: Re: Matrix problem
Post by: bogdan666 on Apr 18, 2019, 03:32 pm
Ok, weird things are happening, the text begin to scroll from the middle, and is upside down.
Title: Re: Matrix problem
Post by: PaulRB on Apr 18, 2019, 05:53 pm
the text begin to scroll from the middle
Can you explain more or post a youtube vid?

and is upside down.
Change this line as below:
Code: [Select]
      bitWrite(image[row], 0, bitRead(newData, 7 - row)); //add in the bit of the character pattern to this row
Title: Re: Matrix problem
Post by: bogdan666 on Apr 18, 2019, 08:24 pm
the change for the flip worked, what i meant by: it starts from the middle was this
the letter B starts from the 8th column and moves towards left
after it reaches column 1 it goes to column 16th and goes towards left
and it fades in column 9
basically, if i break my matrix in half, in order to make it work i have to put the right matrix in front of the left matrix. I think that the the data from 1st 595 should go to 2nd, and the data from 2nd 595 should go to 1st.
Title: Re: Matrix problem
Post by: PaulRB on Apr 18, 2019, 09:19 pm
the letter B starts from the 8th column and moves towards left
after it reaches column 1 it goes to column 16th and goes towards left
and it fades in column 9
basically, if i break my matrix in half, in order to make it work i have to put the right matrix in front of the left matrix. I think that the the data from 1st 595 should go to 2nd, and the data from 2nd 595 should go to 1st.
And you did not see the same thing with the scrolling arrow? Did you change the wiring? If not, try swaping the highByte() and lowByte() functions again.
Title: Re: Matrix problem
Post by: bogdan666 on Apr 19, 2019, 03:03 pm
With the arrow it worked perfectly, for this i changed the highbyte and lowbyte and it works. Only problem is that the matrix starts with every led on, then as the letters scrolls they turn off(the unwanted leds), so at the 2nd time the text scrolls it's ok. Question, how does the code knows which is letter "B" , because i see no way of knowing this? the font.h tab has nowhere written that "this" is letter B.
Title: Re: Matrix problem
Post by: PaulRB on Apr 19, 2019, 05:58 pm
Change this line
Code: [Select]
unsigned int image[8] = {~0, ~0, ~0, ~0, ~0, ~0, ~0, ~0};

The code knows where to find B in the font array because the array is in ASCII order. Characters are stored in the sketch as ASCII codes. But the font array starts with the space character at index zero, and the ASCII code for a space is 32. So when the code goes to find B in the array, it first subtracts the code for a space (32) from the code for B (66) giving an index of 66 - 32 = 34.
Title: Re: Matrix problem
Post by: bogdan666 on Apr 19, 2019, 10:19 pm
ok, i get it, also very tidy since the fonts are in a different tab
Title: Re: Matrix problem
Post by: PaulRB on Apr 20, 2019, 07:16 am
So, I think we got to the functions you wanted? Do you have any other questions about how the code works? Do you still think the matrix is bright enough? Can you post a youtube video? I would like to see it.
Title: Re: Matrix problem
Post by: bogdan666 on Apr 20, 2019, 01:40 pm
link to video (https://www.youtube.com/watch?v=jj_AzT_fExs)


Yes, it works perfectly, now obviously in real life it looks better than on camera, i still have to test the current draw from leds and settle to a value, i can make it a bit brighter i think, the resistors on the right are shorted(it was easier for me to cancel them)
About the code, i understand how it works now, i will play with it more to see what changes in order to understand it better. Paul i cannot thank you enough, you have been very patient with me and helped me a lot, the world needs more people like you. As you can see, i have 2 potentiometers and one button soldered on the board, so i am guessing i could do the speed of scrolling with one potentiometer, and with the button, maybe go to next text
Title: Re: Matrix problem
Post by: PaulRB on Apr 20, 2019, 04:01 pm
I can't see the resistors on the columns. What value are they? You need to limit the current to around 2mA per led, because of the 35mA limit of the individual '595 pins. So these resistors need to be around 1.5K.

Have you got room for 8 transistors where those shorted row resistors are now? You could use 8 bc337 transistors as emitter-followers. No base resistors would be needed. Then you could use lower resistors on the columns. You could allow 8mA per led, 4 times brighter than the current circuit. The column resistors could be much lower at (5 - 2 - 0.7) / 0.008 = 288R
Title: Re: Matrix problem
Post by: bogdan666 on Apr 20, 2019, 08:40 pm
The resistors are on the back side, 1.5k, i didn't have much room on front, as for the transistors, maybe if i remove the resistors i could get them in there, it would be very crowded
Title: Re: Matrix problem
Post by: PaulRB on Apr 20, 2019, 09:43 pm
The transistors are only slightly larger than those resistors, but they have 3 leads rather than 2. You would connect the base lead to the '595 output pin, the emitter to the led row and the collector to 5V.
Title: Re: Matrix problem
Post by: bogdan666 on Apr 21, 2019, 07:29 am
ok, i will try to get them on the board next week, but i will use 2n2222, they are similar, and i have a bunch of them
Title: Re: Matrix problem
Post by: PaulRB on Apr 21, 2019, 08:04 am
2n2222 is fine. Before you change the column resistors, add a transistor to one row and check that the display works as before. Then add the other 7 transistors and test again. Finally, change the column resistors to 300R or 330R.
Title: Re: Matrix problem
Post by: bogdan666 on Apr 21, 2019, 08:36 am
ok, i will, happy Easter Paul.