Thursday, July 26, 2018

http://www.learnerswings.com/2014/08/simple-arduino-program-to-turn-on-all.html

Method to Control 8*8 LED Matrix using Shift Register IC 74595 and Arduino Mega

by realfinetime electronics  |  in LED Matrix at  22:05
Previous : Control 74595 Using Arduino

          So far, we have read a lot about LED matrix and 74595 shift register IC. Click here to start reading about LED matrix from beginning.

          In the past few blogs, we found the basics of working of 8*8 LED matrix and shift register IC 74595. In this blog, we will see the circuit to connect 8*8 LED matrix to arduino through shift registers using minimum number of digital pins of arduino. Essence of this circuit is, controlling 64 LEDs using only six digital output pins from arduino. Circuit is given at the bottom of this page. Before starting the circuit, you should be familiar about the pinout diagram of, 8*8 LED matrix and 74595 shift register IC.


Pinout diagram of 8*8 LED matrix

          Pinout diagram of 8*8 LED matrix is given below. Refer this blog to get a simple circuit to demonstrate the working of 8*8 LED matrix. Small wedges on the middle of four edges of the 8*8 LED matrix is the indication of the pin from which pin numbering should be started.
Internal Circuit of 8*8 LED matrix

          Internal circuit of 8*8 LED matrix is given below. Pin numbering of 8*8 LED matrix is a bit confusing. Read this blog to get a clear idea about the pin numbering of 8*8 LED matrix.


Pin out diagram of 74595

          Pinout diagram of 74595 is given below. Two 74595 ICs are used in this circuit. Read this blog to get an idea about the working of 74595.


          Next is the circuit diagram. Two 74595 ICs are used to control one LED matrix. One IC is for controlling the rows of LED matrix and the other IC is for controlling the columns of LED matrix. 5V for the working of IC is given from a 5V regulator. SHCP, STCP and DS pins of both 74595 are connected to separate digital output pins of arduino as shown in the circuit. VCC and MRbar of both ICs should be connected to 5V. Gnd and OEbar of both ICs should be connected to the Gnd of voltage source. 100 Ohm current limiting resistors should be connected to the cathode pins of 8*8 LED matrix. If current limiting resistor is connected to the anode pins of 8*8 LED matrix, brightness of LEDs will decrease, when more LEDs will turn on. Gnd pin of arduino should be connected to the gnd pin of voltage source for voltage leveling.




Connection between arduino mega and 1st 74595 can be summarized as follows.

1.  Digital pin 11 of arduino is connected to the DS pin (14th pin) of 1st 74595.
2.  Digital pin 12 of arduino is connected to the STCP pin (12th pin) of 1st 74595.
3.  Digital pin 13 of arduino is connected to the SHCP pin (11th pin) of 1st 74595.

Connection between arduino mega and 2nd 74595 can be summarized as follows.

1.  Digital pin 5 of arduino is connected to the DS pin (14th pin) of 2nd 74595.
2.  Digital pin 6 of arduino is connected to the STCP pin (12th pin) of 2nd 74595.
3.  Digital pin 7 of arduino is connected to the SHCP pin (11th pin) of 2nd 74595.

Connection between 1st 74595 and 8*8 LED matrix can be summarized as follows.

1.  Q0 pin (15th pin) of 1st 74595 is connected to the 16th pin 8*8 LED matrix.
2.  Q1 pin (1st pin) of 1st 74595 is connected to the 15th pin 8*8 LED matrix.
3.  Q2 pin (2nd pin) of 1st 74595 is connected to the 11th pin 8*8 LED matrix.
4.  Q3 pin (3rd pin) of 1st 74595 is connected to the 3rd pin 8*8 LED matrix.
5.  Q4 pin (4th pin) of 1st 74595 is connected to the 10th pin 8*8 LED matrix.
6.  Q5 pin (5th pin) of 1st 74595 is connected to the 5th pin 8*8 LED matrix.
7.  Q6 pin (6th pin) of 1st 74595 is connected to the 6th pin 8*8 LED matrix.
8.  Q7 pin (7th pin) of 1st 74595 is connected to the 13th pin 8*8 LED matrix.

