本帖最后由 AllBlue 于 2018-7-12 17:09 编辑
IIC 1602 液晶显示:http://www.yfrobot.com/thread-2263-1-1.html
原文:”https://www.arduinoslovakia.eu/blog/2017/10/i2c-tester?lang=en
I2C测试仪是将新的I2C设备连接到Arduino的任何人的有用工具。 它可以方便地检查I2C通信是否工作。 我们大多数人使用Arduino站点的I2C测试仪。 前几天我发现了一个类似的测试仪,但是输出更清晰。 它被称为i2cdetect,用于单机计算机,如Raspberry Pi或Orange Pi。 这是对Arduino环境的改编。
我根据我在互联网上发现的图像编写了程序。 我将输出模拟为串行端口,类似于原始程序。
[C++] 纯文本查看 复制代码
#include <Wire.h>
void setup() {
Wire.begin();
Serial.begin(115200);
Serial.println("I2C Scanner");
}
void loop() {
uint8_t error, address, line = 1;
int nDevices = 0;
Serial.println(" 0 1 2 3 4 5 6 7 8 9 A B C D E F");
Serial.print ("00: ");
// [url=https://learn.adafruit.com/i2c-addresses/the-list]https://learn.adafruit.com/i2c-addresses/the-list[/url]
for (address = 0x03; address < 0x78; 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) {
printHex(address);
nDevices++;
}
else if (error == 4)
Serial.print(" ER");
else
Serial.print(" --");
if ((address + 1) % 16 == 0) {
Serial.println();
Serial.print(line);
Serial.print("0:");
line++;
}
}
if (nDevices == 0)
Serial.println("\nNo I2C devices found\n");
else {
Serial.print("\nFound ");
Serial.print(nDevices);
Serial.println(" devices\n");
}
delay(5000); // wait 5 seconds for next scan
}
void printHex(uint8_t address) {
Serial.print(" ");
if (address < 16)
Serial.print("0");
Serial.print(address, HEX);
}
程序下载:
源代码位于GitHub服务器上:i2c_tester_raspberry
|