Three wires, eight outputs · 05 of 11

Shift, then latch

Three pins on your board become eight outputs on the module. Bits go in one at a time on one clock, and a second clock decides the instant they all become light.

Three pins, eight outputs

The chip on the back is a 74HC595, and it is the reason the module needs three wires rather than eight. Inside it there are two registers, one behind the other:

  • a shift register, eight stages long, which takes one bit at a time;
  • an output register, eight bits wide, which is what the segments actually see.

Each has its own clock. CLOCK (SRCLK) moves a bit into the shift register. LATCH (RCLK) copies all eight across into the output register at once. That is the whole chip.

Shift eight times, latch once
latch at the end
When the latch is pulsed
Clock ticks
0 of 8
In the shift register
0x00
On the segments
0x00
The segments do not move until the latch does. Eight ticks fill the shift register while the display holds whatever it had, and one pulse of LATCH copies all eight across at the same instant. That is why the digit changes cleanly instead of sweeping.

Press it with the latch at the end and watch the top row fill up one stage at a time while the bottom row — the segments — sits still. Eight ticks, then one latch, and the digit changes in a single step.

Now set the latch to fire after every bit. The display shows the byte arriving: a half-finished pattern, then another, then another. That is not flicker in the sense of a loose wire. It is the display faithfully showing you eight intermediate states you did not mean to send.

In code

digitalWrite(LAT, LOW);                  // freeze the segments
shiftOut(SER, CLK, MSBFIRST, pattern);   // eight bits, one at a time
digitalWrite(LAT, HIGH);                 // all eight appear together

shiftOut() is doing the boring part: for each of eight bits it sets the data pin, raises the clock, lowers it again. It is a loop in the Arduino library, nothing more, and you could write it yourself in five lines.

The two digitalWrite calls around it are the part worth understanding, because their position is the difference between a clean update and a sweep.

Why two registers at all

A shift register on its own would work, in the sense that the right bits would end up in the right places. It would just show you every step on the way there.

The second register exists so that the moment of change is yours to choose. Load whatever you like, take as long as you like, and nothing on the display moves until you say. At two digits that buys you a clean transition. At six it is the difference between a clock and a slot machine.

When it does not work

The display flickers while the number changes

The latch is inside the loop that sends the bytes. Pull LATCH low once, call shiftOut as many times as you have modules, then pull LATCH high once. A latch between bytes shows the chain mid-update, which is a flicker on two modules and a visible sweep on four.

Nothing changes no matter what I send

The latch is never pulsed at all. The shift register will accept bytes for ever without a single one of them reaching the segments — LATCH going from low to high is the only thing that moves them across, and a sketch that never touches that pin displays whatever was there at power-up.

Do I need to send exactly eight bits?

shiftOut always sends eight, so yes if you use it. The register itself does not care: it is a queue, and anything you clock in past eight bits falls out of the far end. That is not an error, it is how chaining works.

Can I use SPI instead of shiftOut?

Yes. The data and clock pins are ordinary SPI MOSI and SCK from the chip's point of view, and the latch is a pin you toggle yourself around the transfer. The chip is rated past 20 MHz, which is far faster than anything a display needs, so shiftOut is fine unless you are driving a long chain very often.

Where this goes next

Why the table is written in hexadecimal, and what the wrong bit order looks like on the display.

The byte behind a digit

Edit this page — content/books/4-inch-7-segment/shift-then-latch.mdx

Community

Questions about this product

See what other owners have asked, and read their solutions.

Ask a question ↗

4″ 7-Segment LED Display with 74HC595

Loading discussions…

Discuss this article

Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.

Browse Modules and blocks on the forum