美文网首页arduinoredexpress的收藏玩转Arduino
【Arduino基础教程】LCD 1602显示屏

【Arduino基础教程】LCD 1602显示屏

作者: 繁著 | 来源:发表于2016-06-20 16:19 被阅读25411次
LCD直接与Arduino相连的接线图
LCD Arduino
RS -> 12
E -> 11
D4 -> 5
D5 -> 4
D6 -> 3
D7 -> 2
VCC -> 5V
R/W -> GND
GND -> GND
LCD 旋转变阻器
VCC -> 左边引脚
Vo -> 中间引脚
R/W -> 右边引脚
GND -> 右边引脚

加载库文件

  • 在Arduino IDE 1.6.2 或者以上版本中, 项目->加载库->管理库中搜索LiquidCrystal,然后安装即可。

示例代码

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("hello, world!");
}

void loop() {
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  lcd.print(millis()/1000);
}

参考文献

https://www.arduino.cc/en/Reference/LiquidCrystal


2.通过PCF8574T转接板与Arduino相连

通过此种方式,可以大大节省Arduino的IO口,前提是你还得购买一块PCF8574T转接板。


串口监视器中显示的地址:0x3F

加载库文件

这里下载最新的New LiquidCrystal,手动添加到你的 Arduino IDE中。(ps:记得修改你的I2C地址,把LiquidCrystal_I2C lcd(0x3F,2,1,0,4,5,6,7);0x3F改为你的真实地址)

示例代码

/* Demonstration sketch for PCF8574T I2C LCD Backpack Uses library from https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads GNU General Public License, version 3 (GPL-3.0) */ 
#include <Wire.h> 
#include <LCD.h> 
#include <LiquidCrystal_I2C.h> 
LiquidCrystal_I2C lcd(0x3F,2,1,0,4,5,6,7); // 0x27 is the I2C bus address for an unmodified backpack 
void setup() { // activate LCD module 
  lcd.begin (16,2); // for 16 x 2 LCD module 
  lcd.setBacklightPin(3,POSITIVE); 
  lcd.setBacklight(HIGH); 
} 
void loop() { 
  lcd.home (); // set cursor to 0,0 
  lcd.print(" tronixlabs.com"); 
  lcd.setCursor (0,1); // go to start of 2nd line 
  lcd.print(millis()); 
  delay(1000); 
  lcd.setBacklight(LOW); // Backlight off delay(250);        
  lcd.setBacklight(HIGH); // Backlight on delay(1000); 
}

参考文献

http://www.instructables.com/id/Using-PCF8574-backpacks-with-LCD-modules-and-Ardui/?ALLSTEPS

经验教训

  1. 之前没有查看I2C的地址,傻傻的复制别人的代码过来直接用,结果人家是0x27,试了好久都不行,后来才看到一篇文章说要先确定I2C的地址,才得以解决。
  2. 有个困惑,之前确定I2C的地址后,用NewliquidCrystal_1.3.4.zip这个库死活还是不行,然后我把这个库删掉,然后换了个库还是不行,最后又换回NewliquidCrystal_1.3.4.zip居然可以了。。。有大神知道是什么原因吗。。。

相关文章

网友评论

  • haige:10KΩ旋转变阻器,和 LCD1602液晶屏转接板(PCF8574AT) 在哪买的? 有链接吗?发一下,谢谢
    繁著:@machh 复制这条信息,打开👉手机淘宝👈即可看到【WH118-1A 2W 10K调速滑动可调变阻器 单圈合成碳膜电位器单联】¥crMVMeLfbu¥http://c.b1wt.com/h.etiZMR?cv=crMVMeLfbu&sm=e4e62e
    繁著:@machh 复制这条信息,打开👉手机淘宝👈即可看到【Risym LCD1602液晶屏转接板 LCD2004转接版 IIC/I2C/接口】¥dv3BMeNUzr¥http://c.b1wt.com/h.etS3OA?cv=dv3BMeNUzr&sm=15a15b
  • JK纯白:您好,还有一个LCD.h的库方便给一下吗?
    繁著:https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads/
    上面有提到,这个链接就可以下载,里面就有包括lcd.h的库
  • Luat物联网通信模块:可以关注下Luat开源项目,基于Air200 GPRS模块(价格才12块多),基于Lua开发应用软件,超级容易上手。 而且开发点阵LCD 的UI 非常方便,有丰富的底层库,支持中文很方便。

本文标题:【Arduino基础教程】LCD 1602显示屏

本文链接:https://www.haomeiwen.com/subject/ypewdttx.html