firmware: diagnose BNO086 I2C address
This commit is contained in:
@@ -9,6 +9,26 @@ Adafruit_BNO08x bno086(-1);
|
||||
sh2_SensorValue_t value;
|
||||
bool initialized = false;
|
||||
float radiansToDegrees(float r) { return r * 180.0f / PI; }
|
||||
bool addressResponds(uint8_t address) {
|
||||
Wire.beginTransmission(address);
|
||||
return Wire.endTransmission() == 0;
|
||||
}
|
||||
|
||||
uint8_t findBnoAddress() {
|
||||
Serial.println("Scanning I2C bus on D7 SDA / D8 SCL...");
|
||||
uint8_t bnoAddress = 0;
|
||||
for (uint8_t address = 1; address < 127; address++) {
|
||||
if (!addressResponds(address)) continue;
|
||||
Serial.print("I2C device found at 0x");
|
||||
if (address < 0x10) Serial.print('0');
|
||||
Serial.println(address, HEX);
|
||||
if (address == BNO086_I2C_ADDRESS || address == BNO086_I2C_ADDRESS_ALTERNATE) {
|
||||
bnoAddress = address;
|
||||
}
|
||||
}
|
||||
return bnoAddress;
|
||||
}
|
||||
|
||||
void updateEuler(ImuState& s) {
|
||||
float sinr = 2 * (s.real * s.i + s.j * s.k);
|
||||
float cosr = 1 - 2 * (s.i * s.i + s.j * s.j);
|
||||
@@ -23,7 +43,18 @@ void updateEuler(ImuState& s) {
|
||||
|
||||
bool initImu() {
|
||||
Wire.begin(BNO086_SDA_PIN, BNO086_SCL_PIN);
|
||||
initialized = bno086.begin_I2C(BNO086_I2C_ADDRESS, &Wire);
|
||||
Wire.setClock(BNO086_I2C_CLOCK_HZ);
|
||||
delay(100);
|
||||
|
||||
uint8_t address = findBnoAddress();
|
||||
if (address == 0) {
|
||||
Serial.println("No BNO086 found at 0x4A or 0x4B");
|
||||
return false;
|
||||
}
|
||||
|
||||
Serial.print("Starting BNO086 at 0x");
|
||||
Serial.println(address, HEX);
|
||||
initialized = bno086.begin_I2C(address, &Wire);
|
||||
if (initialized) initialized = bno086.enableReport(SH2_ROTATION_VECTOR, IMU_REPORT_INTERVAL_US);
|
||||
return initialized;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user