Difference between revisions of "Matrix - I2C LCD1602"

From FriendlyELEC WiKi
Jump to: navigation, search
(Compile & Run Test Program)
Line 120: Line 120:
  
 
==Compile & Run Test Program==
 
==Compile & Run Test Program==
启动开发板并运行Debian系统,进入系统后克隆Matrix代码仓库:
+
Boot your ARM board with Debian and copy the matrix code:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
$ apt-get update && apt-get install git
 
$ apt-get update && apt-get install git
 
$ git clone https://github.com/friendlyarm/matrix.git
 
$ git clone https://github.com/friendlyarm/matrix.git
 
</syntaxhighlight>
 
</syntaxhighlight>
克隆完成后会得到一个名为matrix的目录。
+
If your cloning is done successfully a "matrix" directory will be generated.
  
编译并安装Matrix:
+
Compile and install Matrix:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
$ cd matrix
 
$ cd matrix
Line 133: Line 133:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
运行测试程序:
+
Run test program:
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
$ matrix-lcd1602
 
$ matrix-lcd1602
 
</syntaxhighlight>
 
</syntaxhighlight>
注意:此模块并不支持热插拔,启动系统前需要确保硬件连接正确。<br>
+
Note: this module is not plug and play therefore before running the module please make sure it is connected to an ARM board.<br>
运行效果如下:<br>
+
Here is what you should observe:<br>
 
[[File:matrix-lcd1602_result.png|frameless|600px|matrix-lcd1602_result]] <br>
 
[[File:matrix-lcd1602_result.png|frameless|600px|matrix-lcd1602_result]] <br>
 
LCD上会显示下列2行字符:<br>
 
LCD上会显示下列2行字符:<br>

Revision as of 14:18, 19 June 2016

查看中文

1 Introduction

I2C LCD1602
I2C LCD1602
  • The Matrix-I2C_LCD1602 is an LCD display module composed of an LCD1602 and a PCF8574 module.
  • The LCD1602 can display up to 16x2 characters. It has a parallel interface.
  • The PCF8574 provides GPIO expansion up to 8 bit for I2C. It communicates with a master via I2C and converts data from the master to parallel signals to the LCD1602 thus controls the LCD's display and back light.

2 Features

  • I2C interface, LCD display and backlight control
  • 2.54mm spacing pin
  • IIC Module PCB dimension(mm): 16 x 42
  • LCD1602 PCB dimension (mm): 36 x 80

IIC模块PCB LCD1602 PCB

  • Pin Description:
Pin Description
SDA I2C SDA
SCL I2C SCL
5V Supply Voltage 5V
GND Ground

3 Basic Device Operation

3.1 PCF8574

  • The PCF8574 has I2C parallel expansion. It has an 8bit (P0 - P7) I2C interface.
  • The PCF8574 communicates with a master via I2C. The PCF8574's chip model is PCF8574T whose address specification is as follows:

PCF8574

  • If A2 - A0 are all set to 1 the 7bit address will be 0x27(0100111). By default RW is 0 and it is in the write mode.
  • In the write mode after opening the i2c-0 device and setting up its address the master can write data to it.
  • If you need to read data from it you will need to set the module to the read mode (RW set to 1). Please refer to the PCF8574's datasheet for more details.

3.2 LCD1602

  • The connection diagram between the PCF8574 module and the LCD module is as follows:

1602

  • RS is instruction/data register selection. RW is read/write selection. E is enable signal(edge triggering). BL is back light control. D4-D7 are data bits.
  • The LCD module is controlled by four data bits through which we can send instructions to control its state. Because it has eight instruction/data bits (DB7 - DB0) when writing each instruction/data we need to write the most significant four bits DB7 - DB4 first and then the least significant four bits DB3 - DB0.
  • Note: the LCD module has 192 most commonly used characters stored in CGROM. When we write a common character e.g "A" it will directly display "A". In addition it can store up to eight user defined characters in RAM called CGRAM.

4 Applications

4.1 Connect to NanoPi M1

Refer to the following connection diagram to connect the module to the NanoPi M1:
Matrix-I2C_LCD1602_nanopi_m1

Connection Details

Matrix-I2C_LCD1602 NanoPi M1
SDA Pin3
SCL Pin5
5V Pin4
GND Pin6

4.2 Connect to NanoPi 2

