ESP8266: Controlling chained SN74HC595 ICs

The objective of this post is to illustrate how to chain two SN74HC595 ICs and controlling them, using SPI, with the ESP8266.


The objective of this post is to illustrate how to chain two SN74HC595 ICs and controlling them, using SPI, with the ESP8266. Naturally, the working principle is the same for using the shiftOut function instead of the SPI interface.

Working principle

The working principle of this method consists basically in putting the two shift registers of each IC in sequence.

As we seen in the previous post, when we transfer the serial data and a shift occurs, the last bit is discarded.But, if we use this last bit as the input of the shifting process of the second shift register, then this bit will not be lost and will be stored there. This process is illustrated in figure 1.

Two 74HC595 chained one shift.png

Figure 1 – Propagation of 1 bit between two chained SN74HC595.

So, if we start with a 8 bit sequence in the first IC and no values set in the second and then we transfer a new 8 bit block to the first, the previous sequence will be pushed, bit by bit, to the second IC, as can be seen in figure 2.

Two 74HC595 chained.png

Figure 1 – Propagation of 8 bits between two chained SN74HC595.

Naturally, if we want to define the 16 bits (8 per IC) in one operation, we just send them uninterruptedly from the microcontroller and only in the end we send the load signal to both ICs. This way, the internal operation to transfer the bits from the shift registers to the storage registers will occur in parallel.

This approach scales if we want to add more ICs to extend the number of bits. For the generic case where we have N shift registers, we send N*8 bits uninterruptedly and, in the end, we send the load signal for each IC, in parallel. As before, the first byte that is transferred ends in the last IC of the chain and the last byte in the first IC.


Figure 3 shows the connection diagram for chaining 2 SN74HC595 ICs and controlling them with the ESP8266.

Chaining SN74HC595

Figure 3 – Diagram for chaining two SN74HC595 ICs.

As can be seen, we use exactly the same number of pins from the microcontroller we used before for controlling just one SN74HC595. So, we also connect the RCLK and SRCLK pins of the second IC to the Slave Select and clock pins of the ESP8266.

The only exception is that now we connect the QH’ of the first IC to the SER (corresponding to the Serial data input) pin of the second IC. If we remember what was explained in this previous post, the QH’ outputs the bit of the shift register that is discarded when the shift procedure occurs, when we are transferring the serial data.

So, like was explained in the previous section, if we transfer 16 bits instead of just 8, the first 8 bits will  get propagated to the second IC.

Naturally, this design can be extended to include more SN74HC595 ICs, controllable with just 3 pins of the microcontroller. Nevertheless, we need to take in consideration that as we add more ICs to the chain, some propagation problems may occur, mainly related to noise. Also, since we would use 2 of the pins to control all of the ICs, the fan-out would need to be considered. Check this interesting discussion about the effects of chaining 40 of these devices.


The setup will be exactly the same as in the previous post and will allow the initialization of the SPI bus and of the Slave Select pin.

#include <SPI.h>

const int SSpin = 15; 

void setup() {

   pinMode(SSpin, OUTPUT);


Main loop

The code for the main loop of this tutorial is basically the same as the previous one, with just an extra line of code to transfer the second block of 8 bits. The code is shown below.

byte firstByte = 1;
byte secondByte = 2;


Just remember that the first 8 bits (variable firstByte) will end in the second IC and the second 8 bits (variable secondByte) will stay in the first IC.

If we had more ICs chained, we would just need to add more SPI.transfer calls.

A slightly more interesting main loop function is shown bellow. In this case, we will do a for loop to set all the possible combinations of LEDs on/off for both ICs in parallel. So, the same sequence will occur in both.

void loop() {

  for (int i= 0; i<=7; i++){

     digitalWrite(SSpin, LOW);      //Disable any internal transference in the SN74HC595
      SPI.transfer(i);             //Transfer first byte
      SPI.transfer(i);             //Transfer second byte
      digitalWrite(SSpin, HIGH);   //Start the internal data transference in the SN74HC595
      delay(3000);                 //Wait for next iteration




You can check the final result in the video below.

Just note that if we use the same code of the previous post, which corresponds to commenting one of the SPI.transfer methods, the second IC would show the same sequence of the first with a lag of one iteration. The video bellow shows this case.

Final notes

The possibility of extending the number of controlled bits (and thus output pins) by simply chaining these ICs offers great flexibility and helps solving many constraints when pins of a microcontroller are limited.

On top of that, the possibility of using SPI allows for using the same clock and MOSI pins for controlling other SPI devices (naturally, more Slave Select pins are needed).

One interesting combination consists on using this approach to control a led matrix, allowing for controlling an huge number of LEDs with a minimal number of pins of a microcontroller.

Related Posts


Technical details

  • ESP8266 libraries: v2.3.0.
This entry was posted in Electronics, ESP8266, Microcontrollers and tagged , , , , , , , , , . Bookmark the permalink.

5 Responses to ESP8266: Controlling chained SN74HC595 ICs

  1. Pingback: ESP8266: Connection to SN74HC595 via SPI | techtutorialsx

  2. Pingback: ESP8266: Connection to SN74HC595 | techtutorialsx

  3. Pingback: SN74HC595: Shift Register | techtutorialsx

  4. Pingback: Buying cheap electronics at eBay: part 3 | techtutorialsx

  5. Pingback: ESP8266: Controlling a LED matrix with the 74HC595 ICs | techtutorialsx

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s