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.
Hardware Required
Arduino UNO or Genuino UNO |
USB 2.0 cable type A/B |
LCD I2C |
Jumper Wires |
(Optional) 9V Power Adapter for Arduino |
(Recommended) Screw Terminal Block Shield for Arduino Uno |
(Optional) Transparent Acrylic Enclosure For Arduino Uno |
Or you can buy the following sensor kit:
DIYables Sensor Kit 30 types, 69 units |
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.
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.
#includeLiquidCrystal_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);
Arduino – LCD I2C
In this Arduino LCD I2C tutorial, we will learn how to connect an LCD I2C (Liquid Crystal Display) to the Arduino board. LCDs are very popular and widely used in electronics projects for displaying information. There are many types of LCD. This tutorial takes LCD 16×2 (16 columns and 2 rows) as an example. The other LCDs are similar.
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.
Troubleshooting on LCD I2C
If the text is not displayed on LCD I2C, please check the following issues:
- Adjust the brightness of LCD by rotating potentiometer in the backside of LCD
- Depending on manufacturers, the I2C address of LCD may be different. Usually, the default I2C address of LCD is 0x27 or 0x3F. Try these values one by one. If you still failed, run the below code to find the I2C address.
The result on Serial Monitor:
About LCD I2C 16×2
In the previous tutorial, we had learned how to use the normal LCD. However, wiring between Arduino and the normal LCD is complicated. Therefore, LCD I2C has been created to simplify the wiring. Actually, LCD I2C is composed of a normal LCD, an I2C module and a potentiometer.
Pinout
LCD I2C uses I2C interface, so it has 4 pins:
- GND pin: needs to be connected to GND (0V).
- VCC pin: the power supply for the LCD, needs to be connected to VCC (5V).
- SDA pin: I2C data signal
- SCL pin: I2C clock signal
LCD Coordinate
LCD I2C 16×2 includes 16 columns and 2 rows. the conlums and rows are indexed from 0.
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.
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.
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
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’.
How To Program For LCD I2C
Thanks to the LiquidCrystal_I2C library, the using LCD is a piece of cake.
- Include the library:
- Declare a LiquidCrystal_I2C object with I2C address, the number of columns, the number of rows:
- Initialize the LCD.
- Move cursor to the desired position (column_index, row_index)
- Print a message to the LCD.
There are many things more that we can do with LCD (see Do More with LCD part)
※ NOTE THAT:
The I2C address of LCD can vary according to the manufacturers. In the code, we used 0x27 that is specified by DIYables manufacturer
Arduino Code
Quick Steps
- Navigate to the Libraries icon on the left bar of the Arduino IDE.
- Search “LiquidCrystal I2C”, then find the LiquidCrystal_I2C library by Frank de Brabander
- Click Install button to install LiquidCrystal_I2C library.
- Copy the above code and open with Arduino IDE
- Click Upload button on Arduino IDE to upload code to Arduino
- See the result on LCD
- Try modifying text and position
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.
Do More with LCD
Custom Character
lcd.print() function supports only ASCII characters. If you want to display a special character or symbol (e.g. heart, angry bird), you need to use the below character generator.
LCD 16×2 can display 32 characters (2 rows and 16 columns). Each character is composed of 40 pixels (8 rows and 5 columns).
The character generator represents a character (40 pixels). You just need to do the following steps:
Result on LCD:
Multiple custom characters
We can create up to 8 custom characters (indexed 0 to 7). The below example creates and displays three characters.
Result on LCD:
Summary: how to use custom character on LCD
- Use the above character generator to create binary code for the custom character.
- Declare the binary code for the custom character (copy from above step)
- Create custom character and assign to an index value (from 0 to 7) in setup() function
- Print the custom character in LCD anytime, anywhere (in setup() or loop() function)
Other functions
Add the below functions into loop() function one by one. And add delay(5000) after each function
- Clear LCD screen
- Move the cursor to the upper-left of the LCD
- Move the cursor to the a position (column, row)
- Display the LCD cursor
- Hides the LCD cursor.
- Display the blinking LCD cursor
- Turns off the blinking LCD cursor.
- And more at LiquidCrystal Library Reference
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.
#includeLiquidCrystal_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");
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.
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.
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.
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.
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ế
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.
Step 3: Code
We must require to include two libraries ,in order to work the code attached .
Download the libraries from the attachment LCD library .
Basic functions we use in code
lcd.begin(16,2); //Defining 16 columns and 2 rows of lcd display
lcd.backlight(); //To Power ON /OFF the back light
lcd.setCursor(0,0); //Defining positon to write from first row,first column .
lcd.setCursor(0,1); //Defining positon to write from second row,first column .
lcd.print(” write here to print”); //You can write 16 Characters per line within quotations.
lcd.clear(); //Clean the screen
Code mẫu
#include
#includeLiquidCrystal_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é.
Wiring Diagram
This image is created using Fritzing. Click to enlarge image
LCD I2C | Arduino Uno, Nano | Arduino Mega |
Vin | 5V | 5V |
GND | GND | GND |
SDA | A4 | 20 |
SCL | A5 | 21 |
-
- Tổng tiền thanh toán:
|
#include void loop() |
|
#include void loop() |
|
#include void loop() |
|
#include void loop() |
Tổng quan LCD 16×2 và giao tiếp I2C LCD sử dụng Arduino
Introduction: How to Connect I2C Lcd Display to Arduino Uno
Hello Guys , In this Instructable you are going to see how to connect i2c lcd display to arduino and how to print on lcd display .
Before going to start this tutorial you must know a brief about i2c communication .
Each I2C bus consists of two signals: SCL and SDA. SCL is the clock signal, and SDA is the data signal. The clock signal is always generated by the current bus master; some slave devices may force the clock low at times to delay the master sending more data (or to require more time to prepare data before the master attempts to clock it out). This is called “clock stretching” and is described on the protocol page.
For more information visit Electronics Projects Hub
Now lets start this Instructable ..
Keywords searched by users: i2c lcd display arduino
Categories: Phát hiện thấy 27 I2C Lcd Display Arduino
See more here: kientrucannam.vn
See more: https://kientrucannam.vn/vn/