aboutsummaryrefslogtreecommitdiff
path: root/test_fw/include/i2c_scan.h
diff options
context:
space:
mode:
authorNathan Perry <np@npry.dev>2024-10-23 22:57:18 -0400
committerNathan Perry <np@npry.dev>2024-10-23 22:57:18 -0400
commit9c07c2b85d908f699f8ba590b1d60232157eca90 (patch)
tree750796b85ad46e1aff8f55da2d1e9f081ee208d6 /test_fw/include/i2c_scan.h
parentf2fc1133d5ddf507d92192310f3f3c71fb1c0ba7 (diff)
test_fw: read veml and bme
Diffstat (limited to 'test_fw/include/i2c_scan.h')
-rw-r--r--test_fw/include/i2c_scan.h37
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