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 between the display and the board, U1, is a 74HC595. It is why the module needs three signal wires and not eight. Inside it 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 eight outputs, and so the segments, actually follow.
Each has its own clock. CLOCK (SRCLK) moves the bit on DATAIN (SER) into the shift register. LATCH (RCLK) copies all eight stages into the output register at once, on its rising edge.
With the latch at the end, the top row fills one stage at a time while the bottom row, the one the segments follow, does not move. Eight ticks, one latch, and the digit changes in a single step.
Set the latch to fire after every bit and the digit shows the byte arriving: one half-finished pattern after another. Nothing is loose. The register is doing what the sketch told it to.
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 togethershiftOut() is a loop in the Arduino library: for each bit it sets the data pin, raises the clock and lowers it. The two digitalWrite calls around it are the part worth understanding, because their position is the difference between a clean update and a sweep.
The segments still need a supply before any of this shows. A byte that is latched but dark means the 12 V or the dimmer is missing, not that the byte is wrong: the register holds its byte whether or not the digit is lit.
Two pins tied on the board
On this board U1's output-enable pin is tied to GND, so the outputs are always on, and its clear pin is tied to the logic rail, so nothing can clear the register. The only way to blank the digit by software is to shift in zeros and latch them. The only other way is the PWM pin, which switches the segments' supply and leaves the register alone.
Anything clocked in beyond eight bits comes out of the register's last stage, which the board wires to the DATAOUT pin. That is what the chain pages build on.
When it does not work
The latch is inside the loop that sends the bytes. Pull LATCH low once, call shiftOut once per module, then pull LATCH high once. A latch between bytes shows the chain mid-update: a flicker on two modules and a visible sweep on more.
Either LATCH is never pulsed, or the segments have no supply. The register accepts bytes for ever; only LATCH going from low to high moves them to the outputs. If the latch is right, check the 12 V and the PWM pad before the code: on the newer board, the one with a PWM pad, a new module with nothing wired to PWM stays dark.
The output register can hold anything at power-up, and this board ties the chip's clear pin high and its output-enable pin low, so neither can blank it for you. Send a byte of zeros once in setup, as the sketches in this book do.
shiftOut always sends eight, so use it once per module. The register itself does not count: it is a queue, and a bit clocked in past the eighth leaves through the DATAOUT pin. That is not an error, it is how chaining works.
Yes. DATAIN and CLOCK behave as ordinary SPI data and clock, and LATCH is a pin you toggle yourself around the transfer. The datasheet gives about 21 MHz worst case at 4.5 V, lower on a 3.3 V rail, and a display needs nothing like that, so shiftOut is enough unless you update a long chain very often.
Which bit reaches which bar, and what one wrong word in shiftOut does to every digit.
The byte behind a digit →Edit this page — content/books/seg4/shift-then-latch.mdx
Questions about this product
See what other owners have asked, and read their solutions.
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.