Go Down

Topic: Testing a 8 X 8 led ( R&G ) Matrix (Read 3568 times) previous topic - next topic

Techone

Hi guys;

I just finish to write a program to test my circuit setup. I use 3 74HC595, a 8 X 8 Led ( R & G ) Matrix. I use my ZIF-duino ( http://arduino.cc/forum/index.php/topic,87747.0.html ) to program the chip, remove it and place inside the breadboard circuit. I did have a few issues at first ( the program - Matrix when nuts ), than I got it working. My question is : Can the 74HC595 share the clock signal ? , latch signal ?  . In my program, they are seperated.

Anyway, I am doing my best, I know there are room for improvements.

Here the code and a picture.

Code: [Select]

/*
  byte : 1634
 
  To test one led at a time for a 8 X 8 Matrix
  The circuit use 3 74HC595 to display the led's of the matrix.

  By Serge J Desjardins
  aka techone / tech37
 
  Toronto, Ontario  Canada

  Compile and Tested
*/

const byte datapin[3]={12,11,10};
const byte latchpin[3]={9,8,7};
const byte clockpin[3]={6,5,4};

byte data[3];
byte mask;

void setup()
{
  for (int i=0;i<3;i++)
  {
    pinMode(datapin[i],OUTPUT);
  }
  for (int i=0;i<3;i++)
  {
    pinMode(latchpin[i],OUTPUT);
  }
  for (int i=0;i<3;i++)
  {
    pinMode(clockpin[i], OUTPUT);
  } 
  data[0]=255;
  data[1]=0;
  data[2]=0;
  for (int i=0;i<3;i++)
  {
    digitalWrite(latchpin[i], LOW);
    shiftOut(datapin[i], clockpin[i], LSBFIRST, data[i]);   
    digitalWrite(latchpin[i], HIGH);
  }   
  delay(2000);
   
}

void loop()
{
  data[0]=1;
  for (int y=0;y<8;y++)
  {
    mask=~data[0];
    digitalWrite(latchpin[0], LOW);
    shiftOut(datapin[0], clockpin[0], LSBFIRST, mask);   
    digitalWrite(latchpin[0], HIGH);
    data[1]=1;
    data[2]=1;
    for (int x=0;x<8;x++)
    {
      digitalWrite(latchpin[1], LOW);
      shiftOut(datapin[1], clockpin[1], MSBFIRST, data[1]);   
      digitalWrite(latchpin[1], HIGH);
      digitalWrite(latchpin[2], LOW);
      shiftOut(datapin[2], clockpin[2], MSBFIRST, 0);   
      digitalWrite(latchpin[2], HIGH);   
      delay(1000);
      digitalWrite(latchpin[1], LOW);
      shiftOut(datapin[1], clockpin[1], MSBFIRST, 0);   
      digitalWrite(latchpin[1], HIGH);
      digitalWrite(latchpin[2], LOW);
      shiftOut(datapin[2], clockpin[2], MSBFIRST, data[2]);   
      digitalWrite(latchpin[2], HIGH);
      delay(1000);
      digitalWrite(latchpin[1], LOW);
      shiftOut(datapin[1], clockpin[1], MSBFIRST, data[1]);   
      digitalWrite(latchpin[1], HIGH);
      digitalWrite(latchpin[2], LOW);
      shiftOut(datapin[2], clockpin[2], MSBFIRST, data[2]);   
      digitalWrite(latchpin[2], HIGH);
      delay(1000);
      data[1]=data[1]<<1;
      data[2]=data[2]<<1;     
    }
   data[0]=data[0]<<1;   
  } 

     

nickgammon

Why not use SPI and save yourself some effort? I tried it to good effect here:



Sketch:

Code: [Select]
#include <SPI.h>
#include "pins_arduino.h"  // for the SS define (pin 10)

void setup ()
{
  SPI.begin ();
}  // end of setup

byte c;
void loop ()
{
  c++;
  digitalWrite (SS, LOW);
  SPI.transfer (c);
  digitalWrite (SS, HIGH);
  delay (20);
}  // end of loop


I connected:

Code: [Select]

Arduino     74HC595

SCK  (D13)   SH (11)
MOSI (D11)   DS (14)
SS   (D10)   ST (12)
             /MR  --> Vcc
             /OE  --> Gnd


Quote
Can the 74HC595 share the clock signal ? , latch signal ? 


If you clock out 8 bits, and then raise SS (latch) for one chip and not the other, surely that is all that is required?
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

Techone

SPI.h ? That I have to look it up and experiment on it.  I wonder how I will do it ( using SPI.h ) on a multiple 74HC595's ? It the data, latch and clock are my consern here. My code use a separated data, clock and latch for each chip.  I know the /MR goe to Reset of the Ardiuno, and the /CE goes to GND.  My question is : whish one can be commun for all the chip ( data ? Latch ? or clock ? ) using SPI.h and shiftOut() ?

Techone

Oh I forgot...I don't know if I have the file "SPI.h" and "pins_adiuno.h" in my Arduino Library sub-directory.   Let see... SPI.h in my system...check...pins_arduino.h in my system... Nop... absent...hum

nickgammon

Sure you do. SPI is part of the standard Arduino distribution. It won't be in the libraries folder, it is part of the standard libraries (like Serial).

Read here for more information about it:

http://gammon.com.au/spi
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

nickgammon

#5
Jan 31, 2012, 02:53 am Last Edit: Jan 31, 2012, 03:23 am by Nick Gammon Reason: 1

SPI.h ? That I have to look it up and experiment on it.  I wonder how I will do it ( using SPI.h ) on a multiple 74HC595's ? It the data, latch and clock are my consern here. My code use a separated data, clock and latch for each chip.  I know the /MR goe to Reset of the Ardiuno, and the /CE goes to GND.  My question is : whish one can be commun for all the chip ( data ? Latch ? or clock ? ) using SPI.h and shiftOut() ?


I just tested that with two 74HC595 chips. You parallel up SH and ST on both chips (that is, they are common).

Connect Q7' (pin 9) as an output from the first chip to the DS (data input) on the second one (repeat as required for extra chips). Now that Q7' is the "carry" bit which propagates on the 9th bit (shift) onwards.

This sketch demonstrates:

Code: [Select]
#include <SPI.h>
const byte SS = 10;   // omit this line for Arduino 1.0 onwards

void setup ()
{
 SPI.begin ();
}  // end of setup

unsigned int i;

void loop ()
{
 i++;

 digitalWrite (SS, LOW);
 SPI.transfer (highByte (i));  // goes to second chip
 SPI.transfer (lowByte (i));   // goes to first chip
 digitalWrite (SS, HIGH);
 delay (20);
}  // end of loop


What is happening is that we shift out 16 bits (the two SPI.transfer calls) but only latch when both are done. So the first 8 go to the first 74HC595 chip. But as we keep clocking out the second byte those 8 bits "shift out" into the second chip. So after 16 bits we have 8 in the first and 8 in the second. Then raising SS latches both sets of data into the respective chips. Simple, huh? Still only three wires from the Arduino to the chips (plus power and Gnd).
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

nickgammon

#6
Jan 31, 2012, 03:16 am Last Edit: Jan 31, 2012, 03:28 am by Nick Gammon Reason: 1
Connect them up like this:



You could connect up the /MR lines in parallel and run them to a digital pin (eg. D9), and bring that low to effect a master reset (eg. to clear them on startup). In fact you could do that with a pull-down resistor (eg. 10K) and then just bring it high when you are ready to use the chips. Not totally necessary if you don't mind a brief bit of garbage showing as the Arduino boots. It might be important though if they were connected to motors or something.
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

Techone

Quote
Sure you do. SPI is part of the standard Arduino distribution. It won't be in the libraries folder, it is part of the standard libraries (like Serial).


Yes. I do. I located inside my Libraries Folder <--- In my computer, that is.

But I don't have "pins_arduino.h".

Thank you for clarify the "daisy chain" technique. I read the Tutorials about it.

So the code for three chip is :

Code: [Select]

digitalWrite (latch, LOW);
shiftOut (datapin, clockpin, LSBFIRST, datachip3); // 3rd chip
shiftOut (datapin, clockpin, LSBFIRST, datachip2); // 2nd chip
shiftOut (datapin, clockpin, LSBFIRST, datachip1); // 1st chip
digitalWrite (latch, HIGH);


And still have 3 wire going from the Ardiuno. Hope I am right with the code...  :smiley-roll:

About the /MR... I still feel confortable connecting to the reset of the arduino. The 74HC595 is still using flip-flops inside. It still need a reset signal to clear the register / flip-flops.

Thank Nick for the info. I will work on it.  ( re-wirred my setup...fun...)  XD

nickgammon


But I don't have "pins_arduino.h".


Version 1.0 doesn't seem to have it. Just omit it.

Quote
The 74HC595 is still using flip-flops inside. It still need a reset signal to clear the register / flip-flops.


They effectively get cleared when you clock more stuff into them, but I agree, at startup it might be nice.
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

Techone

So you are using 1.0...  I am still using 022, and I am happy with it. And I am NOT going to change to 1.0.  Raison : I read to many problems on this board about 1.0.  :0   <--- That why !

nickgammon

No I'm not unless I have to. So I don't know where I got "pins_arduino.h" from. But it was there somewhere.
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

Techone

Quote
But it was there somewhere


It is maybe in "cyberspace"... I google it ti see where it it.

Go Up