arduinoredexpress的收藏玩转Arduino

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

2016-06-20  本文已影响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 -> 右边引脚

加载库文件

示例代码

// 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居然可以了。。。有大神知道是什么原因吗。。。
上一篇 下一篇

猜你喜欢

热点阅读