// Bench scanner for the XIAO ESP32-S3 sensor wiring in this walkthrough.
// Servo supply disconnected. Sensor power/logic must be verified for 3.3 V.
#include <Arduino.h>
#include <Wire.h>

void setup() {
  Serial.begin(115200);
  Wire.begin(5, 6);  // XIAO D4 = SDA, D5 = SCL
  Wire.setClock(100000);
}

void loop() {
  unsigned int found = 0;
  Serial.println("Scanning 7-bit I2C addresses...");
  for (uint8_t address = 1; address < 127; ++address) {
    Wire.beginTransmission(address);
    const uint8_t result = Wire.endTransmission();
    if (result == 0) {
      Serial.printf("ACK at 0x%02X\n", address);
      ++found;
    } else if (result != 2) {
      Serial.printf("Bus error %u at 0x%02X\n", result, address);
    }
  }
  Serial.printf("Found %u device(s). ACK does not verify sensor identity.\n", found);
  delay(3000);
}
