FAQ

How to quickly confirm the new I2C address after changing toggles or soldering resistors

userHead Tonny12138 2024-07-11 06:04:05 56 Views0 Replies
How to quickly confirm the new I2C address after changing toggles or soldering resistors
2025-07-24 15:01:03

You can connect the sensor to an Arduino or ESP32 via an address converter and upload the I2C Scanner code below. The serial monitor will output the new I2C address.

 

/**

@file i2cScanner.ino

@brief The i2c_scanner see if a device did acknowledge to the address.

@copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)

@license The MIT License (MIT)

@author [thdyyl]([email protected])

@version V0.1

@date 2024-08-05

*/

#include <Wire.h>

 

void setup(){

Wire.begin();

Serial.begin(115200);

Serial.println();

Serial.println("I2C Scanner");

}

void loop(){

uint8_t error, address;

int numDevices;

Serial.println("Scanning...");

numDevices = 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(" !");

numDevices++;

}else if (error == 4){

Serial.print("Unknow error at address 0x");

if (address < 16)

Serial.print("0");

Serial.println(address, HEX);

}

}

if (numDevices == 0)

Serial.println("No I2C devices found\n");

else

Serial.println("done\n");

delay(2000); // wait 2 seconds for next scan

}

userHeadPic Tonny12138