Display by I2C LCD1602
Introduction
As we all know, though LCD and some other displays greatly enrich the man-machine interaction, they share a common weakness. When they are connected to a controller, multiple IOs will be occupied of the controller which has no so many outer ports. Also it restricts other functions of the controller. Therefore, LCD1602 with an I2C bus is developed to solve the problem.
I2C bus is a type of serial bus invented by PHLIPS. It is a high performance serial bus which has bus ruling and high or low speed device synchronization function required by multiple-host system. The blue potentiometer on the I2C LCD1602 (see the figure below) is used to adjust the backlight for better display. I²C uses only two bidirectional open-drain lines, Serial Data Line (SDA) and Serial Clock Line (SCL), pulled up with resistors. Typical voltages used are +5 V or +3.3 V although systems with other voltages are permitted.
Components
- 1 * SunFounder Uno board
- 1 * I2C LCD1602 module
- 1 * USB cable
- Several jump wires
Experimental Principle
In this experiment, we will let I2C LCD1602 display “SunFounder" and “hello, world" by programming.
Experimental Procedures
Step 1: Build the circuit
The connection between the I2C LCD1602 and the SunFounder Uno board:
I2C LCD1602
|
SunFounder Uno
|
GND
|
GND
|
VCC
|
5V
|
SDA
|
A4
|
SCL
|
A5
|
Note: The wiring of I2C LCD1602 is the same through the following lessons.
Step 2: Program (Please refer to the example code in LEARN -> Get Tutorials on our website)
Step 3: Since in some code, the libraries needed are not included in Arduino, so you need to add them before compiling. Unzip the downloaded file. Copy the folders under the Library folder to the libraries folder in Arduino (if you cannot find the path in Arduino, open Arduino IDE, click File ->Preferences, and you can see the path in the Browse box, as shown in the following diagram). Compile the program.
Step 4: Upload the sketch to the SunFounder Uno board
You should now see your I2C LCD1602 display the flowing characters: "SunFounder" and "hello, world"
Code:
//* Crated by Nguyen Sum,
//* https://nguyensumiot.wordpress.com/
//Compatible with the Arduino IDE 1.0
//Library version:1.1
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display
void setup()
{
lcd.init(); // initialize the lcd
lcd.init();
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(3,0);
lcd.print("Hello, world!");
lcd.setCursor(2,1);
lcd.print("NGUYEN SUM");
lcd.setCursor(0,2);
lcd.print("Arduino LCM IIC 2004");
lcd.setCursor(2,3);
lcd.print("NGUYEN SUM");
}
void loop()
{
}
No comments:
Post a Comment