/* Autor : Siva Prakasam // Date : 30/12/24 // Title : I2C scan */ #include #include #include #include #include #include #include #define I2C_BUS "/dev/i2c-1" // Modify according to your bus int main() { int file; int addr; char *bus = I2C_BUS; // Open the I2C bus if ((file = open(bus, O_RDWR)) < 0) { perror("Failed to open I2C bus"); exit(1); } printf("Scanning I2C bus %s...\n", bus); // Loop through all possible I2C addresses (0x03 to 0x77) for (addr = 0x03; addr < 0x78; addr++) { // Try to communicate with the device at the address if (ioctl(file, I2C_SLAVE, addr) < 0) { // Device not found continue; } // Device found, print the address printf("I2C device found at address 0x%02x\n", addr); } // Close the I2C bus close(file); return 0; }