diff options
Diffstat (limited to 'test_fw/include/i2c_scan.h')
| -rw-r--r-- | test_fw/include/i2c_scan.h | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/test_fw/include/i2c_scan.h b/test_fw/include/i2c_scan.h new file mode 100644 index 0000000..1fc81c1 --- /dev/null +++ b/test_fw/include/i2c_scan.h @@ -0,0 +1,37 @@ +#pragma once + +#include <Arduino.h> +#include <Wire.h> + +namespace ocularium { + inline void scan(TwoWire& wire, bool post_delay = true) + { + for(auto address = 1; address < 127; address++) + { + wire.beginTransmission(address); + const uint8_t 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(); + } + else if (error==4) + { + Serial.print("Unknown error at address 0x"); + if (address<16) + Serial.print("0"); + Serial.println(address,HEX); + } + } + + if (post_delay) + { + // Let the bus settle before doing anything else. + delay(10); + } + } +}
\ No newline at end of file |