Connection between 2nd 74595 and 8*8 LED matrix can be summarized as follows.

1.  Q0 pin (15th pin) of 2nd 74595 is connected to the 4th pin 8*8 LED matrix.
2.  Q1 pin (1st pin) of 2nd 74595 is connected to the 7th pin 8*8 LED matrix.
3.  Q2 pin (2nd pin) of 2nd 74595 is connected to the 2nd pin 8*8 LED matrix.
4.  Q3 pin (3rd pin) of 2nd 74595 is connected to the 8th pin 8*8 LED matrix.
5.  Q4 pin (4th pin) of 2nd 74595 is connected to the 12th pin 8*8 LED matrix.
6.  Q5 pin (5th pin) of 2nd 74595 is connected to the 1st pin 8*8 LED matrix.
7.  Q6 pin (6th pin) of 2nd 74595 is connected to the 14th pin 8*8 LED matrix.
8.  Q7 pin (7th pin) of 2nd 74595 is connected to the 9th pin 8*8 LED matrix.
    We have already seen the circuit to connect 8*8 LED matrix to arduino through 8 bit shift register 74595 in previous blog. Next is a simple program to turn on all LEDs of an 8*8 LED matrix. LED matrix will look like as shown in the following image.

Upload the following program to your arduino board.

int latchPin = 12;  //Pin connected to ST_CP of 1st 74595
int clockPin = 13;  //Pin connected to SH_CP of 1st 74595
int dataPin = 11;   //Pin connected to DS of 1st 74595

int latchPin2 = 6;  //Pin connected to ST_CP of 2nd 74595
int clockPin2 = 7;  //Pin connected to SH_CP of 2nd 74595
int dataPin2 = 5;   //Pin connected to DS of 2nd 74595

void setup() {
  //set pins to output so you can control the shift register
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  
  pinMode(latchPin2, OUTPUT);
  pinMode(clockPin2, OUTPUT);
  pinMode(dataPin2, OUTPUT);
}

void loop() {
  
    /********** Send HIGH to all Anode pins of LED matrix **********/    
  
    // take the latchPin low so the LEDs don't change while you're sending in bits:  
    digitalWrite(latchPin, LOW);
    //Send 1 1 1 1 1 1 1 1 (255) to Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 1st 74595
    shiftOut(dataPin, clockPin, MSBFIRST, 255);
    // shift out the bits:    
    digitalWrite(latchPin, HIGH);


    /********** Send LOW to all Cathode pins of LED matrix **********/    
    
    // take the latchPin low so the LEDs don't change while you're sending in bits:    
    digitalWrite(latchPin2, LOW);
    //Send 0 0 0 0 0 0 0 0 (0) to Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 2nd 74595
    shiftOut(dataPin2, clockPin2, MSBFIRST, 0);
    // shift out the bits:  
    digitalWrite(latchPin2, HIGH);
}

     

          If uploading is successful, all LEDs in LED matrix will turn on. Working of program is simple. Q0 to Q7 pins of first IC is connected to the anode pins of 8*8 LED matrix as given in the previous blog. Arduino will send 255 (1 1 1 1 1 1 1 1) to the first shift register IC. When 255 is shifted out, Q0 Q1 Q2 Q3 Q4 Q5 Q6 Q7 of first shift register will output 1 1 1 1 1 1 1 1. Hence, all the anode pins of LED matrix will get HIGH voltage.

          Similarly Q0 to Q7 pins of second IC is connected to the cathode pins of 8*8 LED matrix. Arduino will send 0 (0 0 0 0 0 0 0 0) to the second shift register IC. When 0 is shifted out, Q0 Q1 Q2 Q3 Q4 Q5 Q6 Q7 of second shift register will output 0 0 0 0 0 0 0 0. Hence, all the cathode pins of LED matrix will get LOW voltage. That is, all LEDs will get HIGH voltage at anode and LOW voltage at cathode. This will turn on all LEDs.

No comments:

Post a Comment

สรุปงานที่ 5 Internet of Things (IoT)

Internet of Things (IoT) คืออะไร           Internet of Things (IoT) คือ  "อินเตอร์เน็ตในทุกสิ่ง" หมายถึง การที่อุปกรณ์ต่างๆ ส...