sparkfun / SparkFun_BNO08x_Arduino_Library

An Arduino Library for the BNO08x IMU combination triple axis accelerometer/gyro/magnetometer packaged with an ARM Cortex M0+ running powerful algorithms.
Other
14 stars 8 forks source link

Library: Can't initialize two BNO086 on one I2C bus #3

Open iLoveAndyBaker opened 1 year ago

iLoveAndyBaker commented 1 year ago

Devices ACK on addresses 0x4A and 0X46, but library won't allow both to init.

RP2040 (As KB2040)

Steps to reproduce

Daisychain two BNO086 via Qwiic connectors, jump address pin on one unit, cut pullups on end unit.

Run example code:


#include "SparkFun_BNO08x_Arduino_Library.h"  // CTRL+Click here to get the library: http://librarymanager/All#SparkFun_BNO08x
BNO08x myIMU;
BNO08x yourIMU;

void setup() {
  Serial.begin(115200);
  delay(5000);
  Serial.println();
  Serial.println("BNO08x Read Example");

  Wire.begin();
  Wire.setClock(100000); //Increase I2C data rate to 400kHz

  if (myIMU.begin(0x4B,Wire,-1,-1) == false) {
    Serial.println("First BNO08x not detected at default I2C address. Check your jumpers and the hookup guide. Freezing...");
    //while (1)
      ;
  } else{
    Serial.println("First IMU found!");
  }

  if (yourIMU.begin(0x4A,Wire,-1,-1) == false) {
    Serial.println("Second BNO08x not detected at default I2C address. Check your jumpers and the hookup guide. Freezing...");
    while (1)
      ;
  } else{
    Serial.println("Second IMU found!");
  }

Expected behavior

Both chips ACK and program continues with begin == false. BUT...

Actual behavior

Second to be init'd will ack, but begin returns false

Device acknowledged at 75
First IMU found!
Device acknowledged at 74
Second BNO08x not detected at default I2C address. Check your jumpers and the hookup guide. Freezing...

I changed the library Sparkfun_BNO8x_Arduino_Library.cpp to call out the address that ACK'd

        return (false); 

// CHANGED THIS SERIAL MESSAGE
    Serial.print(F("Device acknowledged at "));
    Serial.println(_deviceAddress);
    //delay(1000);

    _HAL.open = i2chal_open;

Re-ordering the initialization of the boards doesn't help. The one that goes SECOND fails.

BNO08x Read Example
Device acknowledged at 74
First IMU found!
Device acknowledged at 75
Second BNO08x not detected at default I2C address. Check your jumpers and the hookup guide. Freezing...
iLoveAndyBaker commented 1 year ago

Update: Even tried on separate I2C busses, first device to .begin will initialize, second will not. Reorder and it's still the first one in the code will work, the next will not.

lewispg228 commented 11 months ago

Hi @iLoveAndyBaker , Sorry, but this can only support a single device on the bus. See here. This is due to the fact that the CEVA-DSP SH2 driver has some static methods and static variables. Not sure if this is even possible with the SHTP protocol, but if you wanted to, it might be worth starting another issue on their repo requesting this feature.

rah2501 commented 11 months ago

I raised an issue with the SH2 library: https://github.com/ceva-dsp/sh2/issues/9

Is the closure of this SparkFun_BNO08x_Arduino_Library issue a signal that you're unwilling to add support for more than one sensor? Do you consider the limitation of running only a single sensor to be a bug that should be fixed? If so, please reopen this issue.

lewispg228 commented 11 months ago

Hi @rah2501 , Thank you for submitting the issue and PR on the SH2 Library. When CEVA responds and/or adds in the ability to do multiple sensors, we would be excited to adapt our library to also work with multiple sensors. For now, we will leave this issue open. Thanks again and we look forward to seeing what CEVA says.

rah2501 commented 4 weeks ago

we look forward to seeing what CEVA says

FYI, CEVA have completely ignored the github issue, the PR I raised and generally seem to have stopped communicating with the community. I even did some digging and found the email address of one of the engineers (David Wheeler) and tried emailing them but again, no response. Disappointing.

Edit: To make it worse, a commit was made by David Wheeler to the SH2 github repository the day after I raised the issue. Feels like a bit of a "fsck you". Perhaps they didn't appreciate people pointing out flaws in their handiwork.

iLoveAndyBaker commented 4 weeks ago

I have collected the following: In the SH2 library: @rah2501 states that: The BNO08x library calls sh2_service() which uses another global variable named _sh2 for sensor-specific state.

@rah2501 did some changes to sh2.h at https://github.com/ceva-dsp/sh2/pull/10 but just copying that file over still wouldn't make it compile, and that's the extent of my expertise (I'm more of a project manager in this respect)

So even though it's probably not best practices to just patch up the SH2.h that lives in the Sparkfun library, I kinda don't see how this is going to get resolved in the usual proper manner without support from the upstream CEVA people....without simply patching up this version that's sitting here in the Sparkfun library. There's nothing stopping me from doing this on my own hard drive either, but that's not very useful to anybody else.

Oh and besides the whole static methods issue, there might need to be a need to call out the INT and RST per device too, because I don't see how #define BNO08X_INT xxx is going to work unless it's common across this whole SHTP bus, which I confess I hardly understand its purpose.

iLoveAndyBaker commented 3 weeks ago

CEVA says fork it and fend for ourselves.

https://github.com/ceva-dsp/sh2/issues/9#issuecomment-2405479339