Two wires, but not I²C
A clock line, a data line, a start and a stop: it looks exactly like I²C and it is not. There is no address anywhere in the protocol, which decides how you wire a second display and why a bus scan will never find the first one.
What goes down the wires
Everything the display is ever told is a byte, and every byte goes out the same way: a start, eight bits, an acknowledge from the chip, a stop.
Idle. Both wires sit high, held there by the 10 kΩ resistors on the board — nothing is driving them.
Press through it once. The parts worth noticing:
Both wires idle high on their own. Your board never drives them up. The library either pulls a wire down to 0 V or lets go of it, by switching the pin to an input, and the two 10 kΩ resistors on the board pull it back up. I²C uses the same trick, and for the same reason: two pins can never fight over a wire neither of them drives high. What the wire rises to is the display's VCC, which is the whole of 3.3 V or 5 V.
The bits go out least significant first. I²C sends the most significant bit first. This does not. It matters the moment you start writing segment patterns by hand: bit 0 of the byte is segment A, and it is also the first bit on the wire.
The chip answers. After the eighth bit the display pulls DATA down itself and holds it through a ninth clock, to say it heard you. That amber pulse is the only thing on the wire your board did not put there.
The part that is missing
There is no address. Nowhere in any of those bytes is there anything that says which chip should pay attention.
I²C opens every exchange with an address precisely so that a dozen devices can share two wires. The TM1637 has nothing of the kind — the datasheet says so in as many words, that the protocol "is not equal to I2C bus protocol totally because there is no slave address". Every chip that can hear the wires acts on everything it hears.
Three consequences, all of them practical:
- An I²C scan finds nothing. Not a fault. There is nothing to find.
- It cannot share your I²C bus. SDA and SCL belong to devices that understand addressing; this display would corrupt their traffic and be corrupted by it.
- A second display needs its own DATA pin. This is the one that shapes real projects, and more than one display is entirely about it.
What it costs in time
The library waits 100 µs at every step of every edge. One update (four digits, seven bytes, three start–stop pairs) makes 208 of those waits, about 21 ms doing nothing but waiting.
For a clock, a counter or a thermometer that is invisible. It starts to matter when six displays are being refreshed in a loop, or when 21 ms of blocking upsets something else in the sketch. The fix is the constructor's third argument, which is the delay in microseconds:
TM1637Display display(2, 3, 10); // ten times faster, still far inside the chip's limitThe chip's datasheet allows a clock up to 500 kHz, so there is a great deal of room. Long wires are the reason to leave the default alone: the same resistors that hold the wires high also make them slow to rise, and every extra length of wire slows them further.
When it does not work
It never will. The protocol has no addresses at all, so there is nothing for a scan to find, and Wire is not involved anywhere in driving this display. Two ordinary digital pins and the TM1637 library are the whole of it.
No. A real I²C device would see the TM1637's traffic as malformed frames addressed to nobody, and the TM1637 would try to obey bytes meant for the sensor. Give the display two pins of its own — any two digital pins will do.
The library waits 100 µs between every edge, which works out at about 21 ms for one four-digit update. That is deliberate — it makes the code work on long jumper wires and slow boards. The constructor takes a shorter delay as a third argument if you need the speed.
writeByte() returns it, but nothing in the library's public functions passes it back to you, so in practice you cannot use it to detect a missing display. Treat a blank display as the error signal instead.
The clock panel and the digit panel, and the one bit that behaves differently on each.
Two sets, one board →Edit this page — content/books/tm1637-display/two-wires-not-i2c.mdx
Questions about this product
See what other owners have asked, and read their solutions.
This page covers several products. Choose yours to see the right 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.