Pages: 1 [2] 3 4 5   Go Down
Author Topic: Shift registers and LED's  (Read 8992 times)
0 Members and 1 Guest are viewing this topic.
Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 524
Posts: 26420
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

MR must be held High, making it low clears the outputs.
OE must be held Low, making it high disables the output drivers.
High Power pin is either called Vcc or Vdd. Connects to 5V or 3.3V typically.
Low Power pin is called Vss.  Connects to Ground typically.


* 74HC595-8x8LED.jpg (95.22 KB, 960x720 - viewed 85 times.)
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Canberra Australia
Offline Offline
God Member
*****
Karma: 11
Posts: 514
Hardcore Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks again for that Crossroads.  I have got some ULN2803's coming on "the slow boat from China" so when they arrive I will put it all together and see how I go.
 Pedro.
Logged


Canberra Australia
Offline Offline
God Member
*****
Karma: 11
Posts: 514
Hardcore Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I finally received the ULN2803 arrays to complete the 8 x 8 matrix and after connecting it all up have eventually got a diagonal  row of LED's lighting from left to right, top to bottom. Not knowing anything about the coding in the test array
 ({0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80}; I do not really know where to go from here… (now there's something new hey )   smiley-grin
Does it look like it is  operating as it should and if so how do I "move forward" as they say in the classics. Thanks again Pedro.
 
Logged


Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 524
Posts: 26420
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Good news!
The array would indeed make a diagonal line.

What is it you wanted to display? You could have static 'pictures' defined, and every so often switch to a new one. Maybe based on time, maybe when a button is pushed, maybe when a serial message was received. You could have the display slowly scroll left or right, or up & down. Put what else you want displayed in a larger array and read that data out and write it to the display array. Or make up what is being displayed on the fly.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Canberra Australia
Offline Offline
God Member
*****
Karma: 11
Posts: 514
Hardcore Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the good news Crossroads. I am glad that my perseverance  with sorting out the wiring paid off, I love it when a plan comes together. I suppose that I want to try and understand how to use your code to perform simple displays so that I can start to understand how the arrays control the matrix. For example with the 3 x 3 x 3 cube that you helped me with, I found some PatternTable code that I found useful and after much head scratching and rewiring, worked out which part of the array was controlling each LED.
i.e.  -  in this array  {B100, B000, B000, B000, B000, B000, B000, B000, B000} ;
on my cube this would turn on the first LED on the top level and I also deduced that the first nine numeric's controlled the nine LED's on the top level, the 10th to 18th  numeric's the center level LED's etc. and obviously a one was on and zero off.
I know that it's not rocket science, but to me it showed me how to use the code to control the cube in a much simpler way that turning everything on and off one by one, and that using arrays is the way to go.  I therefore would like to develop a similar understanding of this matrix code so that I can start to control simple things like individual control of each LED, scrolling lights etc and eventually static and scrolling symbols and text.  I don't even recognize the array that you have used here;
byte dataArray[]= {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};  Thanks again for your help in trying to educate me Pedro.
« Last Edit: August 07, 2012, 06:22:05 pm by Pedro147 » Logged


Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 524
Posts: 26420
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

"I don't even recognize the array that you have used here;
byte dataArray[]= {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80}; "

Okay, so rewrite it like the cube display then:
B00000001, B00000010, B00000100, B00001000, B00010000, B00100000, B01000000, B10000000
Same data, different number format. Lot easer to follow than:
Decimal, 1,2,4,6,16,32,64,128 - who can tell where those bits are going to end up? Hex (0x01) and Binary (B00000001) are a lot easier to visualize.

In this case, each group represents 1 column of data, and you have 8 columns representing the matrix.
B00000001, B00000010, B00000100, B00001000, B00010000, B00100000, B01000000, B10000000
column 0,    column 1,     column 2,     column 3,     column 4,     column 5,    column 6,      column 7

As wired to the shift registers & matrix:
cccccccc
76543210

10000000
01000000
00100000
00010000
00001000
00000100
00000010
00000001    

So now you have this 8x8 set of data and it up to you to decide how you will fill that set up and when you will change/update it.  Content, that's always the killer smiley
We already have blink-without-delay going to determine when the display is refreshed.
Add a second one at different time interval, and shift the data in the array:
7 goes into a temporary copy, 6 goes into 7, 5 goes into 6, 4 into 5, 3 into 4, 2 into 3, 1 into 2, 0 into 1, and the temporary copy goes into 0. Now the display becomes:
1st shift   2nd shift  3rd shift
01000000  00100000  00010000
00100000  00010000  00001000
00010000  00001000  00000100
00001000  00000100  00000010
00000100  00000010  00000001
00000010  00000001  10000000
00000001  10000000  01000000
10000000  01000000  00100000

You see how the data moves right and then wraps around?
So that's one thing you can do, and then build other features from there.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Canberra Australia
Offline Offline
God Member
*****
Karma: 11
Posts: 514
Hardcore Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for that. I'll play around with those type of arrays if I can work out how to put them into your code. Yes it did perplex me when I saw  that
" byte dataArray[]= {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 " in your original code you gave me because straight after it you had some in the  B00000001 format but it was "commented out"



#include <SPI.h> // bring in SPI library

byte SSanodes = 9; // output latch for anodes shift register.  Can be any pin except 10,11,12,13.
byte SScathodes = 10; // output latch for cathodes shift register.  Pin D10 needs to be an output for SPI.
byte dataArray[]= {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};  // load up some initial data
// dataArray[0] = B00000001
// dataArray[1] = B00000010
// dataArray[2] = B00000100
// dataArray[3] = B00001000
// dataArray[4] = B00010000
// dataArray[5] = B00100000
// dataArray[6] = B01000000
// dataArray[7] = B10000000

I think that it's time for me to really knuckle down and get a grasp on how all this coding is put together. Thanks again Crossroads and I'll let you know how I go, Pedro.
Logged


Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 524
Posts: 26420
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The commented out part was to show you what the initial data would look like.
dataArray [ x ] represents one column of data, the columns are 0 to 7.  Or perhaps 7 to 0. You can make all the data 0 except for 1 and see how your display actually relates to the array data.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Canberra Australia
Offline Offline
God Member
*****
Karma: 11
Posts: 514
Hardcore Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes I am starting to see how it works. I had a play around with it last night and managed to make a diagonal cross and the letter H. Now there’s progress   smiley-lol
I have a lot of written material about all things Arduino, but can you recommend anything in particular that I read as there is so much information on Arduino in general that it’s hard to know where to start. Thinking in three dimensions with the cubes and two dimensions with data moving in, down and across with the matrix is certainly taxing my intellect I can tell you. Sometimes I’m flat out thinking in one dimension.
Logged


Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 524
Posts: 26420
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I struggle with the same.  So much of what can be found for examples is like uncommented cryptic C commands, hard to follow or to tell what it does.
And then they go into classes and functions and libraries and .cpp files and .h files, and its late at night & my eyes just glaze over.
Get some basic stuff working, ask questions in the forum.
I downloaded a book
"Thinking in C++ Vol 1 - 2nd Edition_bumatek.pdf"
"Thinking in C++ Vol 2 - 2nd Edition_bumatek.pdf"
but didn't get very far reading it yet.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Canberra Australia
Offline Offline
God Member
*****
Karma: 11
Posts: 514
Hardcore Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I must admit that I am a tad inpatient and want to learn how to do what I want to do asap… a bad trait on my behalf  smiley-lol After having a good look at how the arrays for anodes and cathodes generated "pixels" I am confidently turning on any combination of LED's in a static situation so now I will try and tackle some dynamic movement and eventually some scrolling text. I had a look at the Arduino Cookbook and it looks well written so I think that I'll just refer to it when I stop moving forward with all this. Thanks again for the help and inspiration and have a good week, Pedro
Logged


Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 524
Posts: 26420
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The movement is just updating the display array.
One thing you can do is create a larger array, say 8 x 80, 640 bytes used. So that will hold 10 'frames' stuff to be displayed.
Then every so often (250ms? 4 updates a second?) copy the 8 frames into the display array.
Conceptually:
Code:
if (250mS elapsed){
masterArrayPointer = masterArrayPointer+1
  for (x = 0 to 7){
  displayArray[x] = master Array[masterArrayPointer + x]
  }
}
Have to do some checking at the end for a smooth wrap around, or just let the end of the masterArray 'slide off' to the left and start over.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Canberra Australia
Offline Offline
God Member
*****
Karma: 11
Posts: 514
Hardcore Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

So basically in an 8 x 80 array  it's like 10 frames of film where each object changes its position from one frame to the next creating the movement. The "if" and "for" command changes the data being displayed by moving sequentially through the frames every 250 ms. This can be used to say scroll through a word , phrase or any simple graphic image. I'll definitely have to bite the bullet and start using these two commands (if and for)  and make more use of arrays etc rather than relying on the simple methods I have been using. Oh well the world is my oyster better go and hit the books over the weekend and thanks for the explanation. smiley-cool
Logged


Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 524
Posts: 26420
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes.
The 80 columns can be scrolled thru 8 at a time, so a whole new frame comes in, or 1 column at a time so 1 frame gets pushed a column at a time as a new one comes in.
The next frame to be scrolled in can also be pulled from PROGMEM so you really just need 2 frames in SRAM. As the final column gets shifted into the display frame, the next one frame gets pulled from PROGMEM (the flash memory) and put into the array in place of the one that was just shifted out.
Thus you can have scrolling messages as long as you want and not be limited by the meager SRAM size of an Uno.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Canberra Australia
Offline Offline
God Member
*****
Karma: 11
Posts: 514
Hardcore Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I would just like to verify that I am thinking about this the right way. I assume that I am because it works, but stranger things have happened.  To generate this display  for the number 2; please refer to the attached Diagram 1.

 Using this code;

 byte dataArray

 B00000000, B00011000, B00100100, B00001000, B00010000, B00100000, B00111100,  B00000000

 byte cathodePins

 B00000000, B01000000, B00100000, B00010000, B00001000, B00000100, B00000010, B00000000


Am I reasoning correctly in thinking that B00011000  in byte dataArray is indicating C4 and C5 and that B01000000  in byte cathodePins is indicating R2 thus lighting LED's in C4 / R2 and
C5 / R2  and similairly all the "pairs" of  byte dataArray and byte cathodePins data sets?

As I said it works but something tells me that I should be inputting it in a  "two dimensional array" like the one you  indicated;

 dataArray[0] = B00000001
 dataArray[1] = B00000010
 dataArray[2] = B00000100
 dataArray[3] = B00001000
 dataArray[4] = B00010000
 dataArray[5] = B00100000
 dataArray[6] = B01000000
 dataArray[7] = B10000000

but I cannot quite work out how to use this array because if for example I worked out how to put it in the byte dataArray section of code, what do I put into the byte catodePins section, the same array? And although I have tried various things I haven't been successful.

I hope that my explanation makes sense, thanks Pedro.


* Diagram 1.doc (31 KB - downloaded 21 times.)
Logged


Pages: 1 [2] 3 4 5   Go Up
Jump to: