Many years ago, we talked about Vacuum Fluorescent Display (VFD) and history of calculator. In this detailed Arduino 7 segment LED display tutorial with example codes, circuit diagram we will exactly program the same thing. It is very important and basic electronics guide. The 7 segment LED display we are talking about has 4 digits – E.E.E.E. It uses TM1637. TM means Titan Micro. 1637 is the number and it is an integrated circuit (IC) for 4-digit 7-segment display.
How much this 7 Segment TM1637 4 Digit LED display costs? Hardly $3 per unit (at low end of build). So, it is a cheap serial display, which is bright and great for echoing important data, few understandable alphabets too. TM1637 is an interface with a keyboard display dedicated drive control circuit. You can search with TM1637 data sheet to get details. It has key scan circuit, luminance adjustment circuit, two-wire serial interface (CLK, DIO), power-on reset circuit.
Although in this guide we are mainly showing example for echoing display, this unit is quite powerful and supports key input. If we add a DS3231 module (read this guide), it will become a clock. Also it has clock, but I want to avoid it in this guide. You’ll get some information here on Arduino’s site :
---
1 | http://playground.arduino.cc/Main/TM1637 |
Officially this display supports Arduino, BeagleBone, Raspberry Pi etc.
Arduino 7 Segment LED Display Tutorial (TM1637 4 Digit)
Some of the sellers like Avishorp has library for Arduino to allow these displays to be connected to any digital pins. You will commonly need to download the library and install it into your Arduino libraries directory. How to install library is written here :
1 | https://www.arduino.cc/en/Guide/Libraries |
Like this is the latest edition of this library :
1 | https://github.com/avishorp/TM1637 |
Rather this as zip :
1 | https://github.com/avishorp/TM1637/archive/v1.1.0.zip |
That is why the link of Arduino’s site we gave you also has the same link. Connect Arduino to computer via a USB cable.
Also download the 4-Digit Display library :
1 | https://raw.githubusercontent.com/SeeedDocument/Grove-4-Digit_Display/master/res/DigitalTube.zip |
Either use import library function or unzip and put them in the libraries file of Arduino IDE like the path: ..\arduino\libraries
. Restart the Arduino IDE.
At the end you’ll have two libraries installed :
Digital Tube
TM1637
In Arduino’s IDE, if you go to File > Examples > DigitalTube, you’ll get example sketches.
Anyway, we need to give an example code. After adding them, we can use this starting of Arduino coding as example :
1 2 3 | #include const int CLK = 9; const int DIO = 8; |
The TM1637 display has four pins :
- VCC
- GND
- DIO
- CLK
A start signal needs to be sent before sending a command to the display. Then a stop signal needs to be used. If a command has arguments another start signal needs to be sent instead and after all the arguments have been sent we need to send the stop signal.
- Start signal = Setting the CLK and DIO pins to HIGH and then set them to LOW.
- Stop signal = Sett the CLK and DIO pins to LOW and then stem them to HIGH.
Minimum power supply should be 3.3 Volt. Do not cross 5 Volt. I am delivering the dialogues as if hugely knowledgeable because I read this :
1 | https://github.com/avishorp/TM1637/blob/master/docs/TM1637_V2.4_EN.pdf |
Circuit Diagram and Example Codes For Arduino 7 Segment LED Display Tutorial TM1637
Pin assignments are easy.
- Connect CLK with Digital Pin 2 of Arduino
- Connect DIO with Digital Pin 3 of Arduino
- Connect VCC with 5V or 3.3V supply or Pin 5V of Arduino
- Connect GND to GND of Arduino
This example initialises the display and then shows “AbHI” :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | #include <Arduino.h> #include <TM1637Display.h> #define CLK 2 #define DIO 3 const uint8_t SEG_DONE[] = { SEG_E | SEG_F | SEG_A | SEG_B | SEG_C | SEG_G, // A SEG_F | SEG_E | SEG_D | SEG_C | SEG_G, // b SEG_E | SEG_F | SEG_G | SEG_B | SEG_C, // h SEG_B | SEG_C // I }; TM1637Display display(CLK, DIO); void setup() { } void loop() { display.setBrightness(0x0f); display.setSegments(SEG_DONE); } |
Notice this diagram :
So, this :
1 | SEG_E | SEG_F | SEG_A | SEG_B | SEG_C | SEG_G |
means
1 | A |
on display. This is one way of showing the display. No website on internet shows how you can write your wanted character easily on Arduino 7 segment TM1637 4 digit LED display in so easy way. It is normal that an user will want to show own custom thing on a display. Now, in the above way, you can perform it.
Download rigs user guide for TM1637 4 digits display and Grove 4 Digit Display to understand the electronics and coding to control it.
Here is good resource :
1 | https://github.com/bremme/arduino-tm1637 |
We used avishorp’s library, correct? There is another library named Suli :
1 | https://github.com/Seeed-Studio/Four_Digit_Display_Suli |