Understanding Shift Registers Version 2.0

I haven't posted here in forever cause I've been busy with college, but i have some free time, and some extra LEDs so i want to create an 8x10 LED matrix as a portrait piece for my apartment wall with my Arduino. I understand how to solder the LEDs in parallel so they share a common anode and cathode, BUT, i am interested in using this shift register shield (EZ-Expander) and I'm not exactly sure how i would use it to specify individual LEDs in the matrix to create say raindrops, or other shapes. He says that he has a library that makes it easier to address the pins on the shift registers so that instead of using the

shiftOut

method, its a modified version of

digitalWrite

so you would address an LED by writing the command

expander.digitalWrite {1, HIGH}

in order to turn on an individual LED. the thing is i don't think this is going to work if i want to address individual LED's within the matrix. He said you can still operate the Shift Registers manually by using the shiftOut command, and since they are connected on pins 8, 12, and 13 like in the tutorials it should be pretty simple.

But, even if the regular method is the way to go with this shield, (which is nice since it keeps all the circuitry compact) i still don't understand the shiftOut command in the first place, or at least in the Arduino Development Environment. I used this link Conductive Resistance » Blog Archive » Interactive 595 Shift Register Simulator to understand how the 595 shift register works but those aren't the ones used in the Expander. So i really would appreciate any help to explain how a REALLY simple example of how to use the bits, and shiftOut command with the Arduino IDE.

Thanks,

Ryan

I understand how to solder the LEDs in parallel so they share a common anode and cathode,

I hope you don't, LEDs should never be connected in parallel like this.

A shift register is not a matrix. For how a matrix works see:-
http://www.thebox.myzen.co.uk/Workshop/LED_Matrix.html

Shift registers are just a way of squeezing lots of data out of a couple of pins. In the end they present as parallel data. Then what you do with the outputs is up to you.

To control an individual LED all you do is to set a bit in the output bit pattern and write the whole bit pattern out again.
All that his modified expander.digitalWrite {1, HIGH} is doing is setting a bit in the byte that is going to be outputted to the shift register. You can do this yourself with the bitWrite() function.

I know that a shift register isn't a matrix. What i don't understand is how i would use a shift register to control a 8x10 LED matrix such as this. In addition when i said that i wired them in parallel i meant i wired them they way specified in the diagram via the link you posted Arduino Workshop
I didn't realize that what i said was incorrect. how should i describe this wiring pattern?
and so to control an 8x10 matrix like this with a shift register, i would do exactly like in the link.

but how would i wire up the driver with the shift register? the diagram posted explanation isn't that great, plus he says that whether its a common anode or cathode column defines how you can drive it.

When using a shift register to drive a matrix you use some of the pins for driving the rows and some for the columns. As you have seen from my web page there will need to be drivers on either or both of the row / columns. Depending on the pattern you drive them at. The simplest way is to have a shift register with a greater pull down or current sink capacity like the TPIC6B595 that can sink up to 150mA and use a lesser shift register like the 74HC595 or 74HCT595 to source the current. Driving it with the walking bit pattern on the columns.
Failing that the you can add a darlington driver to the column pins like the ULN2803.

how should i describe this wiring pattern?

Just as "wired in a matrix" what you said implied that the anode and cathode of two LEDs were wired together.

he says that whether its a common anode or cathode column defines how you can drive it.

It will make a difference to things like RGB LEDs because then with say a common anode you have to put your walking bit onto the common anode line and so you will probably need a high sided switch or a current source driver like a PNP transistor or p-channel FET.

Ok, so i know this seems like a stupid question but source is where the current comes from, and sink is where it goes, correct? And the reason you use the shift register to sink current is so that the current coming back into the Arduino isn't harmful to it.

The only problem i see now is that the way my matrix is arranged so that if the grid is 8 wide by 10 long like this (each x is an LED with a little divider thing)