Refer to the following connection diagram to connect the module to the NanoPi 2:
Matrix-I2C_LCD1602_nanopi_2

Connection Details:

Matrix-I2C_LCD1602 NanoPi 2
SDA Pin3
SCL Pin5
5V Pin4
GND Pin6

4.3 Connect to NanoPi M2 / NanoPi 2 Fire

Refer to the following connection diagram to connect the module to the NanoPi M2/ NanoPi 2 Fire.
Matrix-I2C_LCD1602_nanopi_m2

Connection Details:

Matrix-I2C_LCD1602 NanoPi M2
SDA Pin3
SCL Pin5
5V Pin4
GND Pin6

4.4 Connect to NanoPC-T2

Refer to the following connection diagram to connect the module to the NanoPC-T2:
Matrix-I2C_LCD1602_NanoPC-T2

Connection Details:

Matrix-I2C_LCD1602 NanoPC-T2
SDA Pin6
SCL Pin5
5V Pin29
GND Pin30

5 Compile & Run Test Program

Boot your ARM board with Debian and copy the matrix code:

$ apt-get update && apt-get install git
$ git clone https://github.com/friendlyarm/matrix.git

If your cloning is done successfully a "matrix" directory will be generated.

Compile and install Matrix:

$ cd matrix
$ make && make install

Run test program:

$ matrix-lcd1602

Note: this module is not plug and play therefore before running the module please make sure it is connected to an ARM board.
Here is what you should observe:
matrix-lcd1602_result
LCD上会显示下列2行字符:
" B&G Char LCD"
"--by FriendlyARM"
如果LCD上没有显示,则需要旋转模块上的可调电阻以调节字体颜色的深浅。

6 代码说明

所有的开发板都共用一套Matrix代码,本模块的测试示例代码为matrix-i2c_lcd1602,内容如下:

int main(int argc, char ** argv)
{
    int devFD, board;
    int i2cDev = 0;
 
    if ((board = boardInit()) < 0) {
        printf("Fail to init board\n");
        return -1;
    }
 
    if (argc == 2)
        i2cDev = atoi(argv[1]);
    if ((devFD = LCD1602Init(i2cDev)) == -1) {
        printf("Fail to init LCD1602\n");
        return -1;
    }
    if (LCD1602Clear(devFD) == -1) {
        printf("Fail to Clear\n");
    }
    printf("clearing LCD1602\n");
    sleep(1);
    if (LCD1602DispLines(devFD, "  B&G Char LCD", "--by FriendlyARM") == -1) {
        printf("Fail to Display String\n");
    }
    printf("displaying LCD1602\n");
    LCD1602DeInit(devFD);
    return 0;
}

API说明参考维基:Matrix API reference manual

7 与Arduino连接使用

7.1 准备工作

确保你的Arduino板能正常下载运行程序,参考:https://www.arduino.cc/en/Guide/HomePage
这里我们使用的是Arduino uno板。

7.2 硬件连接

参考下图连接模块Matrix-I2C_LCD1602和Arduino Uno
matrix-i2c_lcd1602_arduino

7.3 编译运行测试程序

由于arduino开发板并不运行Linux系统,所以matrix for arduino的代码由独立的仓库进行管理:git://github.com/friendlyarm/matrix-arduino.git
克隆matrix-arduino代码仓库

$ git clone git://github.com/friendlyarm/matrix-arduino.git

克隆完成后会得到一个matrix-arduino目录,里面存放着所有Matrix 配件用于支持arduino的代码。

拷贝matrix-i2c_lcd1602目录到Arduino IDE的libraries目录下

$ cd matrix-arduino
$ cp matrix-i2c_lcd1602 Arduino_IDE/libraies -r

启动Arduino IDE
点击File->Examples->matrix-i2c_lcd1602->displaychar,打开测试程序。
点击upload,运行测试程序。

7.4 代码展示

#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
 
// set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27,16,2);  
 
void setup()
{
  lcd.init();                        
  lcd.backlight();
  lcd.setCursor(2, 0);
  lcd.print("B&G Char LCD"); 
  lcd.setCursor(0, 1);
  lcd.println("--by FriendlyARM");
}
 
void loop()
{
}


8 Resources

LCD1602.pdf
pcf8574.pdf


9 Update Log

9.1 Feb-23-2016

  • Added the description for "NanoPi 2 branch" in Section 4
  • Added Section 5: Connect to NanoPi 2