diff options
| author | adiee5 <58359866+adiee5@users.noreply.github.com> | 2026-03-17 00:36:27 +0100 |
|---|---|---|
| committer | adiee5 <58359866+adiee5@users.noreply.github.com> | 2026-03-17 00:36:27 +0100 |
| commit | f9032ca0d68f0b2ba7c007e90444c7e88d32e194 (patch) | |
| tree | 23eea612019ed8c7a263e257f0eb3f1d6be51a58 /src/i2ccheck.cpp.q | |
| parent | 71bdb9a31ceaf97c6bb2c4bc0d2834299bea874c (diff) | |
True init
Diffstat (limited to 'src/i2ccheck.cpp.q')
| -rw-r--r-- | src/i2ccheck.cpp.q | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/i2ccheck.cpp.q b/src/i2ccheck.cpp.q new file mode 100644 index 0000000..f849ba1 --- /dev/null +++ b/src/i2ccheck.cpp.q @@ -0,0 +1,51 @@ +#include <Wire.h> +#include <Arduino.h> + +void setup() { + Wire.begin(); + + Serial.begin(9600); + while (!Serial); // Leonardo: wait for serial monitor + Serial.println("\nI2C Scanner"); +} + +void loop() { + byte error, address; + int nDevices; + + Serial.println("Scanning..."); + + nDevices = 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(" !"); + + nDevices++; + } + else if (error == 4) + { + Serial.print("Unknown error at address 0x"); + if (address < 16) + Serial.print("0"); + Serial.println(address, HEX); + } + } + if (nDevices == 0) + Serial.println("No I2C devices found\n"); + else + Serial.println("done\n"); + + delay(5000); // wait 5 seconds for next scan +} |
