Chuyển tới nội dung
Home » Arduino Lcd 16X4 I2C Code | How To Create And Display Custom Characters?

Arduino Lcd 16X4 I2C Code | How To Create And Display Custom Characters?

How to Use I2C LCD with Arduino | Very Easy Arduino LCD I2C Tutorial | Arduino 16x2 LCD I2C Tutorial

I2C Address of LCD

If you have multiple devices on the same I2C bus, you may need to set a different I2C address for the LCD adapter to avoid conflicting with another I2C device.

For this purpose, the adapter comes with three solder jumpers/pads (A0, A1, and A2). The address is set when a jumper is shorted with a blob of solder.

An important point to note here is that several companies, including Texas Instruments and NXP Semiconductors, manufacture the same PCF8574 chip. And the I2C address of your LCD depends on the chip manufacturer.

If your LCD has Texas Instruments’ PCF8574 chip:

According to the Texas Instruments’ datasheet, the three address selection bits (A0, A1, and A2) are located at the end of the 7-bit I2C address register.

Because there are three address inputs that can take on two states, either HIGH or LOW, eight (2^3) different combinations (addresses) are possible.

All three address inputs are pulled HIGH using onboard pullups. This gives the PCF8574 a default I2C address of 0x27.

When you short a solder jumper, you pull that address input LOW. If you were to short all three jumpers, the address would be 0x20. So the range of all possible addresses spans from 0x20 to 0x27.

You can set a different I2C address, according to the table below.

If your LCD has NXP’s PCF8574 chip:

According to the NXP Semiconductors’ datasheet, the three address selection bits (A0, A1, and A2) are located at the end of the 7-bit I2C address register. However, the remaining bits in the address register are different.

Because there are three address inputs that can take on two states, either HIGH or LOW, eight (2^3) different combinations (addresses) are possible.

All three address inputs are pulled HIGH using onboard pullups. This gives the PCF8574 a default I2C address of 0x3F.

When you short a solder jumper, you pull that address input LOW. If you were to short all three jumpers, the address would be 0x38. So the range of all possible addresses spans from 0x38 to 0x3F.

You can set a different I2C address, according to the table below.

So the I2C address of your LCD is most likely 0x27 or 0x3F. If you’re not sure what your LCD’s I2C address is, there’s an easy way to figure it out. You’ll learn about that later in this tutorial.

Recommended articles

  • How to use an HC-SR04 Ultrasonic Distance Sensor with Arduino
  • How to use DHT11 and DHT22 Sensors with Arduino
  • LM35 analog temperature sensor with Arduino tutorial
  • TMP36 analog temperature sensor with Arduino tutorial

(I also have an article on How To Control A Character I2C LCD with ESP32 if you want to work with an ESP32 microcontroller instead).

How to Use I2C LCD with Arduino | Very Easy Arduino LCD I2C Tutorial | Arduino 16x2 LCD I2C Tutorial
How to Use I2C LCD with Arduino | Very Easy Arduino LCD I2C Tutorial | Arduino 16×2 LCD I2C Tutorial

Create and Display Custom Characters

If you find the default font uninteresting, you can create your own custom characters (glyphs) and symbols. They come in handy when you need to display a character that isn’t in the standard ASCII character set.

As previously discussed in this tutorial, a character is made up of a 5×8 pixel matrix; therefore, you must define your custom character within this matrix. You can define a character by using the

createChar()

function.

To use

createChar()

, you must first create an 8-byte array. Each byte in the array corresponds to a row in a 5×8 matrix. In a byte, the digits 0 and 1 indicate which pixels in a row should be OFF and which should be ON.

All of these user-defined characters are stored in the LCD’s CGRAM.

CGROM and CGRAM

All Hitachi HD44780 driver-based LCDs have two types of memory: CGROM and CGRAM (Character Generator ROM and RAM).

CGROM is non-volatile memory that retains data even when the power is removed, whereas CGRAM is volatile memory that loses data when the power is removed.

The CGROM stores the font that appears on a character LCD. When you instruct a character LCD to display the letter ‘A’, it needs to know which pixels to turn on so that we see an ‘A’. This data is stored in the CGROM.

CGRAM is an additional memory for storing user-defined characters. This RAM is limited to 64 bytes. Therefore, for a 5×8 pixel LCD, only 8 user-defined characters can be stored in CGRAM, whereas for a 5×10 pixel LCD, only 4 can be stored.

Custom Character Generator

Creating custom characters has never been easier! We’ve developed a small application called Custom Character Generator. Can you see the blue grid below? You can click on any pixel to set or clear that pixel. And as you click, the code for the character is generated next to the grid. This code can be used directly in your Arduino sketch.

There’s no limit to what you can create. The only limitation is that the LiquidCrystal_I2C library only supports eight custom characters. But don’t be sad, look at the bright side; at least we have eight characters.

Arduino Example Code

The sketch below demonstrates how to display custom characters on the LCD.


#include LiquidCrystal_I2C lcd(0x3F, 16, 2); // set the LCD address to 0x3F for a 16 chars and 2 line display // make some custom characters: byte Heart[8] = { 0b00000, 0b01010, 0b11111, 0b11111, 0b01110, 0b00100, 0b00000, 0b00000 }; byte Bell[8] = { 0b00100, 0b01110, 0b01110, 0b01110, 0b11111, 0b00000, 0b00100, 0b00000 }; byte Alien[8] = { 0b11111, 0b10101, 0b11111, 0b11111, 0b01110, 0b01010, 0b11011, 0b00000 }; byte Check[8] = { 0b00000, 0b00001, 0b00011, 0b10110, 0b11100, 0b01000, 0b00000, 0b00000 }; byte Speaker[8] = { 0b00001, 0b00011, 0b01111, 0b01111, 0b01111, 0b00011, 0b00001, 0b00000 }; byte Sound[8] = { 0b00001, 0b00011, 0b00101, 0b01001, 0b01001, 0b01011, 0b11011, 0b11000 }; byte Skull[8] = { 0b00000, 0b01110, 0b10101, 0b11011, 0b01110, 0b01110, 0b00000, 0b00000 }; byte Lock[8] = { 0b01110, 0b10001, 0b10001, 0b11111, 0b11011, 0b11011, 0b11111, 0b00000 }; void setup() { lcd.init(); // Make sure backlight is on lcd.backlight(); // create a new characters lcd.createChar(0, Heart); lcd.createChar(1, Bell); lcd.createChar(2, Alien); lcd.createChar(3, Check); lcd.createChar(4, Speaker); lcd.createChar(5, Sound); lcd.createChar(6, Skull); lcd.createChar(7, Lock); // Clears the LCD screen lcd.clear(); // Print a message to the lcd. lcd.print("Custom Character"); } // Print All the custom characters void loop() { lcd.setCursor(0, 1); lcd.write(0); lcd.setCursor(2, 1); lcd.write(1); lcd.setCursor(4, 1); lcd.write(2); lcd.setCursor(6, 1); lcd.write(3); lcd.setCursor(8, 1); lcd.write(4); lcd.setCursor(10, 1); lcd.write(5); lcd.setCursor(12, 1); lcd.write(6); lcd.setCursor(14, 1); lcd.write(7); }

