From 9c07c2b85d908f699f8ba590b1d60232157eca90 Mon Sep 17 00:00:00 2001 From: Nathan Perry Date: Wed, 23 Oct 2024 22:57:18 -0400 Subject: test_fw: read veml and bme --- test_fw/include/i2c_scan.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 test_fw/include/i2c_scan.h (limited to 'test_fw/include/i2c_scan.h') 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 +#include + +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 -- cgit v1.3.1