Skip to content

7 Segment Display

Component 7 Segment Display
Type Output
Introduction If you like to display the time, score or any number without too much effort.

Introduction

A 7-segment display is a type of electronic display device that can display decimal numbers and some alphabets. It is made up of seven LEDs arranged in a rectangular fashion. Each LED is called a segment. The display can be used to display numbers, letters, and some special characters. It is commonly used in digital clocks, electronic meters, and other electronic devices that display numerical information.

To control a 7 segment display, especially 4 or 8 in a row, you need quite a few wires. This is why we use a 7 segment display driver, which you connect to your micocontroller using I2C or SPI, this way you only need 2 - 4 wires to control all displays.

We have two laying around:

  • TM1637 (4 digits, 7 segment display, I2C, time-dots)

TM1637

  • MAX7219 (8 digits, 7 segment display, SPI, decimal points)

MAX7219

Pin Description

Both displays have a different pin layout, but they are both controlled using I2C. The TM1637 has 4 pins, VCC, GND, SDA, and SCL. The MAX7219 has 5 pins, VCC, GND, DIN, CS, and CLK.

By using a library, you can control the display with just a few lines of code.

Code Example

The following code example shows how to use the TM1637Display library to control a 4 digit 7 segment display.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#include <TM1637Display.h>

// Module connection pins (Digital Pins)
#define CLK 2
#define DIO 3

TM1637Display display(CLK, DIO);

void setup() {
  display.setBrightness(0x0f);
}

void loop() {
  display.showNumberDec(1234, false);
  delay(1000);
  display.showNumberDec(8765, false);
  delay(1000);
}

The following code example shows how to use the max7219 library to control a 8 digit 7 segment display.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
#include <max7219.h>
#define LEFT 0
#define RIGHT 1

MAX7219 max7219;

void setup() {
  Serial.begin(9600);
  max7219.Begin();
}

void loop() {
  //Display HELLO right justified
  max7219.Clear();
  max7219.DisplayText("HELLO", RIGHT);
  delay(1000);
}

Make sure you have the correct library installed, and the correct pins are defined.