Example Code for Arduino-Digital Tube Display

Last revision 2026/01/08

Display experiment of the digital tube. Users can learn how to use the DFR0645 module to display characters and variable values on a 4-digit 7-segment display, including initializing the module, setting the display area, and printing characters/decimal values.

Software Preparation

Development tools: Arduino IDE (version not specified).
Download library file and example: Library File and Example.
Library installation tutorial: How to install a library?

Wiring Diagram

DFR0645 Gravity: 4/8-Digital LED Segment Display Module Connection Diagram

Other Preparation Work

  1. Install the library file using the provided tutorial.
  2. Confirm the module is connected to the Arduino board as per the wiring diagram.
  3. Open the Arduino IDE and load the sample code.

Sample Code

/*!
 * @file ledPrint.ino
 * @brief Display experiment of the digital tube
 * @n Experiment phenomenon: The digital tube displays "HALO",and in one second, displays "H.A.L.O.", then show value of the variable val after one second
 * @copyright   Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
 * @license     The MIT License (MIT)
 * @author [Actor]([email protected]),[TangJie]([email protected])
 * @version  V1.0.1
 * @data  2022-03-21
 * @url https://github.com/DFRobot/DFRobot_LedDisplayModule
 */
# include "DFRobot_LedDisplayModule.h"
/**
 * DFRobot_LedDisplayModule Constructor
 * Parameter &wire  Wire
 * In default, the IIC address of 8 bits digital tube is 0xE0
 * The IIC address of 8 bits digital tube can be changed by combining A1 and A0
 * 1  1  1  0  | 0  A1 A0 0
 * 1  1  1  0  | 0  0  0  0    0xE0
 * 1  1  1  0  | 0  0  1  0    0xE2
 * 1  1  1  0  | 0  1  0  0    0xE4
 * 0  0  1  0  | 0  1  1  0    0xE6
 */ 
//DFRobot_LedDisplayModule LED(&Wire, 0xE0);

/**
 * DFRobot_LedDisplayModule Constructor
 * In default, the IIC address of 4 bits digital tube is 0x48 
 */
DFRobot_LedDisplayModule LED(&Wire, 0x48);

void setup() 
{
  Serial.begin(115200);
  /*Wait for the chip to be initialized completely, and then exit*/
  while(LED.begin(LED.e4Bit) != 0)
  {
    Serial.println("Failed to initialize the chip , please confirm the chip connection!");
    delay(1000);
  }
  
  /**
   * Set the display area to 1, 2, 3, 4
   * It can show 4 bits, the region of each parameter is 1~4 
   * Please resend the display value if the display area is changed
   */
  LED.setDisplayArea(1,2,3,4);
}

void loop() 
{
  /**
   * Display "HALO"
   * At present, it only supports showing the numbers 0 to 9, capital letters A, B, C, D, E, F, H, L, O, P, U and dash-,
   * and you can also bring decimal points, such as "0." "9." "A." "-."
   */
  LED.print("H","A","L","O");
  delay(1000);
  
  LED.print("H.","A.","L.","O."); 
  delay(1000);
  
  /**
   * Show a viriable value
   * The viriable could be both integer and decimal
   * Here it can be compatible with the sensor return value, such as temperature, humdity and so on
   */
  double val = 13.25;
  LED.print(val);
  delay(1000);
}

Result

DFR0645 Gravity: 4/8-Digital LED Segment Display Module Result

Was this article helpful?

TOP