The output appears as shown.

Code Explanation:

After including the library and creating the LCD object, custom character arrays are defined. The array consists of 8 bytes, with each byte representing a row in a 5×8 matrix.

This sketch contains eight custom-characters. Take, for example, the

Heart[8]

array. You can see that the bits (0s and 1s) are forming the shape of a heart. 0 turns the pixel off, and 1 turns it on.


byte Heart[8] = { 0b00000, 0b01010, 0b11111, 0b11111, 0b01110, 0b00100, 0b00000, 0b00000 };

In the setup, we use the

createChar()

function to create a custom character. This function accepts two parameters: a number between 0 and 7 to reserve one of the eight supported custom characters, and the name of the array.


lcd.createChar(0, Heart);

In the loop, to display the custom character, we simply call the

write()

function and pass it the number of the character we reserved earlier.


lcd.setCursor(0, 1); lcd.write(0);

Display

A library for I2C LCD displays.
The library allows to control I2C displays with functions extremely similar to LiquidCrystal library. THIS LIBRARY MIGHT NOT BE COMPATIBLE WITH EXISTING SKETCHES.

Maintainer: Marco Schwartz

This library is compatible with the avr architecture so you should be able to use it on the following Arduino boards:

Note: while the library is supposed to compile correctly on these architectures, it might require specific hardware features that may be available only on some boards.

To use this library, open the Library Manager in the Arduino IDE and install it from there.

Module I2C Arduino

LCD có quá nhiều nhiều chân gây khó khăn trong quá trình đấu nối và chiếm dụng nhiều chân trên vi điều khiển.

Module I2C LCD ra đời và giải quyết vấn để này cho bạn.

Thay vì phải mất 6 chân vi điều khiển để kết nối với LCD 16×2 (RS, EN, D7, D6, D5 và D4) thì module IC2 bạn chỉ cần tốn 2 chân (SCL, SDA) để kết nối.

Module I2C hỗ trợ các loại LCD sử dụng driver HD44780(LCD 16×2, LCD 20×4, …) và tương thích với hầu hết các vi điều khiển hiện nay.

Ưu điểm

  • Tiết kiệm chân cho vi điều khiển.
  • Dễ dàng kết nối với LCD.

Thông số kĩ thuật

  • Điện áp hoạt động: 2.5-6V DC.
  • Hỗ trợ màn hình: LCD1602,1604,2004 (driver HD44780).
  • Giao tiếp: I2C.
  • Địa chỉ mặc định: 0X27 (có thể điều chỉnh bằng ngắn mạch chân A0/A1/A2).
  • Tích hợp Jump chốt để cung cấp đèn cho LCD hoặc ngắt.
  • Tích hợp biến trở xoay điều chỉnh độ tương phản cho LCD.

Để sử dụng màn hình LCD giao tiếp I2C sử dụng Arduino thì ta cần cài đặt thư viện Liquidcrystal_I2C. Tại đây

ARDUINO 20x4 LCD i2c Tutorial | How to Print Text On LCD Display
ARDUINO 20×4 LCD i2c Tutorial | How to Print Text On LCD Display

How to find the I2C address of my LCD?

Most I2C LCDs ship with the default address ‘0x27’, but it can be different depending on the batch/manufacturer. If this is the case, you will need to find the actual address of the LCD before you can start using it. On the Arduino website, you can find a simple example sketch that scans the I2C-bus for devices. If a device is found, it will display the address in the serial monitor.

/*I2C_scanner This sketch tests standard 7-bit addresses. Devices with higher bit address might not be seen properly. */ #include “Wire.h” void setup() { Wire.begin(); Serial.begin(9600); while (!Serial); Serial.println(“\nI2C Scanner”); } void loop() { byte error, address; int nDevices; Serial.println(“Scanning…”); nDevices = 0; for (address = 1; address < 127; address++ ) { Wire.beginTransmission(address); error = Wire.endTransmission(); if (error == 0) { Serial.print(“I2C device found at address 0x”); if (address < 16) Serial.print(“0″); Serial.print(address, HEX); Serial.println(” !”); nDevices++; } else if (error == 4) { Serial.print(“Unknown error at address 0x”); if (address < 16) Serial.print(“0”); Serial.println(address, HEX); } } if (nDevices == 0) Serial.println(“No I2C devices found\n”); else Serial.println(“done\n”); delay(5000); }

If you upload this sketch to the Arduino and run it, you should see the following output in the Serial Monitor (Ctrl + Shift + M).

Write down the address you find, you will need it later when programming the LCD.

Adjusting the contrast of the LCD

After you have wired up the LCD, you will need to adjust the contrast of the display. On the I2C module, you will find a potentiometer that you can turn with a small screwdriver.

Plug in the USB connector of the Arduino to power the LCD. You should see the backlight light up. Now rotate the potentiometer until one (16×2 LCD) or 2 rows (20×4 LCD) of rectangles appear. You can tweak the contrast later if needed.

Once that is done, we can start programming the LCD.

Arduino Black LCD 16x4 I2C Code Character Module Display High Contrast
Arduino Black LCD 16×4 I2C Code Character Module Display High Contrast

Tutorial- 8051 Microcontroller

Format Documents Name Version Language Update Date Size
1.0 English

Jun-18-2009

5K
1.0 English

Mar-30-2016

312K
N/A N/A

N/A

N/A
Gross Weight (kg) 0.1000
Manufacturer EastRising
Continuity Supply We promise the long term continuity supply for this product no less than 10 years since 2015.
Part Number ERM1604FS-1
Display Format 16×4 Character
Interface 6800 4-bit Parallel , 6800 8-bit Parallel
IC or Equivalent AIP31066 , HD44780, KS0066 , SPLC780 , ST7066
Appearance Black on White
Diagonal Size 1.9“
Connection Pin Header
Outline Dimension 87.0(W)x60.0(H)x12.5(T)mm
Visual Area 61.70×25.20mm
Active Area 56.20×20.80mm
Dot (Pixel) Size 0.55×0.55mm
Dot (Pixel) Pitch 0.60×0.60mm
IC Package COB
Display Type FSTN-LCD Grey
Touch Panel Optional No
Sunlight Readable Yes
Viewing Direction 6:00
Viewing Angle Range Left:50.0 , Right:50.0 , Up:40.0 , Down:40.0 degree
Brightness(Typ) 80cd/m2
Backlight Color White Color
Backlight Current (Typ) 45mA
Power Supply(Typ) 3.3V, 5V
Supply Current for LCM(Max) 1800uA
Operating Temperature -20℃~70℃
Storage Temperature -30℃~80℃

