如何用Arduino查询LCD1602液晶屏 I2C的初始地址是0x3f还是0x27?

更详细的图片带视频在这里:

https://www.haibucuo.com/5326/

经过本人测试有效,特地写出教程供广大爱好者阅读。

第一步:.连线arduino和LCD1602显示器

LCD1602—–arduino uno

GND ———— GND

VCC ———— 5V

SDA ———— A4

SCL ———— A5

第二部,上传程序

#include <Wire.h>

void setup()

{

Wire.begin();

Serial.begin(9600);

Serial.println(” I2C 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

}

第三部,打开串口监视

如何用Arduino查询LCD1602液晶屏 I2C的初始地址是0x3f还是0x27?

通过上面我们已经可以看到扫描的结果了。

最后更新:2022.02.19

上一篇:

下一篇:

相关新闻

发表回复

公众号
公众号
创客圈 配件商城
分享本页
返回顶部