Files
IoTManager/src/utils/I2CUtils.cpp
2024-09-21 12:09:11 +03:00

34 lines
824 B
C++

#ifndef LIBRETINY
#include <Wire.h>
#include "utils/SerialPrint.h"
void scanI2C() {
byte error, address;
int nDevices;
String message = "";
nDevices = 0;
for(address = 8; address < 127; address++ ) {
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0){
message += "I2C device found at address 0x";
message += uint64ToStringIoTM(address, 16);
message += " !";
nDevices++;
}
else if (error==4) {
message += "Unknow error at address 0x";
message += uint64ToStringIoTM(address, 16);
}
}
if (nDevices == 0)
message += "No I2C devices found\n";
else
message += "done\n";
SerialPrint("i", "I2C Scaner", message);
}
#endif