This article includes everything you need to know about using a character I2C LCD with Arduino. I have included a wiring diagram and many example codes to help you get started.

The first part of this article covers the basics of displaying text and numbers. In the second half, I will go into more detail on how to display custom characters and how you can use the other functions of the LiquidCrystal_I2C library.

Once you know how to display text and numbers on the LCD, I suggest you take a look at the articles below. In these tutorials, you will learn how to measure and display sensor data on the LCD.

Description

ERM1604FS-1 is 16 characters wide,4 rows character lcd module,SPLC780C controller (Industry-standard HD44780 compatible controller),6800 4/8-bit parallel interface,single led backlight with white color included can be dimmed easily with a resistor or PWM,fstn-lcd positive,black text on the white color,high contrast,wide operating temperature range,wide view angle,rohs compliant,built in character set supports English/Japanese text, see the SPLC780C datasheet for the full character set. It’s optional for pin header connection,5V or 3.3V power supply and I2C adapter board for arduino.

It’s easily controlled by MCU such as 8051,PIC,AVR,ARDUINO,ARM and Raspberry Pi.It can be used in any embedded systems,industrial device,security,medical and hand-held equipment.

Of course, we wouldn’t just leave you with a datasheet and a “good luck!”.For 8051 microcontroller user,we prepared the detailed tutorial such as interfacing, demo code and Development Kit at the bottom of this page.

How to use IIC I2C 2004 204 20 x 4 Character LCD with Arduino
How to use IIC I2C 2004 204 20 x 4 Character LCD with Arduino

Giao tiếp I2C LCD Arduino

Module I2C LCD 16×2 Arduino UNO
GND GND
VCC 5V
SDA A4/SDA
SCL A5/SCL

Sơ đồ đấu nối

Các linh kiện cần thiết cho dự án:

Tên linh kiện Số lượng Shopee
Arduino UNO R3 Mua ngay
Dây cáp nạp Mua ngay
Màn hình LCD 16×2 Mua ngay
Module I2C LCD 16×2 Mua ngay
Dây cắm (Đực – Cái) Mua ngay

Bạn sẽ học được gì

  • Có kiến thức cơ bản về Robotics
  • Chế tạo Robot dò đường thông minh
  • Đánh thức nhà khoa học bên trong bạn
  • Tìm hiểu thêm về Robotics, các thuật toán Robot tự động
  • Kiến thức nền tảng để chế tạo các máy móc tự động phục vụ đời sống sinh hoạt, lao động sản xuất
  • Kiến thức để chế tạo sản phẩm, tham gia các cuộc thi khoa học công nghệ trong nước và quốc tế

Introduction: How to Interface a 16×4 LCD With an Arduino

Introduction

I recently received some free LCD samples from my friends at FocusLCDs.com. One of which is a 16×4 LCD; P/N: C164AXBSYLY6WT. It uses a ST7066U controller (see datasheet here) instead of the HD44780 commonly found in LCD shields. I am not so sure if it will work with an Arduino and its libraries, so I wanted to try it out.

Summary of Features

  • Sharper Image, Wider Viewing Angle
  • Driver: ST7066U
  • Yellow Background
  • Y/G Backlight
  • Temperature Range: -20° C to +70° C
  • ROHS Compliant
Arduino LCD I2C - Tutorial with Arduino Uno
Arduino LCD I2C – Tutorial with Arduino Uno

Basic Arduino example code for I2C LCD

You can upload the following example code to the Arduino using the Arduino IDE.

For this tutorial, I used this 16×2 I2C character LCD display, but you can use other I2C LCDs of different sizes as well. This example sketch will display the classic ‘Hello World!’ on the first line of the LCD and ‘LCD tutorial’ on the second line.

Next, I will explain how the code works.

/* I2C LCD with Arduino example code. More info: https://www.makerguides.com */ #include “Wire.h” // Library for I2C communication #include “LiquidCrystal_I2C.h” // Library for LCD // Wiring: SDA pin is connected to A4 and SCL pin to A5. // Connect to LCD via I2C, default address 0x27 (A0-A2 not jumpered) LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 16, 2); // Change to (0x27,20,4) for 20×4 LCD. void setup() { // Initiate the LCD: lcd.init(); lcd.backlight(); } void loop() { // Print ‘Hello World!’ on the first line of the LCD: lcd.setCursor(2, 0); // Set the cursor on the third column and first row. lcd.print(“Hello World!”); // Print the string “Hello World!” lcd.setCursor(2, 1); //Set the cursor on the third column and the second row (counting starts at 0!). lcd.print(“LCD tutorial”); }

You should see the following output on the LCD:

How the code works

First, the required libraries are included. As mentioned earlier we need both the Wire.h and the LiquidCrystal_I2C library. In the rest of this tutorial, I will cover more of the built-in functions of this library.

*When using the latest version of the LiquidCrystal_I2C library it is no longer needed to include the wire.h library in your sketch. The other library imports wire.h automatically.

#include “Wire.h” // Library for I2C communication #include “LiquidCrystal_I2C.h” // Library for LCD

The next step is to create an LCD object with the LiquidCrystal_I2C class and specify the address and dimensions. For this, we use the function

LiquidCrystal_I2C(address, columns, rows)

.

This is where you will need to change the default address to the address you found earlier if it happens to be different. When using a 20×4 LCD, change this line to

LiquidCrystal_I2C(0x27,20,4);

Note that we have called the display ‘lcd’. You can give it a different name if you want like ‘menu_display’. You will need to change ‘lcd’ to the new name in the rest of the sketch.

// Connect to LCD via I2C, default address 0x27 (A0-A2 not jumpered) LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 16, 2); // Change to (0x27,20,4) for 20×4 LCD.

Setup

In the setup, the LCD is initiated with

lcd.init()

and the backlight is turned on with

lcd.backlight()

.

