Accelerometer type not found: MBL_MW_MODULE_TYPE_NA

Hello!
I'm trying to interface with the MMRL+ sensor with the c++ api and a microcontroller.
I can connect, read & write (for example control the haptic motor).

But I can't read accelerometer data, the base of this problem seems to be that the Accelerometer type is not found, I get 'MBL_MW_MODULE_TYPE_NA' when running:

void check_acc_type(MblMwMetaWearBoard* board) {
  auto acc_type= mbl_mw_metawearboard_lookup_module(board, MBL_MW_MODULE_ACCELEROMETER);
  switch(acc_type) {
  case MBL_MW_MODULE_TYPE_NA:
      // should never reach this case statement
      printf("No accelerometer on this board\n");
      break;
  case MBL_MW_MODULE_ACC_TYPE_MMA8452Q:
      printf("Acc Type = MMA8452Q\n");
      break;
  case MBL_MW_MODULE_ACC_TYPE_BMI160:
      printf("Acc Type = BMI160\n");
      break;
  case MBL_MW_MODULE_ACC_TYPE_BMI270:
      printf("Acc Type = BMI160\n");
      break;
  case MBL_MW_MODULE_ACC_TYPE_BMA255:
      printf("Acc Type = BMA255\n");
      break;
  default:
      printf("Unknown type\n");
      break;
  }
}

Any idea what can be at the base of this problem?
Debug output in the attached file.

Thanks in advance!

Comments

  • What does the diagnostic say from the MetaBase App?

  • edited June 2021

    Hi @Laura,
    Thank you for the quick reply.

    I've added the diagnostics as attachment, looks all fine to me, the accelerometer module is there and has an implementation of 1, which corresponds to the BMI160 = Good. So the less good part is obviously my code.

    From the debug output I see that the function "mbl_mw_metawearboard_lookup_module" doesn't read values from the metaboard with a new BLE-read, so board->module_info should already be populated by the initialization?

    int32_t mbl_mw_metawearboard_lookup_module(const MblMwMetaWearBoard *board, MblMwModule module) {
        auto it = board->module_info.find(module);
        return it == board->module_info.end() || !it->second.present ? MBL_MW_MODULE_TYPE_NA : it->second.implementation;
    }
    
  • So if it's in the diagnostic but not working in your code, then the issue is with your code syntax.
    The module info does get populated when the SDK initializes (right after a connection is secured).

  • edited June 2021

    Okay Thanks Laura! I'll do some digging !

  • @Laura Not finding it so far...
    When I call 'mbl_mw_metawearboard_initialize' I see multiple BLE-reads from the board, but nothing containing the accelerometer type.

    What I get from the board are the following parameters:

    Line 77: Value read from characteristic: 1.5.1
    Line 99: Value read from characteristic: 5
    Line 122: Value read from characteristic: 0.5
    Line 148: Value read from characteristic: MbientLab Inc
    Line 173: Value read from characteristic: 061DC3
    

    These parameters are also accessable when calling mbl_'mw_metawearboard_get_device_information'.
    Where do the accelerometer parameters live? Are they read from the board or derived in the code from the boardtype and version?

    Could use a tip :)

  • When the SDK is initialized, a bunch of additional stuff happens in the background where the code reads information about the hardware on the board using our own protocol over BLE (we have the metawear characteristic that we use to send info using a private protocol).

    Once that is done, we know exactly what sensors are on the board.

    You can then use the mbl_mw_metawearboard_lookup_module API call to see if a module is on board.

    So as long as we are fully connected and the SDK is setup, you should be able to use that function.

    If you can't, it's because your setup is wrong or not done. Maybe you are not waiting long enough for the init() to get done (it does take a few seconds).

    You should check out https://github.com/mbientlab/MetaWear-SDK-JavaScript/blob/master/examples/setup_connect.js

    You can read the setup code in detail here https://github.com/mbientlab/MetaWear-SDK-JavaScript/blob/master/lib/metawear.js

  • Thanks @Laura !
    I managed to get it working, as expected, it was all just bad code.

    The initialization never got completed, mbl_mw_metawearboard_is_initialized always returned 0 and the initialization callback always return status 16 MBL_MW_STATUS_ERROR_TIMEOUT.
    This was because the enable notifications handler wasn't properly implemented, so it kept waiting on a callback after notification but it of course never came. After fixing that it worked like a charm.

    Silly me.

    Thanks again for the support!

Sign In or Register to comment.