From dfab98c048c897d849a132c20d8501d11df64273 Mon Sep 17 00:00:00 2001 From: Hannes Date: Mon, 20 Oct 2025 19:51:00 +0200 Subject: [PATCH] Moved the i2c detection into git --- README.md | 5 +++++ platformio.ini | 33 +++++++++++++++++++++++++++++++++ src/detect_icc.cpp | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 platformio.ini create mode 100644 src/detect_icc.cpp diff --git a/README.md b/README.md index cbcdf16..70354e1 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,7 @@ # esp32-detect-i2c +## IDE +Should be able to be put onto an esp32 with for example PlatformIO and ArduinoIDE + +### PlattformIO +A PlatformIO ```platformio.ini``` is included with the uncommented part being for an ```ESP-32D``` and the commented part for ```ESP32-C3``` \ No newline at end of file diff --git a/platformio.ini b/platformio.ini new file mode 100644 index 0000000..3b8c966 --- /dev/null +++ b/platformio.ini @@ -0,0 +1,33 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + +; [env:esp32-c3-devkitm-1] +; platform = espressif32 +; board = esp32-c3-devkitm-1 +; framework = arduino + +; monitor_speed = 115200 + +; build_flags = +; -DARDUINO_USB_CDC_ON_BOOT=1 +; -DARDUINO_USB_MODE=1 + +[env:esp32dev] +platform = espressif32 +board = esp32dev +framework = arduino +upload_speed = 115200 +monitor_speed = 115200 + +; Explicit flash settings for stability +board_build.flash_mode = dio +board_build.flash_size = 4MB +board_build.flash_freq = 40m + diff --git a/src/detect_icc.cpp b/src/detect_icc.cpp new file mode 100644 index 0000000..98bfcd5 --- /dev/null +++ b/src/detect_icc.cpp @@ -0,0 +1,37 @@ +#include +#include + +#define SDA_PIN 7 // Blue +#define SCL_PIN 8 // Green + +void setup() { + Serial.begin(115200); + while (!Serial) { delay(100); } + + Serial.println("I2C Scanner starting..."); + Wire.begin(SDA_PIN, SCL_PIN); // SDA=7, SCL=8 +} + +void loop() { + byte error, address; + int nDevices = 0; + + Serial.println("Scanning I2C bus..."); + + for(address = 1; address < 127; address++ ) { + Wire.beginTransmission(address); + error = Wire.endTransmission(); + + if (error == 0) { + Serial.print("I2C device found at 0x"); + if (address<16) Serial.print("0"); + Serial.println(address, HEX); + nDevices++; + } + } + + if (nDevices == 0) Serial.println("No I2C devices found\n"); + else Serial.println("Scan complete\n"); + + delay(5000); // repeat every 5 seconds +} \ No newline at end of file