void setup() { // Initiate the LCD: lcd.init(); lcd.backlight(); }

Loop

In the loop section of the code, the cursor is set to the third column and the first row of the LCD with

lcd.setCursor(2,0)

.

Note that counting starts at 0 and the first argument specifies the column. So

lcd.setCursor(2,1)

sets the cursor on the third column and the second row.

Next the string ‘Hello World!’ is printed with

lcd.print("Hello World!")

. Note that you need to place quotation marks (” “) around the text since we are printing a text string.

When you want to print numbers, no quotation marks are necessary. For example

lcd.print(12345)

.

void loop() { lcd.setCursor(2, 0); // Set the cursor on the third column and first row. lcd.print(“Hello World!”); // Print the string “Hello World!”. lcd.setCursor(2, 1); //Set the cursor on the third column and the second row. lcd.print(“LCD tutorial”); // Print the string “LCD tutorial”. }

If you want to see an example for displaying (changing) variables on the LCD, check out my tutorial for the HC-SR04 ultrasonic distance sensor:

Step 6: View the Result

Congratulations! Your LCD should show something like this.

If you’ve ever attempted to connect an LCD display to an Arduino, you’ve probably noticed that it uses a lot of Arduino pins. Even in 4-bit mode, the Arduino requires seven connections – half of the Arduino’s available digital I/O pins.

The solution is to use an I2C LCD display. It only uses two I/O pins that are not even part of the digital I/O pin set and can be shared with other I2C devices.

Introduction to LCD2004 LCD display with I2C module for Arduino
Introduction to LCD2004 LCD display with I2C module for Arduino

Hardware Overview

A typical I2C LCD display consists of an HD44780-based character LCD display and an I2C LCD adapter. Let’s learn more about them.

Character LCD Display

As the name suggests, these LCDs are ideal for displaying only characters. A 16×2 character LCD, for example, can display 32 ASCII characters across two rows.

If you look closely, you can see tiny rectangles for each character on the screen as well as the pixels that make up a character. Each of these rectangles is a grid of 5×8 pixels.

Please refer to our in-depth guide for more information about character LCD displays.

I2C LCD Adapter

At the heart of the adapter is an 8-bit I/O expander chip – PCF8574. This chip converts the I2C data from an Arduino into the parallel data required for an LCD display.

The board also includes a tiny trimpot for making precise adjustments to the display’s contrast.

There is a jumper on the board that provides power to the backlight. To control the intensity of the backlight, you can remove the jumper and apply external voltage to the header pin labeled ‘LED’.

Tutorial – Arduino

Format Documents Name Version Language Update Date Size
Arduino Libraries and Examples for Character Display 1.0 English Jul-23-2019

45K

Interfacing I2C Adapter Board to Arduino 1.0 English Aug-12-2019 97K
Arduino i2c 16x4 LCD Display Menu. Greenhouse monitoring system Part 2
Arduino i2c 16×4 LCD Display Menu. Greenhouse monitoring system Part 2

Other useful functions of the LiquidCrystal_I2C library

The example sketch above shows you the basics of displaying text on the LCD. Now we will take a look at the other functions of the LiquidCrystal_I2C library.

clear()

Clears the LCD screen and positions the cursor in the upper-left corner (first row and first column) of the display. You can use this function to display different words in a loop.

#include “LiquidCrystal_I2C.h” LiquidCrystal_I2C lcd(0x27, 16, 2); void setup() { lcd.init(); lcd.backlight(); } void loop() { lcd.clear(); lcd.print(“Monday”); delay(2000); lcd.clear(); lcd.print(“13:45”); delay(2000); }

home()

Positions the cursor in the top-left corner of the LCD. Use

clear()

if you also want to clear the display.

cursor()

Displays the LCD cursor: an underscore (line) at the position of the next character to be printed.

noCursor()

Hides the LCD cursor. The following example creates a blinking cursor at the end of “Hello World!”.

#include “LiquidCrystal_I2C.h” LiquidCrystal_I2C lcd(0x27, 16, 2); void setup() { lcd.init(); lcd.backlight(); lcd.print(“Hello World!”); } void loop() { lcd.cursor(); delay(500); lcd.noCursor(); delay(500); }

blink()

Creates a blinking block style LCD cursor: a blinking rectangle at the position of the next character to be printed.

noBlink()

Disables the block style LCD cursor. The following example displays the blinking cursor for 5 seconds and then disables it for 2 seconds.

#include “LiquidCrystal_I2C.h” LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 16, 2); void setup() { lcd.init(); lcd.backlight(); lcd.print(“blink() example”); } void loop() { lcd.blink(); delay(5000); lcd.noBlink(); delay(2000); }

display()

This function turns on the LCD screen and displays any text or cursors that have been printed to the display.

noDisplay()

This function turns off any text or cursors printed to the LCD. The text/data is not cleared from the LCD memory.

This means it will be shown again when the function

display()

is called.

The following example creates a blinking text effect.

#include “LiquidCrystal_I2C.h” LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 16, 2); void setup() { lcd.init(); lcd.backlight(); lcd.print(“Blinking text”); } void loop() { lcd.display(); delay(2000); lcd.noDisplay(); delay(2000); }

write()

This function can be used to write a character to the LCD. See the section about creating and displaying custom characters below for more info.

scrollDisplayLeft()

Scrolls the contents of the display (text and cursor) one space to the left.

You can use this function in the loop section of the code in combination with

delay(500)

, to create a scrolling text animation.

#include “LiquidCrystal_I2C.h” LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 16, 2); void setup() { lcd.init(); lcd.backlight(); lcd.print(“Hello World!”); } void loop() { lcd.scrollDisplayLeft(); delay(500); }

scrollDisplayRight()

Scrolls the contents of the display (text and cursor) one space to the right.

autoscroll()

This function turns on automatic scrolling of the LCD. This causes each character output to the display to push previous characters over by one space.

If the current text direction is left-to-right (the default), the display scrolls to the left, if the current direction is right-to-left, the display scrolls to the right.

This has the effect of outputting each new character to the same location on the LCD.

The following example sketch enables automatic scrolling and prints the character 0 to 9 at the position (16,0) of the LCD. Change this to (20,0) for a 20×4 LCD.

#include “LiquidCrystal_I2C.h” LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 16, 2); void setup() { lcd.init(); lcd.backlight(); } void loop() { lcd.autoscroll(); lcd.setCursor(16, 0); for (int x = 0; x < 10; x++) { lcd.print(x); delay(500); } lcd.clear(); }

noAutoscroll()

Turns off automatic scrolling of the LCD.

leftToRight()

This function causes text to flow to the right from the cursor, as if the display is left-justified (default).

rightToLeft()

This function causes text to flow to the left from the cursor, as if the display is right-justified.

Conclusion

In this article, I have shown you how to use a character I2C LCD with Arduino.

I hope you found it useful and informative. If you did, please share it with a friend that also likes electronics and making things!

I would love to know what projects you plan on building (or have already built) with these LCDs. If you have any questions, suggestions or if you think that things are missing in this tutorial, please leave a comment down below.

Note that comments are held for moderation to prevent spam.

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

How to use 16x2 and 20x4  LCD Display with Arduino || Liquid Crystal I2C Library Download
How to use 16×2 and 20×4 LCD Display with Arduino || Liquid Crystal I2C Library Download

Supplies

Hardware components

16×2 character I2C LCD × 1 Amazon
20×4 character I2C LCD (alternative) × 1 Amazon
Arduino Uno Rev3 × 1 Amazon
Jumper wires (male to female) × 4 Amazon
USB cable type A/B × 1 Amazon

Tools

Small screwdriver Amazon

Software

Arduino IDE

Makerguides.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to products on Amazon.com. As an Amazon Associate we earn from qualifying purchases.

Other useful functions of the LiquidCrystal_I2C Library

There are many useful functions you can use with LiquidCrystal_I2C Object. Some of them are listed below:


  • lcd.home()

    function positions the cursor in the upper-left of the LCD without clearing the display.

  • lcd.blink()

    function displays a blinking block of 5×8 pixels at the position to which the next character will be written.

  • lcd.noBlink()

    function turns off the blinking LCD cursor.

  • lcd.cursor()

    function displays an underscore (line) at the position to which the next character will be written.

  • lcd.noCursor()

    function hides the LCD cursor.

  • lcd.scrollDisplayRight()

    function scrolls the contents of the display one space to the right. If you want the text to scroll continuously, you have to use this function inside a

    for

    loop.

  • lcd.scrollDisplayLeft()

    function scrolls the contents of the display one space to the left. Similar to the above function, use this inside a

    for

    loop for continuous scrolling.

  • lcd.noDisplay()

    function turns off the LCD display, without losing the text currently shown on it.

  • lcd.display()

    function turns on the LCD display, after it’s been turned off with

    noDisplay()

    . This will restore the text (and cursor) that was on the display.
How to use a 1602 i2c Serial LCD Display with Arduino
How to use a 1602 i2c Serial LCD Display with Arduino

Lời kết

Qua bài hôm nay các bạn biết cách làm thế nào để hiển thị các ký tự và chuỗi ký tự lên LCD 16×2 và biết cách giao tiếp I2C.

Để nhận được nhiều kiến thức mới các bạn Đăng ký để nhận được thông báo sớm nhất.

Tham gia Cộng đồng Arduino KIT để cùng nhau thảo luận và chia sẽ kiến thức về lập trình Arduino.

Nếu các bạn thấy bài viết bổ ích nhớ Like và Share cho mọi người cùng đọc nhé.

Chúc các bạn thành công.

Trân trọng.

Arduino LCD 16×4 I2C Character Display Module Wide View Angle

  • Buy 10 for US$6.52 each and save 3%
  • Buy 30 for US$6.34 each and save 5%
  • Buy 50 for US$6.17 each and save 8%
  • Buy 100 for US$5.99 each and save 11%
  • Buy 500 or more Quote Request
  • This Item:
    Arduino LCD 16×4 I2C Character Display Module Wide View Angle
    US$6.70
  • 8051 Microcontroller Development Board for Character LCD ERM1604-1
    US$44.75
  • Total price

Basic Arduino Sketch – Hello World

The test sketch below will print ‘Hello World!’ on the first line of the LCD and ‘LCD Tutorial’ on the second.

However, before you upload the sketch, you must make a minor change to make it work for you. You must pass the I2C address of your LCD as well as the display dimensions to the LiquidCrystal_I2C constructor. If you’re using a 16×2 character LCD, pass 16 and 2; if you’re using a 20×4 character LCD, pass 20 and 4.


// enter the I2C address and the dimensions of your LCD here LiquidCrystal_I2C lcd(0x3F, 16, 2);

Once you are done, go ahead and try the sketch.


#include LiquidCrystal_I2C lcd(0x3F,16,2); // set the LCD address to 0x3F for a 16 chars and 2 line display void setup() { lcd.init(); lcd.clear(); lcd.backlight(); // Make sure backlight is on // Print a message on both lines of the LCD. lcd.setCursor(2,0); //Set cursor to character 2 on line 0 lcd.print("Hello world!"); lcd.setCursor(2,1); //Move cursor to character 2 on line 1 lcd.print("LCD Tutorial"); } void loop() { }

This is what you should see on the screen.

Code Explanation:

The sketch begins by including the LiquidCrystal_I2C library.


#include

The next step is to create an object of LiquidCrystal_I2C class. The LiquidCrystal_I2C constructor accepts three inputs: I2C address, number of columns, and number of rows of the display.


LiquidCrystal_I2C lcd(0x3F,16,2);

In the setup, three functions are called. The first function is

init()

. It initializes the interface to the LCD. The second function is

clear()

. This function clears the LCD screen and positions the cursor in the upper-left corner. The third function,

backlight()

, turns on the LCD backlight.


lcd.init(); lcd.clear(); lcd.backlight();

The function

setCursor(2, 0)

is then called to move the cursor to the third column of the first row. The cursor position specifies where you want the new text to appear on the LCD. It is assumed that the upper left corner is

col=0

and

row=0

.


lcd.setCursor(2,0);

Next, the

print()

function is used to print “Hello world!” to the LCD.


lcd.print("Hello world!");

Similarly, the next two lines of code move the cursor to the third column of the second row and print ‘LCD Tutorial’ to the LCD.


lcd.setCursor(2,1); lcd.print("LCD Tutorial");

Top 20 Arduino LCD Animation Projects || animation lcd 16x2 || LCD Custom Animation Project
Top 20 Arduino LCD Animation Projects || animation lcd 16×2 || LCD Custom Animation Project

How to connect the I2C LCD to Arduino UNO

The wiring diagram below shows you how to connect the I2C LCD to the Arduino. Wiring an I2C LCD is a lot easier than connecting a standard LCD. You only need to connect 4 pins instead of 12.

The connections are also given in the table below.

I2C LCD Connections

I2C Character LCD Arduino
GND GND
VCC 5 V
SDA A4
SCL A5

If you are not using an Arduino Uno, the SDA and SCL pins can be at a different location.

Note that an Arduino Uno with the R3 layout (1.0 pinout) also has the SDA (data line) and SCL (clock line) pin headers close to the AREF pin. Check the table below for more details.

Board SDA SCL
Arduino Uno A4 A5
Arduino Nano A4 A5
Arduino Micro
Arduino Mega 2560 20 21
Arduino Leonardo
Arduino Due 20 21

Các lỗi thường gặp khi sử dụng I2C LCD

  • Hiển thị một dãy ô vuông.
  • Màn hình chỉ in ra một ký tự đầu.
  • Màn hình nhấp nháy.

Các lỗi này chủ yếu là do sai địa chỉ bus, để fix lỗi các bạn thay địa chỉ mặc định là “0x27” thành “0x3F.

Trong trường hợp vẫn không được các bạn fix lỗi bằng cách nạp code tìm địa chỉ bus của I2C.

Sau khi tìm xong các bạn thay địa chỉ vừa tìm được vào vị trí “0x27” là xong.

  • Các bạn có thể tải code tìm địa chỉ bus ở đây. Tải ngay.
I2C LCD not showing Text | I2C LCD Errors Fixing || 16x2 LCD not displaying Text || 1602 LCD Error
I2C LCD not showing Text | I2C LCD Errors Fixing || 16×2 LCD not displaying Text || 1602 LCD Error

Library Installation

Before you can proceed, you must install the LiquidCrystal_I2C library. This library allows you to control I2C displays using functions that are very similar to the LiquidCrystal library.

To install the library, navigate to Sketch > Include Library > Manage Libraries… Wait for the Library Manager to download the library index and update the list of installed libraries.

Filter your search by entering ‘liquidcrystal‘. Look for the LiquidCrystal I2C library by Marco Schwartz. Click on that entry and then choose Install.

Installing the LiquidCrystal_I2C Arduino library

In this tutorial, I will be using the LiquidCrystal_I2C library. This library has many built-in functions that make programming the LCD quite easy.

The latest version of this library can be found here on GitHub or click the download button below.

Make sure that you have this exact library installed and delete any other libraries that have the same name (LiquidCrystal_I2C). Other libraries will probably work as well but might use slightly different names for the different functions.

The LiquidCrystal_I2C library works in combination with the Wire.h library which allows you to communicate with I2C devices. This library comes pre-installed with the Arduino IDE.

To install this library, go to Tools > Manage Libraries (Ctrl + Shift + I on Windows) in the Arduino IDE. The Library Manager will open and update the list of installed libraries.

Now search for ‘liquidcrystal_i2c’ and look for the library by Frank de Brabander. Select the latest version and then click Install.

The library does include some examples that you can use, but you will have to modify them to match your hardware setup. I have included many example codes below that you can use with the wiring setup I have shown earlier.

First I will show you some basic example code and then I will explain the functions in more detail.

How to Use 16x2 i2C LCD Display With ESP32 | With Program Explanation
How to Use 16×2 i2C LCD Display With ESP32 | With Program Explanation

Wiring an I2C LCD Display to an Arduino

Connecting an I2C LCD is much simpler than connecting a standard LCD. You only need to connect four pins.

Begin by connecting the VCC pin to the Arduino’s 5V output and the GND pin to ground.

Now we are left with the pins that are used for I2C communication. Note that each Arduino board has different I2C pins that must be connected correctly. On Arduino boards with the R3 layout, the SDA (data line) and SCL (clock line) are on the pin headers close to the AREF pin. They are also referred to as A5 (SCL) and A4 (SDA).

The following table lists the pin connections:

I2C LCD Arduino
VCC 5V
GND GND
SCL SCL or A5
SDA SDA or A4

The diagram below shows how to connect everything.

Determining the I2C Address

As previously stated, the I2C address of your LCD depends on the manufacturer. If your LCD has a PCF8574 chip from Texas Instruments, its I2C address is 0x27; if it has a PCF8574 chip from NXP Semiconductors, its I2C address is 0x3F.

If you’re not sure what your LCD’s I2C address is, you can run a simple I2C scanner sketch that scans your I2C bus and returns the address of each I2C device it finds.

You can find this sketch under File > Examples > Wire > i2c_scanner.

Load the i2c_scanner sketch into your Arduino IDE.


#include

void setup() { Wire.begin(); Serial.begin(9600); while (!Serial); // Leonardo: wait for serial monitor Serial.println("\nI2C Scanner"); } void loop() { int nDevices = 0; Serial.println("Scanning..."); for (byte address = 1; address < 127; ++address) { // The i2c_scanner uses the return value of // the Write.endTransmisstion to see if // a device did acknowledge to the address. Wire.beginTransmission(address); byte error = Wire.endTransmission(); if (error == 0) { Serial.print("I2C device found at address 0x"); if (address < 16) { Serial.print("0"); } Serial.print(address, HEX); Serial.println(" !"); ++nDevices; } else if (error == 4) { Serial.print("Unknown error at address 0x"); if (address < 16) { Serial.print("0"); } Serial.println(address, HEX); } } if (nDevices == 0) { Serial.println("No I2C devices found\n"); } else { Serial.println("done\n"); } delay(5000); // Wait 5 seconds for next scan }

After you’ve uploaded the sketch, launch the serial monitor at 9600 baud. You should see the I2C address of your I2C LCD display.

Please make a note of this address. You’ll need it in later examples.

How to solder header pins to 2x16 LCD
How to solder header pins to 2×16 LCD

Specifications

The specifications of the 16×2, 20×4, and other sized LCDs are mostly the same. They all use the same HD44780 Hitachi LCD controller, so you can easily swap them. You will only need to change the size specifications in your Arduino code.

The specifications of a typical 16×2 I2C display can be found in the table below.

16×2 I2C LCD Specifications

Operating voltage 5 V
Controller Hitachi HD44780 LCD controller
Default address 0x27
Screen resolution 2-lines × 16 characters
Character resolution 5 × 8 pixels
Module dimensions 80 × 36 × 12 mm
Viewing area dimensions 64.5 × 16.4 mm
Cost Check price

For more information, you can check out the datasheets below.

The 16×2 and 20×4 datasheets include the dimensions of the LCD and you can find more information about the Hitachi LCD driver in the HD44780 datasheet.

The PCF8574 chip is used in the I2C module on the back of the LCD.

#include

#include #define BACKLIGHT_PIN 13
LiquidCrystal_I2C lcd(0x20); // Set the LCD I2C address
void setup()
{
// Switch on the backlight
pinMode ( BACKLIGHT_PIN, OUTPUT );
digitalWrite ( BACKLIGHT_PIN, HIGH );
lcd.begin(16,4); // initialize the lcd
lcd.home (); // go home
lcd.print(“Hello, ARDUINO “);
lcd.setCursor ( 0, 1 ); // go to the next line
lcd.print (” FORUM – fm “);
}
void loop()
{
}

In this case it doesn’t look like any of the standard devices. On the page you linked I cannot find a datasheet or manual. You should never buy stuff from a supplier that doesn’t provide datasheets.
Are you able to get the a photo of the other side of the smaller PCB, so we might find out what chips are mounted there? The library you’re using is built for an I2C IO expander module that then drives the 4bit LCD interface. Because your module also offers an SPI interface it probably is controlled by a microprocessor and may speak a higher level “protocol”.

In this web you can find the Library and the schematic.

I have tested it, but the display not work properly.

/*
Demonstration sketch for Adafruit i2c/SPI LCD backpack
using MCP23008 I2C expander
( http://www.ladyada.net/products/i2cspilcdbackpack/index.html )
This sketch prints “Hello World!” to the LCD
and shows the time.
The circuit:
* 5V to Arduino 5V pin
* GND to Arduino GND pin
* CLK to Analog #5
* DAT to Analog #4
*/
// include the library code:
#include

#include // Connect via i2c, default address #0 (A0-A2 not jumpered)
LiquidCrystal lcd(0);
void setup() {
// set up the LCD’s number of rows and columns:
lcd.begin(16, 4);
// Print a message to the LCD.
lcd.print(“hello, world!”);
}
void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(millis()/1000);
lcd.setBacklight(HIGH);
delay(500);
lcd.setBacklight(LOW);
delay(500);
}

I would try to modify the library and check the return value of Wire.endTransmission() and Wire.requestFrom(). If they are 0 there was an I2C error (NAK received in most cases) and you know that you have to look for hardware errors.

Tổng quan LCD 16×2 và giao tiếp I2C LCD sử dụng Arduino

Arduino LCD I2C tutorial | how to program LCD
Arduino LCD I2C tutorial | how to program LCD

Giới thiệu LCD 16×2

Thông số kỹ thuật LCD 16×2

LCD 16×2 được sử dụng để hiển thị trạng thái hoặc các thông số.

  • LCD 16×2 có 16 chân trong đó 8 chân dữ liệu (D0 – D7) và 3 chân điều khiển (RS, RW, EN).
  • 5 chân còn lại dùng để cấp nguồn và đèn nền cho LCD 16×2.
  • Các chân điều khiển giúp ta dễ dàng cấu hình LCD ở chế độ lệnh hoặc chế độ dữ liệu.
  • Chúng còn giúp ta cấu hình ở chế độ đọc hoặc ghi.

LCD 16×2 có thể sử dụng ở chế độ 4 bit hoặc 8 bit tùy theo ứng dụng ta đang làm.

Step 5: Code the Sketch

Type in this sketch in the IDE and upload.

/* This is a sketch to test 16×4 LCD:

* FocusLCD P/N: C164AXBSYLY6WT

*/

#include LiquidCrystal lcd(8,9,4,5,6,7);

void setup() {

lcd.begin(16,4);

lcd.setCursor(0,0);

lcd.print(“FocusLCDs.com”);

lcd.setCursor(0,1);

lcd.print(“The BEST LCDs!”);

lcd.setCursor(0,2);

lcd.print(“P/N: “);

lcd.setCursor(0,3);

lcd.print(“C164AXBSYLY6WT”);

void loop() {

How to Set Up and Program an LCD on the Arduino
How to Set Up and Program an LCD on the Arduino

I2C LCD Basics

This guide is part of our hub of articles on Arduino Displays. This type of LCD is ideal for displaying text and numbers, hence the name ‘character LCD’.

The I2C LCD that we are using in this tutorial comes with a small add-on circuit mounted on the back of the module. This module features a PCF8574 chip (for I2C communication) and a potentiometer to adjust the LED backlight.

The advantage of an I2C LCD is that the wiring is very simple. You only need two data pins to control the LCD. Standard LCDs typically require around 12 connections, which can be a problem if you do not have many GPIO pins available.

Luckily, you can also buy the I2C add-on circuit separately on Amazon, so you can easily upgrade a standard LCD as well.

For a tutorial and wiring diagram for standard character LCDs, please see the following article:

If you look closely at the LCD, you can see the small rectangles that form the individual characters of the LCD. Each rectangle is made up of a grid of 5×8 pixels. Later in this tutorial, I will show you how you can control the individual pixels to display custom characters on the LCD.

Code mẫu

#include

#include LiquidCrystal_I2C lcd(0x3F,16,2); void setup() { lcd.init(); lcd.backlight(); lcd.setCursor(2,0); lcd.print(“Arduinokit.vn”); lcd.setCursor(0,1); lcd.print(“Xin chao cac ban”); } void loop() { }

Giải thích code

LiquidCrystal_I2C lcd(0x3F,16,2);

  • Đặt địa chỉ LCD là 0x3F cho màn hình LCD 16×2.
  • 16 là số cột của màn hình (nếu dùng loại màn hình 20×4) thì thay bằng 20.
  • 2 là số dòng của màn hình (nếu dùng loại màn hình 20×4) thì thay bằng 4.

lcd.init();

Khởi động màn hình LCD, bắt đầu cho phép Arduino sử dụng màn hình.

lcd.backlight();

Bật đèn nền LCD 16×2.

lcd.setCursor(2,0);

Đưa con trỏ tới hàng 1, cột 3.

Lưu ý: giá trị hàng và cột bắt đầu từ số 0 có nghĩa 0 là hàng(cột) 1.

lcd.print(“Arduinokit.vn”);

Xuất ra dòng chữ Arduinokit.vn tại vị trí con trỏ ở hàng 1, cột 3.

lcd.setCursor(0,1); lcd.print(“Xin chao cac ban”);

Đoạn code này thì tương tự như trên, xuất ra dòng chữ “Xin chao cac ban” tại vị trí con trỏ ở hàng 2, cột 1.

Bây giờ thì các bạn upload chương trình và xem kết quả nhé.

HOWTO Raspberry Pi + LCD 16x2 i2c
HOWTO Raspberry Pi + LCD 16×2 i2c

Datasheet for Character LCD Module,Controller IC,Adapter Board

Format Documents Name Version Language Update Date Size
16×4 Character LCD Module Datasheet 1.0 English Jul-12-2012

412K

Controller IC SPLC780C Datasheet 1.1 English Jul-09-2002 813K
Single Row I2C Adapter Board Drawing 1.0 English Jul-17-2019 203K

Adjusting The LCD Contrast

After wiring the LCD, you will need to adjust the contrast of the LCD. On the I2C module, there is a potentiometer that can be rotated with a small screwdriver.

Now, turn on the Arduino. You will see the backlight light up. As you turn the potentiometer knob, the first row of rectangles will appear. If you have made it this far, Congratulations! Your LCD is functioning properly.

LCD Not showing Text  || 16x2 LCD Not Displaying Text | Arduino 16x2 LCD not working | Arduino Tamil
LCD Not showing Text || 16×2 LCD Not Displaying Text | Arduino 16×2 LCD not working | Arduino Tamil

How to create and display custom characters?

With the function

createChar()

it is possible to create and display custom characters on the LCD. This is especially useful if you want to display a character that is not part of the standard ASCII character set.

CGROM and CGRAM

LCDs that are based on the Hitachi HD44780 LCD controller have two types of memory: CGROM and CGRAM (Character Generator ROM and RAM).

CGROM generates all the 5 x 8 dot character patterns from the standard 8-bit character codes. CGRAM can generate user-defined character patterns.

For 5 x 8 dot displays, CGRAM can write up to 8 custom characters and for 5 x 10 dot displays 4. For more info see the datasheet.

Custom character example code

The following example sketch creates and displays eight custom characters (numbered 0 – 7). You can copy the code by clicking on the button in the top right corner of the code field.

/* Arduino example code to display custom characters on I2C character LCD. More info: www.www.makerguides.com */ // Include the library: #include “LiquidCrystal_I2C.h” // Create lcd object of class LiquidCrystal_I2C: LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 16, 2); // Change to (0x27,20,4) for 20×4 LCD. // Make custom characters: byte Heart[] = { B00000, B01010, B11111, B11111, B01110, B00100, B00000, B00000 }; byte Bell[] = { B00100, B01110, B01110, B01110, B11111, B00000, B00100, B00000 }; byte Alien[] = { B11111, B10101, B11111, B11111, B01110, B01010, B11011, B00000 }; byte Check[] = { B00000, B00001, B00011, B10110, B11100, B01000, B00000, B00000 }; byte Speaker[] = { B00001, B00011, B01111, B01111, B01111, B00011, B00001, B00000 }; byte Sound[] = { B00001, B00011, B00101, B01001, B01001, B01011, B11011, B11000 }; byte Skull[] = { B00000, B01110, B10101, B11011, B01110, B01110, B00000, B00000 }; byte Lock[] = { B01110, B10001, B10001, B11111, B11011, B11011, B11111, B00000 }; void setup() { // Initialize LCD and turn on the backlight: lcd.init(); lcd.backlight(); // Create new characters: lcd.createChar(0, Heart); lcd.createChar(1, Bell); lcd.createChar(2, Alien); lcd.createChar(3, Check); lcd.createChar(4, Speaker); lcd.createChar(5, Sound); lcd.createChar(6, Skull); lcd.createChar(7, Lock); // Clear the LCD screen: lcd.clear(); // Print a message to the lcd: lcd.print(“Custom Character”); } // Print all the custom characters: void loop() { lcd.setCursor(0, 1); lcd.write(0); lcd.setCursor(2, 1); lcd.write(1); lcd.setCursor(4, 1); lcd.write(2); lcd.setCursor(6, 1); lcd.write(3); lcd.setCursor(8, 1); lcd.write(4); lcd.setCursor(10, 1); lcd.write(5); lcd.setCursor(12, 1); lcd.write(6); lcd.setCursor(14, 1); lcd.write(7); }

You should see the following output on the LCD:

How the code works

After including the library and creating the LCD object, the custom character arrays are defined. Each array consists of 8 bytes (only 5 bits are considered). There is 1 byte for each row of the 5 x 8 led matrix. In this example, 8 custom characters are created.

// Make custom characters: byte Heart[] = { B00000, B01010, B11111, B11111, B01110, B00100, B00000, B00000 };

When looking closely at the array, you will see the following. Each row consists of 5 numbers corresponding to the 5 pixels in a 5 x 8 dot character. A 0 means pixel off and a 1 means pixel on. The prefix ‘B’ is the Arduino specific binary formatter.

It is possible to edit each row by hand, but I recommend using this visual tool on GitHub. This application automatically creates the character array and you can click on the pixels to turn them on or off.

In the setup, the custom characters are created with

lcd.createChar(num, data)

. The first argument in this function is the number of the custom character (0-7) and the second argument is the character array that we created.

// Create new characters: lcd.createChar(0, Heart); lcd.createChar(1, Bell); lcd.createChar(2, Alien); lcd.createChar(3, Check); lcd.createChar(4, Speaker); lcd.createChar(5, Sound); lcd.createChar(6, Skull); lcd.createChar(7, Lock);

In the loop, all the characters are displayed with lcd.write(). As the argument, we use the number of the custom character that we want to display.

lcd.setCursor(0, 1); lcd.write(0);

Keywords searched by users: arduino lcd 16×4 i2c code

Graduated Scale Of The Value Of A Potentiometer Using A 16X4 - Hackster.Io
Graduated Scale Of The Value Of A Potentiometer Using A 16X4 – Hackster.Io
Setting Up A 16×4 Liquid Crystal Display To Show Hello World – The Chewett  Blog
Setting Up A 16×4 Liquid Crystal Display To Show Hello World – The Chewett Blog
Arduino Lcd 16X4 I2C Character Display Module Wide View Angle
Arduino Lcd 16X4 I2C Character Display Module Wide View Angle
Arduino I2C 16X4 Lcd Display Menu. Greenhouse Monitoring System Part 2 -  Youtube
Arduino I2C 16X4 Lcd Display Menu. Greenhouse Monitoring System Part 2 – Youtube
Character I2C Lcd With Arduino Tutorial (8 Examples)
Character I2C Lcd With Arduino Tutorial (8 Examples)
In-Depth: Interfacing An I2C Lcd With Arduino
In-Depth: Interfacing An I2C Lcd With Arduino
Arduino Black Lcd 16X4 I2C Code Character Module Display High Contrast -  Youtube
Arduino Black Lcd 16X4 I2C Code Character Module Display High Contrast – Youtube
Arduino And I2C Lcd In Proteus – Microcontrolere
Arduino And I2C Lcd In Proteus – Microcontrolere
Real Time Clock On 20X4 I2C Lcd Display With Arduino - Electronics-Lab.Com
Real Time Clock On 20X4 I2C Lcd Display With Arduino – Electronics-Lab.Com
Arduino Lcd 16X4 I2C Character Display Module Wide View Angle
Arduino Lcd 16X4 I2C Character Display Module Wide View Angle
Easy Arduino Lcd I2C Scrolling Text Animation | Scroll Text On Lcd Display  Arduino | I2C Lcd Scroll - Youtube
Easy Arduino Lcd I2C Scrolling Text Animation | Scroll Text On Lcd Display Arduino | I2C Lcd Scroll – Youtube
Real Time Clock On 20X4 I2C Lcd Display With Arduino - Electronics-Lab.Com
Real Time Clock On 20X4 I2C Lcd Display With Arduino – Electronics-Lab.Com
Lcd 16X4 (Kèm Module I2C) - Phụ Kiện Âm Thanh Và Hình Ảnh Cho Ô Tô [Hồ Chí  Minh] | Nghenhinviet.Com
Lcd 16X4 (Kèm Module I2C) – Phụ Kiện Âm Thanh Và Hình Ảnh Cho Ô Tô [Hồ Chí Minh] | Nghenhinviet.Com
How To Interface I2C Lcd With Arduino Nano
How To Interface I2C Lcd With Arduino Nano
Arduino Tutorial: 20X4 I2C Character Lcd Display With Arduino Uno From  Banggood.Com - Youtube
Arduino Tutorial: 20X4 I2C Character Lcd Display With Arduino Uno From Banggood.Com – Youtube
Iic I2C Twi 164 1604 16X4 Lcd Screen Module Character Series With Backlight  For Arduino-Digilog.Pk
Iic I2C Twi 164 1604 16X4 Lcd Screen Module Character Series With Backlight For Arduino-Digilog.Pk
I2C Lcd With Esp32 On Arduino Ide - Esp8266 Compatible | Random Nerd  Tutorials
I2C Lcd With Esp32 On Arduino Ide – Esp8266 Compatible | Random Nerd Tutorials
Graduated Scale Of The Value Of A Potentiometer Using A 16X4 - Hackster.Io
Graduated Scale Of The Value Of A Potentiometer Using A 16X4 – Hackster.Io
Simulation For I2C T0 Lcd 16X2 Using Proteus - Networking, Protocols, And  Devices - Arduino Forum
Simulation For I2C T0 Lcd 16X2 Using Proteus – Networking, Protocols, And Devices – Arduino Forum
Real Time Clock On 20X4 I2C Lcd Display With Arduino - Electronics-Lab.Com
Real Time Clock On 20X4 I2C Lcd Display With Arduino – Electronics-Lab.Com
Interface I2C 16X2 Lcd With Arduino Uno (Just 4 Wires) - Hackster.Io
Interface I2C 16X2 Lcd With Arduino Uno (Just 4 Wires) – Hackster.Io

See more here: kientrucannam.vn

Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *