Example Code for Arduino-Display Text and Variable

Last revision 2026/01/08

This article demonstrates how to use Arduino to display text, including numbers and specific letters, on a digital tube, with compatibility for sensor-returned values like temperature and humidity.

Software Preparation

Click to download Library File and Example.
How to install a library?

Wiring Diagram

DFR0646 8-Digital LED Segment Display Module Connection Diagram

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.e8Bit) != 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

DFR0646 8-Digital LED Segment Display Module Result

Was this article helpful?

TOP