Arduino Basic Input Output Circuits
Digital Out - Run out of Pins? Using Multiple Shift Register ICs
So the first Shift Register example showed how you can control 8 output pins with 3 Arduino Digital Pins
In this example we will use 2 x 74HC595 Shift Registers to control 16 Digital outs (in this case drive LED's) using the same 3 Arduino DO pins.
This example will also add 3 additional LEDs to monitor the Data entering the 1st Shift Register, the 2nd Shift Register and the common clock.
Again my specific hardware is the Arduino Duemilanove platform, but the concept is the same regardless of the exact platform.
Before continuing make sure you have read and understand the warning notice here.
Hardware Requirements;
1x Arduino
19x LED
19x Resistor (560Ohm)
2x 74HC595 Shift Register
This circuit diagram for this example is shown below;

The Enable pins and the Reset pins on each Shift Register are active LOW, this means that the Enable must be tied to 0v and the Reset held at the Vcc level.
The Shift Registers used will provide Vcc at the outputs of Q0 to Q7 and has a supply current in the region of 20mA.
The Overflow/SerialOut pin on the 1st Shift Register will pass the serial data onto the 2nd Shift Register. You could go on and extend this further should you so wish.
Something extra to try;
Once you have uploaded one of the code examples and got your circuit working, if you disconnect the data line from the 1st Shift Register (Pin 9) and connect to the same source data line from the Arduino, you will see the second shift register LED's copy the 1st Shift Register, demonstrating that the bytes are being passed through correctly. Remember to put it back again after you have satisfied yourself that this is happening.
You can also see on the Extra 3 LED's that the data lines are indeed doing different things and the clock is a constant pulse.
Upload any of the following code examples to the Arduino to do the relevant example;
/*
Basic Digital Output - Dual Shift Register #1
This example uses 3 Digital Output Pins to Control 16 Digital Output Signals from Dual Shift Registers
8 LED are on the outputs on each the Shift Registers.
This example will do the Knight Rider [2009 model kitt] dual light sweep (out to in and back).
Author: David M. Auld
Date: 14th October 2009
*/
int dataPin = 2; // The Serial Data Pin to the Shift Register
int latchPin = 3; // The Latch Pin to the Shift Register
int clockPin = 4; // The Clock Pin to the Shift Register
int seq[14] = {1,2,4,8,16,32,64,128,64,32,16,8,4,2};
int seq2[14] = {128,64,32,16,8,4,2,1,2,4,8,16,32,64};
int value = 0;
int value2 = 0;
void setup()
{
pinMode(dataPin, OUTPUT); // Configure Digital Pins
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
}
void loop()
{
for (int n=0; n < 14; n++)
{
value = seq[n]; //Forward array
value2 = seq2[n]; //Reverse array
writeOutput();
delay(75);
}
}
void writeOutput()
{
digitalWrite(latchPin, LOW); // Pull latch LOW to send data
shiftOut(dataPin, clockPin, MSBFIRST, value); // Send the data byte 1
shiftOut(dataPin, clockPin, MSBFIRST, value2); // Send the data byte 2
digitalWrite(latchPin, HIGH); // Pull latch HIGH to stop sending data
}
/*
Basic Digital Output - Dual Shift Register #2
This example uses 3 Digital Output Pins to Control 16 Digital Output Signals from Dual Shift Registers
8 LED are on the outputs on each the Shift Registers.
This example will do a binary increment on Byte 1 and binary decrement on Byte 2
Author: David M. Auld
Date: 14th October 2009
*/
int dataPin = 2; // The Serial Data Pin to the Shift Register
int latchPin = 3; // The Latch Pin to the Shift Register
int clockPin = 4; // The Clock Pin to the Shift Register
int value = 0;
int value2 = 0;
void setup()
{
pinMode(dataPin, OUTPUT); // Configure Digital Pins
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
}
void loop()
{
for (int n=0; n < 256; n++)
{
value = n; //increment
value2 = 255-n; //decrement
writeOutput();
delay(250);
}
}
void writeOutput()
{
digitalWrite(latchPin, LOW); // Pull latch LOW to send data
shiftOut(dataPin, clockPin, MSBFIRST, value); // Send the data byte 1
shiftOut(dataPin, clockPin, MSBFIRST, value2); // Send the data byte 2
digitalWrite(latchPin, HIGH); // Pull latch HIGH to stop sending data
}
/*
Basic Digital Output - Dual Shift Register #3
This example uses 3 Digital Output Pins to Control 16 Digital Output Signals from Dual Shift Registers
8 LED are on the outputs on each the Shift Registers.
This example will do a 16-Bit binary increment.
Author: David M. Auld
Date: 14th October 2009
*/
int dataPin = 2; // The Serial Data Pin to the Shift Register
int latchPin = 3; // The Latch Pin to the Shift Register
int clockPin = 4; // The Clock Pin to the Shift Register
int value = 0;
int value2 = 0;
void setup()
{
pinMode(dataPin, OUTPUT); // Configure Digital Pins
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
}
void loop()
{
for (int n=0; n < 256; n++)
{
value2 = n; //Outer Loop Byte 2
for (int m=0; m < 256; m++)
{
value = m; //Inner Loop Byte 1
delay(25);
writeOutput();
}
}
}
void writeOutput()
{
digitalWrite(latchPin, LOW); // Pull latch LOW to send data
shiftOut(dataPin, clockPin, MSBFIRST, value); // Send the data byte 1
shiftOut(dataPin, clockPin, MSBFIRST, value2); // Send the data byte 2
digitalWrite(latchPin, HIGH); // Pull latch HIGH to stop sending data
}
/*
Basic Digital Output - Dual Shift Register #4
This example uses 3 Digital Output Pins to Control 16 Digital Output Signals from Dual Shift Registers
8 LED are on the outputs on each the Shift Registers.
This example will do a 16 LED Knight Rider Sweep.
Author: David M. Auld
Date: 14th October 2009
*/
int dataPin = 2; // The Serial Data Pin to the Shift Register
int latchPin = 3; // The Latch Pin to the Shift Register
int clockPin = 4; // The Clock Pin to the Shift Register
int value = 0;
int value2 = 0;
int seq[31] = {128,64,32,16,8,4,2,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,4,8,16,32,64};
int seq2[31]= {0,0,0,0,0,0,0,0,128,64,32,16,8,4,2,1,2,4,8,16,32,64,128,0,0,0,0,0,0,0,0};
void setup()
{
pinMode(dataPin, OUTPUT); // Configure Digital Pins
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
}
void loop()
{
for (int n=0; n < 31; n++)
{
value2 = seq[n];
value = seq2[n];
writeOutput();
delay(50);
}
}
void writeOutput()
{
digitalWrite(latchPin, LOW); // Pull latch LOW to send data
shiftOut(dataPin, clockPin, MSBFIRST, value); // Send the data byte 1
shiftOut(dataPin, clockPin, MSBFIRST, value2); // Send the data byte 2
digitalWrite(latchPin, HIGH); // Pull latch HIGH to stop sending data
}
|
Comments
RSS feed for comments to this post.