Moved the i2c detection into git
This commit is contained in:
@@ -1,2 +1,7 @@
|
|||||||
# esp32-detect-i2c
|
# 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```
|
||||||
33
platformio.ini
Normal file
33
platformio.ini
Normal file
@@ -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
|
||||||
|
|
||||||
37
src/detect_icc.cpp
Normal file
37
src/detect_icc.cpp
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
#include <Wire.h>
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
#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
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user