noiasca:
this is my adoption of one of the existing i2c scanners. it tries to guess the IC by the address.
// Version 1
// This program (or code that looks like it)
// can be found in many places.
// For example on the Arduino.cc forum.
// The original author is not know.
// Version 2, Juni 2012, Using Arduino 1.0.1
// Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26 2013
// V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
// by Arduino.cc user Krodal.
// Changes by louarnold removed.
// Scanning addresses changed from 0...127 to 1...119,
// according to the i2c scanner by Nick Gammon
// Gammon Forum : Electronics : Microprocessors : I2C - Two-Wire Peripheral Interface - for Arduino
// Version 5, March 28, 2013
// As version 4, but address scans now to 127.
// A sensor seems to use address 120.
// Version 6, 2019-09-09 noiasca
// Identification of some well known devices
// Version 7, 2019-09-29 noiasca
// added some devices
// Version 2020-03-15 noiasca
// added SHT21/SI7021
#include <Wire.h>
void setup()
{
Serial.begin(115200);
Serial.println("\nI2C Scanner");
#ifdef ARDUINO_ESP8266_NODEMCU
Serial.println(F("Init I2C on ESP8266_NODEMCU"));
Wire.begin(SDA,SCL); //NODEMCU/ESP Default ist D2 = 4 = SDA ; D1 = 5 = SCL
//Wire.begin(D5, D6); // my Robot
#else
Wire.begin();
#endif
// some microprocessors support higher speeds
//Wire.setClock(10000); // low speed mode (default)
Wire.setClock(100000); // standard mode
//Wire.setClock(400000); // fastmode
//Wire.setClock(1000000); // fast mode plus // NOK on UNO
//Wire.setClock(3400000); // high speed mode
}
void loop()
{
uint8_t error, address;
uint8_t 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(F("I2C device found at address 0x"));
if (address < 16)
Serial.print(F("0"));
Serial.print(address, HEX);
if (address <= 0x07) Serial.print(F(" - reserved"));
if (address >= 0x20 && address <= 0x27) Serial.print(F(" MCP23008 MCP23017 PCF8574A"));
if (address == 0x21 || address == 0x22) Serial.print(F(" SAA4700"));
if (address >= 0x30 && address <= 0x3F) Serial.print(F(" PCF8574"));
if (address >= 0x3c && address <= 0x3d) Serial.print(F(" PCF8578"));
if (address == 0x40) Serial.print(F(" SHT21/SI7021"));
if (address >= 0x50 && address <= 0x57) Serial.print(F(" AT24C32")); // on some DS3231 breakout boards there is this IC at 0x57
if (address == 0x68) Serial.print(F(" DS3231"));
if (address >= 0x68 && address <= 0x6b) Serial.print(F(" PCF8573"));
if (address >= 0x70 && address <= 0x77) Serial.print(F(" HT16K33 TCA9548"));
if (address >= 0x76 && address <= 0x77) Serial.print(F(" BME280 BME680 BMP280"));
Serial.println();
nDevices++;
}
else if (error == 4)
{
Serial.print(F("Unknow error at address 0x"));
if (address < 16)
Serial.print(F("0"));
Serial.println(address, HEX);
}
}
if (nDevices == 0)
Serial.println(F("No I2C devices found\n"));
else
Serial.println(F("done\n"));
delay(5000); // wait 5 seconds for next scan
}
some IC support some kind of identification in individual registers. So it could be expanded to do a better identification.you are aware of, that I2C is not made for "hot plugging"?
This ended up being exactly what I needed. My struggles were coming from sensors that werent plugged in that were still be addressed. I tried calling them by 'HEX -- xx' which gave me that issue.
Thanks again!