x/x/x/x/x/x/x/x/------- + positive leads come out in the rows
x/x/x/x/x/x/x/x/
x/x/x/x/x/x/x/x/
x/x/x/x/x/x/x/x/
x/x/x/x/x/x/x/x/
x/x/x/x/x/x/x/x/
x/x/x/x/x/x/x/x/
x/x/x/x/x/x/x/x/
x/x/x/x/x/x/x/x/
x/x/x/x/x/x/x/x/
/
/

  • negative leads come out in the columns

and after i finished making this diagram i realized that your grid is set up exactly the same way. I'm not used to reading LED schematic symbols.
Anyways, so just to clarify i would need to have 2 shift registers to control this matrix? i like the Row Scanning method, so i would put the high powered shift register with the output pins controlling the rows (or anodes), to source the current, and then have the other shift register with its outputs connected to the cathodes, to source the current, in addition to resistors specific to my LEDs correct?

and now that i look at the data sheets for both shift registers the only can handle 8 bits of data, how can a control 10 rows with an 8 bit shift register?

but source is where the current comes from, and sink is where it goes, correct?

Yes correct. :slight_smile:

And the reason you use the shift register to sink current is so that the current coming back into the Arduino isn't harmful to it.

Yes that current actually flows through the shift register (or driver) to ground not through the arduino chip because that can't handle more than 40mA without being damaged.

so just to clarify i would need to have 2 shift registers to control this matrix?

No you would need 3. You only get 8 bits per shift register so you need 8 bits for the columns and 10 for the rows so you need 2 shift registers here one of them only uses two of the bits.

i realized that your grid is set up exactly the same way.

:slight_smile: :slight_smile: :slight_smile:

so i would put the high powered shift register with the output pins controlling the rows (or anodes), to source the current,

No the high powered shift register can only sink current it can't source it, so you need it the other way round. This is good anyway because you will have one byte of data per row and just 10 bytes for the whole matrix.

Ok cool. so where does the walking bit come in? which register writes the walking bit and which one supplies the data?

I JUST HAD AN EPIPHANY!

i understand what the walking bit does. it supplies power to the row! so the 2 regular shift registers write the walking bit down the rows to turn on each row to allow the high powered register to latch the data bit ex. 01100110 to turn on whichever LEDs are located in the column with a 1!

BRILLIANT!!

so, now i just need to understand how to write the 10 bit walking bit pattern in the code/ how to wire it up. and how that works with the data pattern written by the high powered register.

Closer, but the other way round.
If you have a power shift register that has to be on the current sinking side and that is where your walking bit should be. This allows all the LEDs in a column to light up at the same time because all the shift register can source is enough to power one LED. The way round you had it would require top side drivers to supply up to 8 LEDs at the same time and the sinking would only be sinking one LED at a time.

now i just need to understand how to write the 10 bit walking bit pattern in the code

Simple an int has 16 bits, start with a value of 1 and do a left shift each time (left shift is done by val = val <<1;)
But remember you only want 8 bits. You need 10 bits of data.

so instead of this matrix being row scanned, it will be column scanned? since the walking bit will be like the second example video on your website? but if the regular shift register can only power 1 led at a time, how would i do patterns like the one in that video? would i use another high powered driver to be able to power multiple ones at once, or use transistors to step up the current?

the regular shift register can only power 1 led at a time,

Yes that is one LED per shift register output. With one column being pulled down only each one of the row shift register pin can light an LED.

So that means that with a regular shift register i would not be able to create complex patterns like the ones displayed in the videos on your site. to do that i would need to step up the current with transistors, or use another driver, right?

So that means that with a regular shift register i would not be able to create complex patterns like the ones displayed in the videos

If they were all three just a "regular" shift register then no you could not drive a matrix as it is commonly known. You could drive it in such a way that there was only one LED on at any one time but that would put up the multiplexing ratio tremendously and the LEDs would appear very dim and it would take a lot of processing power to do it.

