Arduino控制器的控制端口数量有限,连接一个LCD就好像没接口了似得!
下面我们介绍一个使用IIC接口连接的LCD1602模块。这一模块只用4根线就可以解决与arduino连接问题,非常方便初学者使用,再也不用为繁琐的连线头疼了~~
IIC 1602背面图片:
模块基本参数:
工作电压为+5V
有背光且可调节对比度
I2C接口通讯地址:0x27
下面我们介绍下IIC:
IIC 即Inter-Integrated Circuit(集成电路总线)又叫I2C,一种总线结构,这种总线类型是由菲利浦半导体公司在八十年代初设计出来的,主要是用来连接整体电路(ICS) ,IIC是一种多向控制总线,也就是说多个芯片可以连接到同一总线结构下,同时每个芯片都可以作为实施数据传输的控制源。
I2C串行总线一般有两根信号线,一根是双向的数据线SDA,另一根是时钟线SCL。所有接到I2C总线设备上的串行数据SDA都接到总线的SDA上,各设备的时钟线SCL接到总线的SCL上。模块使用芯片(PCF8574)中文资料:
PCF8574中文手册.pdf (245.09 KB, 下载次数: 1322)
IIC LCD1602库文件:
LiquidCrystal_I2C.zip (7.61 KB, 下载次数: 3137)
--- 已更新 1.6.6 版本IDE 可用 更改方法:点击查看
IIC LCD1602模块有4个引脚,连接非常简单,分别连接arduino(在这里要特别提示下各位用户,首先将库文件添加到library中,不然程序无法工作;虽然连线只有4根,但是还是要注意下连线,正负极不可反接):
GND ———— GND
VCC ———— 5V
SDA ———— A4(AREF旁的SDA)
SCL ———— A5 (AREF旁的SCL)
连接好电路后,将下面的例程下载到控制板中,就可以实现显示了:
#include <Wire.h> #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display void setup(){lcd.init(); // initialize the lcd lcd.backlight(); //Open the backlightlcd.print("Welcome to "); // Print a message to the LCD.lcd.setCursor(0,1); //newlinelcd.print("www.yfrobot.com");// Print a message to the LCD}void loop(){}复制代码
程序中使用到:
lcd.init(); 初始化LCD lcd.backlight(); 打开背景灯
lcd.print("Welcome to "); 显示“Welcome to”文本
还要说明的是 :之前介绍的LCD 1602的语法,在这个库中同样适用 其他语法介绍请见1602实验
显示图片:
模块原理图: I2C LCD Module SCH.pdf (39.67 KB, 下载次数: 235) -----------------------------------------------------------------分割君--------------------------------------------------------------网友:hwn444 贡献的IIC地址查询,给用到的朋友整理到这里。
[C] 纯文本查看 复制代码
?
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#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
}
