库文件下载
抗揍云下载:https://wwa.lanzouo.com/inufWx44r9c
LCD1602A原理图
引脚说明
GND——GND
VCC——5V/3.3v
SDA—— I2C
SCL——I2C
接线说明
Arduino Mega
Arduino UNO
代码部分
Arduino 代码部分在使用了PCF8574驱动板简练方便了不少
#include <Wire.h> //调用wire库
#include <LiquidCrystal_I2C.h> //调用LiquidCrystal_I2C库
LiquidCrystal_I2C lcd(0x27,16,2); //设置LCD1_602A设备地址
void setup()
{
lcd.init(); // 初始化LCD_1602A
lcd.backlight(); //设置LCD背景等亮
}
void loop()
{
lcd.setCursor(0,0); //第一行显示
lcd.print("Hello&Wellcome"); //输出字符
lcd.setCursor(0,1); //第二行显示
lcd.print("LiquidCrystal");
常见bug汇总及解决方法
为什么屏幕一直常亮没有字符显示?
答:对比度过高/低,LCD_1602A这块屏幕是需要调节对比度的,拿个小螺丝刀拧拧,调到能看见一排方块
答:设备地址不匹配,LCD1602设备地址有0x3F,0x20,0x27(常见为0x27)
LCD_1602A地址查询方法
在正确与arduino连接下,运行如下代码
#include <Wire.h>
void setup(){
Wire.begin();
Serial.begin(9600);
Serial.println("\nI2C Scanner");
}
void loop(){
byte error, address;
int nDevices;
Serial.println("Scanning...");
nDevices = 0;
for (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);
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("Unknow 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
}
效果图:
为什么只显示一行或两行首字符?
答:修改库文件
任意打开一个LiquidCrystal_I2C1602的示例文件,然后在新开的窗口打开顶部导航栏的 项目-显示当前项目文件夹,然后向前返回两级菜单或者打开C:\Users\rain\Documents\Arduino\libraries\LiquidCrystal_I2C1602V1.1
然后打开LiquidCrystal_I2C.cpp修改这里:
将return 0;改为return 1;
eg:
inline size_t LiquidCrystal_I2C::write(uint8_t value) {
send(value, Rs);
return 1;
}
Comments NOTHING