You need a driver either on the current sourcing side or the current sinking side to prevent the shift registers from being damaged.

Yes, so to be able to light up multiple LEDs in a row at once, i would need 1 high powered shift register sinking current from the columns, and 2 regular registers sourcing current, correct?

How would i write the code for this, would i just write out 16 bits of data instead of 8 once i had the 2 regular shift registers wired correctly?

i would need 1 high powered shift register sinking current from the columns, and 2 regular registers sourcing current, correct?

Yes that is one solution.

would i just write out 16 bits of data instead of 8

Yes, the other 6 unused outputs would simply “spill their seed in the sand” to quote the Bible.

Ok thanks a bunch, but now that i know how to wire it, i really don’t understand how the coding for the shift registers works.

int rowCount = 0;
byte rowPin[ ] = { 2, 3, 4, 5, 6, 7, 8, 9}; // change these to the pins you use
byte colPin[ ] = { 10, 11, 12, 13, 14, 15, 16, 17}; // note pins 14 to 17 are the analogue pins used in a digital mode
byte displayData [ ] = { B11111111, B10000001, B10111101, B10100101, B10100101, B10111101, B10000001, B11111111 }; // display pattern

void setup(){
// set up the pins as outputs
for(int i = 0;  i<8; i++){
   pinMode(rowPin[i], OUTPUT);
   pinMode(colPin[i], OUTPUT);
  }
// the rest of the stuff in your setup
} // end of setup

void refresh(){
byte tempData;
digitalWrite(colPin[rowCount], LOW); // turn off the LEDs
rowCount ++; // increment to next line
if (rowCount == 8) rowCount = 0; // wrap it round so it only counts 0 to 7
// now set the data on the rows
tempData = displayData[rowCount];
for(int i=0 ; i<8; i++){
   if((tempData & 1) == 0) digitalWrite(rowPin[i], LOW); else digitalWrite(rowPin[i], HIGH);
   }
digitalWrite(colPin[rowCount], HIGH); // turn on the LEDs
} // end of refresh

i really don’t understand what each of these different commands do, and how to apply them to my project.

Ok not sure where you got that code from but it has nothing to do with shift registers. You want to look at the shift out tutorial in the main site.

I got this code from your website Arduino Workshop

this was the code that controls the column scrolling example video on the site.

Yes but like I said it has nothing to do with shift registers, it is a code fragment for running a matrix using the arduino pins. You don't want to do that you want to use a shift register so all the code will be totally different. You have to do the same sort of things but the code you will need to do it through your chosen interface method, the shift register.
So first of all you have to design your circuit. How are you chaining your registers, that is in what order?
This tells you about it:-

Do not put the 1uF capacitor in that is a big error and will damage your arduino but nobody will change it.
So you need to set up a byte for your walking bit and an array of 8 ints for your pattern and shift out one of these pattern ints and the walking bit byte each refresh.

ok, so I've started coding out the patterns, can you tell me if I'm leaning in the right direction?

  int clockpin =
  int datapin =
  int latchpin =
  int clock =
  int reset =
  
  #define square1 {B11111111, B10000001, B10000001, B10000001, B10000001, B10000001, B10000001, B10000001, B10000001, B10000001, B11111111}
  #define square2 {B00000000, B01111110, B01000010, B01000010, B01000010, B01000010, B01000010, B01000010, B01000010, B01111110, B00000000}
  #define square3 {B00000000, B00000000, B00111100, B00100100, B00100100, B00100100, B00100100, B00100100, B00111100, B00000000, B00000000}
  #define square4 {B00000000, B00000000, B00000000, B00011000, B00011000, B00011000, B00011000, B00011000, B00000000, B00000000, B00000000}
  #define space {B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B00000000,}
  
  void setup {
    
  }
  
  void displaypattern

the reason i haven't defined any pins is i haven't ordered any of the shift registers yet, I'm ordering them tonight.