Arduino通过I2C(PCF8574T)驱动1602LCD
Arduino中使用I2C通信可直接调用Wire.h库, 这个库允许Arduino链接其他I2C设备, 链接线有两条, 分别是SDA(数据行)和SCI(时钟线). 各型号Arduino的I2C对应引脚:
Arduino Board:I2C / TWI pins
Arduino Uno/Ethernet:A4 (SDA), A5 (SCL)
Arduino Mega2560:20 (SDA), 21 (SCL)
Arduino Leonardo:2 (SDA), 3 (SCL)
Arduino Due:20 (SDA), 21 (SCL), SDA1, SCL1
一般购买到的是分开的两个组件, 需要按下图这样将PCF8574T焊接到1602LCD上

PCF8574T模块4pin(Gnd, Vcc, SDA i2c数据, SCL i2c时钟)和Arduino接口的对应关系: Gnd -> Gnd, Vcc -> Vcc, SDA -> A4, SDL -> A5
获取I2C地址
#include <Wire.h>
void setup() {
Serial.begin (); // Leonardo: wait for serial port to connect
while (!Serial) { }
Serial.println ();
Serial.println ("I2C scanner. Scanning ...");
byte count = ;
Wire.begin();
for (byte i = ; i < ; i++) {
Wire.beginTransmission (i);
if (Wire.endTransmission () == ) {
Serial.print ("Found address: ");
Serial.print (i, DEC); Serial.print (" (0x");
Serial.print (i, HEX); Serial.println (")");
count++; delay (); // maybe unneeded?
} // end of good response
} // end of for loop
Serial.println ("Done.");
Serial.print ("Found ");
Serial.print (count, DEC);
Serial.println (" device(s).");
} // end of setup
void loop() {}
运行时, 打开Serial Monitor, 将波特率设为115200, 看到的输出就是I2C地址
自带LiquidCrystal_I2C显示测试
在运行显示测试前检查是否已经安装了library: LiquidCrystal, LiquidCrystal_I2C
#include <Wire.h>
#include <LiquidCrystal_I2C.h> // I2C地址, 一般为0x3F, 0x20或0x27
LiquidCrystal_I2C lcd(0x27,,); void setup() {
lcd.init();
lcd.backlight(); // 打开背光
} void loop() {
lcd.setCursor(,);
lcd.print("LCD1602 iic Test");
lcd.setCursor(,);
lcd.print("0123456789ABCDEF");
delay();
}
如果屏幕亮但是无显示, 可以调节背后的电位器让字符显示到合适的对比度.
第三方New LiquidCrystal显示测试
到 https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads/ 下载最新的library并安装
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,,,,,,,); // 0x27 is the I2C bus address for an unmodified backpack void setup() { // activate LCD module
lcd.begin (,); // for 16 x 2 LCD module
lcd.setBacklightPin(,POSITIVE);
lcd.setBacklight(HIGH);
} void loop() {
lcd.home (); // set cursor to 0,0
lcd.print("HELLO WORLD....");
lcd.setCursor (,); // go to start of 2nd line
lcd.print(millis());
delay();
lcd.setBacklight(LOW); // Backlight off
delay();
lcd.setBacklight(HIGH); // Backlight on
}
供电和耗电测试
硬件是Arduino NANO + 扩展板 + PCF8574T + 1602LCD, 使用输入电压12V. 扩展板本身不带IC, 只有一个电源LED, 功耗可以忽略. 在使用自带的LiquidCrystal_I2C库跑上面的测试代码时, 测得的功耗仅为0.95W左右.
Arduino通过I2C(PCF8574T)驱动1602LCD的更多相关文章
- Arduino通过I2C(SSD1306)驱动0.96寸12864OLED
I2C驱动的128x64 OLED I2C (Inter-Integrated Circuit) 集成电路总线是I2CBus的简称, 是一种串行通信总线, 使用多主从架构. 飞利浦公司在1980年代为 ...
- Linux I2C设备驱动编写(三)-实例分析AM3359
TI-AM3359 I2C适配器实例分析 I2C Spec简述 特性: 兼容飞利浦I2C 2.1版本规格 支持标准模式(100K bits/s)和快速模式(400K bits/s) 多路接收.发送模式 ...
- Linux I2C设备驱动编写(二)
在(一)中简述了Linux I2C子系统的三个主要成员i2c_adapter.i2c_driver.i2c_client.三者的关系也在上一节进行了描述.应该已经算是对Linux I2C子系统有了初步 ...
- Linux I2C设备驱动编写(一)
在Linux驱动中I2C系统中主要包含以下几个成员: I2C adapter 即I2C适配器 I2C driver 某个I2C设备的设备驱动,可以以driver理解. I2C client 某个I2C ...
- 【转】Linux I2C设备驱动编写(三)-实例分析AM3359
原文网址:http://www.cnblogs.com/biglucky/p/4059586.html TI-AM3359 I2C适配器实例分析 I2C Spec简述 特性: 兼容飞利浦I2C 2.1 ...
- 【转】Linux I2C设备驱动编写(二)
原文网址:http://www.cnblogs.com/biglucky/p/4059582.html 在(一)中简述了Linux I2C子系统的三个主要成员i2c_adapter.i2c_drive ...
- 【转】Linux I2C设备驱动编写(一)
原文网址:http://www.cnblogs.com/biglucky/p/4059576.html 在Linux驱动中I2C系统中主要包含以下几个成员: I2C adapter 即I2C适配器 I ...
- C51单片机模拟I2C总线驱动程序设计
/********************************** I2C总线驱动 ******************************** 模块名:I2C总线驱动 型号:I2C 功能描述 ...
- Linux i2c子系统(一) _动手写一个i2c设备驱动
i2c总线是一种十分常见的板级总线,本文以linux3.14.0为参考, 讨论Linux中的i2c驱动模型并利用这个模型写一个mpu6050的驱动, 最后在应用层将mpu6050中的原始数据读取出来 ...
随机推荐
- Spring配置中的"classpath:"与"classpath*:"的区别研究
概念解释及使用场景: classpath是指WEB-INF文件夹下的classes目录. 通常我们一般使用这种写法实在web.xml中,比如spring加载bean的上下文时,如下: <!--系 ...
- go语言之进阶篇方法的重写
1.方法的重写 示例: //Person类型,实现了一个方法 func (tmp *Person) PrintInfo() { fmt.Printf("name=%s, sex=%c, ag ...
- JavaScript-undefined与null区别
JavaScript中的null在其他编程语言中也很常见,但是JavaScript在设计的过程中null自动转换为0,为了更好表示空,这个时候undefined出现了,null通过typeof结果是“ ...
- SQLSERVER 免费对比数据库结构和数据的工具支持:SQL Server 2012, SQL Server 2008 and SQL Server 2005
New xSQL Schema Compare - version 5 Compare the schemas of two SQL Server databases, review differen ...
- python中read() readline()以及readlines()用法
[转自:http://www.ibm.com/developerworks/cn/linux/sdk/python/python-5/index.html#N1004E] 我们谈到“文本处理”时,我们 ...
- Docker创建虚机和swarm
创建虚机: First, quickly create a virtual switch for your virtual machines (VMs) to share, so they will ...
- dubbo 提示No such extension Filter for filter/com.alibaba.dubbo.rpc.Filter
配置时 <dubbo:provider filter="DubboExceptionFilter"></dubbo:provider> DubboExcep ...
- 机器学习之深入理解SVM
在浏览本篇博客之前,最好先查看一下我写的还有一篇文章机器学习之初识SVM(点击可查阅哦).这样能够更好地为了结以下内容做铺垫! 支持向量机学习方法包括构建由简至繁的模型:线性可分支持向量机.线性支持向 ...
- jquery keycode
判断键盘按下的键 $(window).keydown(function(event) { switch (event.which) { case (13): //Enter //要执行的操作 brea ...
- 架构师速成7.3-devops为什么非常重要
evops是一个非常高大上的名字,事实上说的简单点就是开发和运维本身就是一个团队的,要干就一起把事情干好.谁出了问题,站点都不行. 作为一个架构师.必需要devops,并且要知道怎样推行devops. ...