1602的接线
首先,把转接板焊接到LCD显示屏上(方向如上图)
PCF8574T | Arduino | |
---|---|---|
GND | -> | GND |
VCC | -> | 5V |
SDA | -> | A4 |
SCL | -> | A5 |
这个sda scl口是固定的,所以在写程序时候都不用写管脚声明,只需要声明管脚i2c地址即可。
添加arduino的1602液晶显示屏库
我购买的1602 i2c模块是pcf8574,由于这个不是专门的i2c转1602芯片,而是i2c接口的I/O扩展芯片,所以,在arduino库中搜索的时候,有些标注了使用了pcf8574,有些却没有。
实验时,发现红箭头的是最常用的。许多大神都是有这个库,而liquidcrystal_pcf8574也可以用,例程中还有自定义字符,但是使用上相对要复杂点。
扫描I2C地址及地址的缺点和修改方法
通过软件获得设备i2c地址
在参考文献中,我发现一个很好的i2c设备地址扫描程序。如下:
将以下代码拷贝到Arduino IDE,并执行。然后选择工具
->串口监视器
,把右下角的波特率改为115200
,即可在串口监视器中读出I2C地址
// I2C Scanner
#include <Wire.h>
void setup() {
Serial.begin (115200); // Leonardo: wait for serial port to connect
while (!Serial) { }
Serial.println ();
Serial.println ("I2C scanner. Scanning ...");
byte count = 0;
Wire.begin();
for (byte i = 8; i < 120; i++) {
Wire.beginTransmission (i);
if (Wire.endTransmission () == 0) {
Serial.print ("Found address: ");
Serial.print (i, DEC);
Serial.print (" (0x");
Serial.print (i, HEX);
Serial.println (")");
count++;
delay (1); // 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() {}
通过硬件焊点改变i2c地址
如下图
串口数据显示程序
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2); //这里改成自己的i2c设备地址
void setup(){
lcd.init();
lcd.backlight();
Serial.begin(9600);
}
void loop(){
if (Serial.available()) {
delay(100);
lcd.clear();
while (Serial.available() > 0) {
lcd.write(Serial.read());
}
}
}
程序写好后,就可以用串口调试器调试,设置好波特率发送文本即可在1602上显示。
Troubleshooting
- 没有根据实际情况更改液晶屏的地址。
- LCD的尺寸与所需尺寸不同(16x2)。
- pcf8574模块蓝色选钮控制的字符灰度,不正确的灰度会导致液晶屏无显示,但是可以控制亮度(我遇到的1602不显示问题)。
- 在非I2c显示器上使用LCD_I2c库,反之亦然。
- LCD未正确连接。
- Arduino连接不正确。
- 系统没有安装驱动程序(CH340[用于中国的Arduino])。
- 你真倒霉。
参考资料:
https://create.arduino.cc/projecthub/thesahilsaluja/cpu-and-ram-usage-monitor-windows-linux-921282?ref=similar&ref_id=32069&offset=0
https://create.arduino.cc/projecthub/zakrzu/arduino-pc-monitor-66c07a
https://www.arduino.cn/thread-49987-1-1.html
https://www.jianshu.com/p/eee98fb5e68f