|
一般情况下,默认用库就可以了
但也有不显示的情况,例如只有一行显示黑框~~
果断就是i2C地址错了,不是默认的0x27
于是乎,找到正确的地址就是关键了
来自百度大神的提供:
http://tieba.baidu.com/p/2465553311
- #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
- }
复制代码
地址扫描出来后,修改正确的地址即可,比如我买的1602转i2c
4个,有3个是0x27,余下一个是 0x3F(标准程序必然运行不起来),尼玛,坑爹啊
PS:转接板是个好东西,4元不到,加上普通的1602,就成了i2C的了~~~
PS2:这个转接板看测试程序,目测还带字库,艾玛,这是赚了的节奏?
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|