Arduino驱动IIC/I2C LCD1602模块显示

 

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)

 

连接好电路后,将下面的例程下载到控制板中,就可以实现显示了:

  1. #include <Wire.h> 
  2. #include <LiquidCrystal_I2C.h>
  3.  
  4. LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
  5.  
  6. void setup()
  7. {
  8. lcd.init(); // initialize the lcd 
  9. lcd.backlight(); //Open the backlight
  10. lcd.print("Welcome to "); // Print a message to the LCD.
  11. lcd.setCursor(0,1); //newline
  12. lcd.print("www.yfrobot.com");// Print a message to the LCD
  13. }
  14. void loop()
  15. {
  16. }

复制代码

程序中使用到:

      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

}

 

  • 4
    点赞
  • 37
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是Arduino控制DHT11模块LCD1602IIC显示的示例程序: DHT11模块: ```c++ #include <dht.h> dht DHT; #define DHT11_PIN 2 void setup() { Serial.begin(9600); } void loop() { int chk = DHT.read11(DHT11_PIN); Serial.print("Temperature: "); Serial.print(DHT.temperature); Serial.print("C, Humidity: "); Serial.print(DHT.humidity); Serial.println("%"); delay(2000); } ``` LCD1602IIC显示: ```c++ #include <Wire.h> #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x27, 16, 2); void setup() { lcd.init(); lcd.backlight(); lcd.setCursor(0, 0); lcd.print("Hello, World!"); } void loop() { // do nothing } ``` 结合两个模块的示例程序: ```c++ #include <Wire.h> #include <LiquidCrystal_I2C.h> #include <dht.h> dht DHT; #define DHT11_PIN 2 LiquidCrystal_I2C lcd(0x27, 16, 2); void setup() { Serial.begin(9600); lcd.init(); lcd.backlight(); } void loop() { int chk = DHT.read11(DHT11_PIN); Serial.print("Temperature: "); Serial.print(DHT.temperature); Serial.print("C, Humidity: "); Serial.print(DHT.humidity); Serial.println("%"); lcd.setCursor(0, 0); lcd.print("Temp: "); lcd.print(DHT.temperature); lcd.print("C"); lcd.setCursor(0, 1); lcd.print("Humidity: "); lcd.print(DHT.humidity); lcd.print("%"); delay(2000); } ``` 这个程序可以读取DHT11模块的温度和湿度,并在LCD1602IIC显示。需要注意的是,LCD1602IIC需要使用Wire库进行通信,因此需要在程序开头添加`#include <Wire.h>`,并在setup函数中初始化I2C通信。在loop函数中,先读取DHT11模块的数据并打印到串口上,然后将温度和湿度信息分别显示在LCD的第一行和第二行上。最后延时2秒钟,再次读取并更新数据。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值