Example Code for Arduino-Text and Date/Time Display

Last revision 2026/01/29

This article provides an in-depth tutorial on how to display text and date/time on an Arduino using both I2C and UART communication modes, complete with hardware preparation, software setup, wiring diagrams, and sample code.

Hardware Preparation

Software Preparation

Wiring Diagram

  1. I2C Communication Mode:
    DFR0997-I2C wiring diagram
    Pin Connection Description

    • Display: + Pin --- (Connect to) --- Controller: 5V
    • Display: - Pin --- (Connect to) --- Controller: GND
    • Display: C Pin --- (Connect to) --- Controller: SCL
    • Display: D Pin --- (Connect to) --- Controller: SDA
  2. UART Communication Mode:
    DFR0997-UART wiring diagram
    Pin Connection Description

    • Display: + Pin --- (Connect to) --- Controller: 5V
    • Display: - Pin --- (Connect to) --- Controller: GND
    • Display: R Pin --- (Connect to) --- Controller: 5/TX
    • Display: T Pin --- (Connect to) --- Controller: 4/RX

Sample Code

  1. Supports displaying text in four languages: Chinese, English, Japanese, and Korean.

  2. Display Date and Time: The date has a separate API, but it can also be displayed using text.

#include "DFRobot_LcdDisplay.h"
DFRobot_Lcd_IIC lcd(&Wire, /*I2CAddr*/ 0x2c);

uint8_t labelId = 0;
uint8_t lcdTimeId = 0;
void setup(void){
  lcd.begin();
  lcd.cleanScreen();
  delay(500);
  lcd.setBackgroundColor(WHITE);
}

void loop(void)
{
  //The fourth parameter is the font size, where 0 represents a font height of 24 pixels and 1 represents a font height of 12 pixels.
  //This parameter is only applicable to eChina and eAscii text.
  labelId = lcd.drawString( 10, 10, "Hello, World\nhello,World2024\n안녕하세요こんにちは\nПривет мирΓεια σου κόσμε", 0,  BLUE);
  lcdTimeId = lcd.drawLcdTime(10, 90, 15, 26, 00, 1, BLUE); //Display time
  lcd.drawLcdDate(10, 120, 4, 7, 7, 0, BLUE); //Display date
  delay(2000);
  lcd.updateString( labelId, 10, 10, "Hello, World", 1, BLACK);//Update text
  delay(2000);
  lcd.updateLcdTime(lcdTimeId, 10, 90, 20, 10, 20, 1, BLACK); //Update time
  delay(2000);
  lcd.cleanScreen(); //The clean screen API will delete all the displayed content
}

Result

DFR0997-Text and Date/Time Display

Was this article helpful?

TOP