Arduino 和 LCD1602 I2C 接口实验
LCD1602液晶屏 带I2C接口
为什么使用I2C接口?因为省IO口啊,只需要4条线,可以看看之前发的实验,接线多复杂呀,对吧。
(传送门:Arduino携手LCD1602 向世界问好“hello World!”)
还有背光灯,和可调节对比度(就是背面蓝色那块可以旋转的调)
具体怎么实现解决问题,请往下看
引脚说明
GND ------ 地线
VCC ------ 电源(5V or 3.3v 电源不同显示效果有点差别)
SDA ------ I2C 数据线
SCL ------ I2C 时钟线
接线方法
LCD1602 i2c模块 Ardunio Uno
GND <------> GND接地线
VCC <------> 5V 接电源
SDA <------> A4
SCL <------> A5
程序实现
需要用到LCD1602 I2C的库,下载地址是 https://github.com/marcoschwartz/LiquidCrystal_I2C
把下载的库放到Arduino的库里(PS:不懂库是啥?请点击这里)
程序和库打包下载:https://u16460183.ctfile.com/fs/16460183-295783929
文件夹说明:
LiquidCrystal_I2C-master ——LCD1602 I2C库(库需要复制在arduino的库目录里)
LS_LCD1602 ——主程序
//LingShun lab
#include <Wire.h>
#include <LiquidCrystal_I2C.h> //引用I2C库
//设置LCD1602设备地址,这里的地址是0x3F,一般是0x20,或者0x27,具体看模块手册
LiquidCrystal_I2C lcd(0x3F,16,2);
void setup()
{
lcd.init(); // 初始化LCD
lcd.backlight(); //设置LCD背景等亮
}
void loop()
{
lcd.setCursor(0,0); //设置显示指针
lcd.print("LCD1602 iic Test"); //输出字符到LCD1602上
lcd.setCursor(0,1);
lcd.print(" by L.L.");
delay(1000);
}
实例效果
问题解疑
是一个模块还是两个模块?
这模块是通过LCD1602屏 和 LCD1602 I2C 模块 焊接结合的,可以直接买焊接好的,也可以分开买,不过就需要点动手能力。
无法正常显示?
刚上电的时候,老是显示一个个方块,如图
这情况一般是地址错误,我根据说明上写的地址0x20,0x27 都试了个遍还是无法正常显示
后来通过一网友的帖子把这问题给解决了,
贴出了一个寻找设备地址的代码 (来源:Arduino驱动IIC/I2C LCD1602模块显示(4根线解决连接))
#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
}
把模块按接线方法接好,上传这段代码后,打开端口监视器,就能找到在I2C上的设备地址,大家可以试试哦
推荐阅读
-
构建三层交换与VTP、STP及Eth-Trunk融合实验:基于双核架构实现高效、稳定、冗余网络" 实验目标: 利用双核心结构,整合三层交换技术、VTP (Virtual Trunking Protocol)、生成树协议 (STP) 和以太网通道 (Eth-Trunk),达成网络高速切换、高可用性、高可靠性和备份连接,适用于双核心拓扑场景。 实验步骤: 1. VLAN划分与IP地址规划: - VLAN10:192.168.10.0/24,默认网关192.168.10.1 - VLAN20:192.168.20.0/24,默认网关192.168.20.1 - VLAN30:192.168.30.0/24,默认网关192.168.30.1 - VLAN40:192.168.40.0/24,默认网关192.168.40.1 2. MSW1三层交换机配置: - 开启三层路由功能:`MSW1(config)#ip routing` - 配置Trunk接口:`MSW1(config-if-range)#switchport trunk encapsulation dot1q; switchport mode trunk` - 设置VTP域和模式:`MSW1(config)#vtp domain test; vtp mode server; vtp password cisco; vtp version 2` - 创建并命名VLAN:`MSW1(config)#vlan 10; MSW1(config-vlan)#name caiwu; ... (为其他VLAN重复操作)` - 分配VLAN IP地址:`MSW1(config-if)#int vlan 10; ip address 192.168.10.1 255.255.255.0; no shutdown; ... (为其他VLAN重复操作)` - 配置生成树优先级:`MSW1(config)#spanning-tree vlan 10,20 root primary; MSW1(config)#spanning-tree vlan 30,40 root secondary` - 链接Eth-Trunk通道:`MSW1(config-if-range)#channel-group 1 mode on; ... (为其他相关接口重复操作)` 3. MSW2三层交换机配置类似MSW1,只需更改VLAN名称和IP地址以及相关端口配置即可。 通过以上步骤,两台三层交换机之间可通过Eth-Trunk实现高速数据交互,并通过VTP统一管理VLAN资源,STP则确保了网络流量的负载均衡,从而构建了一个高效、稳定且具备冗余保护的网络环境。
-
实验 1 密码引擎加密应用程序接口的实施和测试
-
实验 1 - 密码引擎 - 加密应用程序接口的实施和测试
-
Arduino]通过基于 I2C 模块的 LiquidCrystal_I2C 库驱动 LCD1602 字符 LCD 模块显示文本:仅用两个引脚控制 LCD1602 液晶屏 - 步骤
-
Arduino 和 LCD1602 I2C 接口实验
-
使用 Arduino 和 LCD1602(I2C)的策略
-
OSPF 在不同接口网络类型(集线器和辐条与全网状)下的综合实验
-
手机和 Arduino 蓝牙串行通信实验和完整例程
-
建议 "进行 Arduino 和 LCD1602 I2C 接口实验。
-
AW9523/HTR3316(I2C 接口、16 个 LED 呼吸灯驱动器和 GPIO 控制器)