扫描程序代码如下
#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");
else
Serial.println("done");
delay(5000); // wait 5 seconds for next scan
}
![](https://imgsa.baidu.com/forum/w%3D580/sign=78958b744390f60304b09c4f0913b370/b056ccdde71190ef84d1959ac71b9d16fdfa6034.jpg)
0x3F就是设备地址了。
注意选择波特率。
然后点 文件->示例->LiquidCrystal_I2C>hello word
把第七行的0x2F改成0x3F,上传代码看一下屏幕有没有显示。如果没有显示找个小螺丝刀(改锥)调一下背面的电位器。
电位器最小时:
![](https://imgsa.baidu.com/forum/w%3D580/sign=cbbca82546c2d562f208d0e5d71090f3/0c719a1bb051f819f49c050fd3b44aed2f73e799.jpg)
![](https://imgsa.baidu.com/forum/w%3D580/sign=832da6bfd8c8a786be2a4a065708c9c7/3c94b9529822720eaac1e4bf72cb0a46f31fabcf.jpg)
电位器调到最大时。
![](https://imgsa.baidu.com/forum/w%3D580/sign=592bd8b1be4543a9f51bfac42e168a7b/61841fd12f2eb93871627cb7dc628535e4dd6fcf.jpg)
![](https://imgsa.baidu.com/forum/w%3D580/sign=837e9c24fadeb48ffb69a1d6c01e3aef/94e8aed6277f9e2f798c1b4d1630e924b999f399.jpg)
如果出现像我这样只显示每行的第一个字母,就把LiquidCrystal_I2C这个库删了,然后重新下载。