Coder Social home page Coder Social logo

arduino_bmi270_bmm150's Introduction

Arduino_BMI270_BMM150

Compile Examples status Spell Check Sync Labels status Arduino Lint

Allows you to read the accelerometer, magnetometer and gyroscope values from the combo BMI270+BMM150 IMU on your Arduino Nano 33 BLE Sense Rev2.

๐Ÿ”Ž Resources

๐Ÿ› Bugs & Issues

If you want to report an issue with this library, you can submit it to the issue tracker of this repository. Remember to include as much detail as you can about your hardware set-up, code and steps for reproducing the issue. Make sure you're using an original Arduino board.

๐Ÿง‘โ€๐Ÿ’ป Development

There are many ways to contribute:

  • Improve documentation and examples
  • Fix a bug
  • Test open Pull Requests
  • Implement a new feature
  • Discuss potential ways to improve this library

You can submit your patches directly to this repository as Pull Requests. Please provide a detailed description of the problem you're trying to solve and make sure you test on real hardware.

๐Ÿ’› Donations

This open-source code is maintained by Arduino with the help of the community. We invest a considerable amount of time in testing code, optimizing it and introducing new features. Please consider donating or sponsoring to support our work, as well as buying original Arduino boards which is the best way to make sure our effort can continue in the long term.

License

Copyright (c) 2022 Arduino SA. All rights reserved.

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

arduino_bmi270_bmm150's People

Contributors

aentinger avatar agdl avatar dependabot[bot] avatar facchinm avatar jacobhylen avatar karlsoderby avatar rocketct avatar rotorman avatar sebromero avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

arduino_bmi270_bmm150's Issues

Some Basic Code improvements

I found some code improvements:

in the header arduino::Stream& is used. some arduino cores do not have stream under the arduino namespace (teensy for example)
Stream is usually used directly:
void debug(Stream&);

Some functions do not return a value but should:


int BoschSensorClass::readAcceleration(float& x, float& y, float& z) {
  struct bmi2_sens_data sensor_data;
  bmi2_get_sensor_data(&sensor_data, &bmi2);
  x = sensor_data.acc.x;
  y = sensor_data.acc.y;
  z = sensor_data.acc.z;
  return 1;//<- this is missing
}
int BoschSensorClass::readGyroscope(float& x, float& y, float& z) {
  struct bmi2_sens_data sensor_data;
  bmi2_get_sensor_data(&sensor_data, &bmi2);
  x = sensor_data.gyr.x;
  y = sensor_data.gyr.y;
  z = sensor_data.gyr.z;
  return 1; //<- this is missing
}

// Magnetometer
int BoschSensorClass::readMagneticField(float& x, float& y, float& z) {
  struct bmm150_mag_data mag_data;
  bmm150_read_mag_data(&mag_data, &bmm1);
  x = mag_data.x;
  y = mag_data.y;
  z = mag_data.z;
  return 1;//<- this is missing
}

also:

  • there is no need to declare all functions virtual if no class inheritance is used
  • the end() and getTemperature() function are declared in the .h file but is missing in the .cpp
  • the same is true for interrupt_handler if mbed is not defined as it is only removed in the .cpp by ifdef but is always defined in the .h
  • in begin, there is no (working) check for chip id. so begin can not fail. it would be good to check the chip id reg (0x00) for value 0x24 to make sure an imu is actually connected to I2c. same goes for the mag device id
  • the debug print result only uses the bmi270 result codes but is also called for results of the BMM150. there should be a second print results for bmi result codes like BMM150_E_NULL_PTR, BMM150_E_DEV_NOT_FOUND etc
  • i2c reads should have the following structure:

beginTransmission
write
endTransmission(false) <- this is important
requestFrom(...)
read
endTransmission() <- only end transmission after interaction is done


No member named 'onInterrupt' ?

The "Simple" examples work, but the "Interrupts_subclassing" example fails to compile with two separate problems:

There is an error regarding Wire1 (which I assume should be Wire).

There is also this:

Compilation error: 'class MyBoschSensor' has no member named 'onInterrupt'

I'm just trying to get the example to run - no changes.

Missing implementation of getTemperature()

The library declares a BoschSensorClass::getTemperature() function:

float getTemperature();

But if you try to use it:

#include <Arduino_BMI270_BMM150.h>
void setup() {
  IMU.getTemperature();
}
void loop() {}

compilation fails due to the declared function not being implemented:

C:\Users\per\AppData\Local\Temp\.arduinoIDE-unsaved2023718-18988-8022i1.jjmfp\sketch_aug18a/sketch_aug18a.ino:3: undefined reference to `BoschSensorClass::getTemperature()'

I see from its datasheet that the sensor does support temperature readings.

Magnetic Field Sample Rate unit Change

Hello, I noticed that the units for the magnetic field sample rate changed from microTesla to Hz and was wondering if I will need to make this change in the scripts that I have been using with the BMM150. Thank you.

arduino is not declared error

In file included from /home/hu/Arduino/libraries/Arduino_BMI270_BMM150/src/Arduino_BMI270_BMM150.h:23:0,
                 from /tmp/.arduinoIDE-unsaved2023218-79256-177af8o.lu7x/sketch_mar18a/sketch_mar18a.ino:1:
/home/hu/Arduino/libraries/Arduino_BMI270_BMM150/src/BoschSensorClass.h:38:16: error: 'arduino' has not been declared
     void debug(arduino::Stream&);
                ^~~~~~~
/home/hu/Arduino/libraries/Arduino_BMI270_BMM150/src/BoschSensorClass.h:38:31: error: expected ',' or '...' before '&' token
     void debug(arduino::Stream&);
                               ^

exit status 1

Compilation error: exit status 1

I am getting arduino not declared error, any possible cause?

how to increase the sample rate

Dear everyone,

I am struggling in increasing the sample rate of BMI270 on Arduino nano BLE sense Rev2.

I slightly modify the example of examples/interrupts, and I change the line of ODR.
It turns out my code can successfully go to 200Hz, but fail to go to 400Hz or higher.
It is hard to believe it occurs because of the upper bound of Arduino, since I can achieve much better sample rate on others.
I attach my code as follows:

#include "Arduino_BMI270_BMM150.h"

class MyBoschSensor: public BoschSensorClass {

  public:
    MyBoschSensor(TwoWire& wire = Wire) : BoschSensorClass(wire) {};

  protected:
    virtual int8_t configure_sensor(struct bmi2_dev *dev)
    {
      int8_t rslt;
      uint8_t sens_list[2] = { BMI2_ACCEL, BMI2_GYRO };

      struct bmi2_int_pin_config int_pin_cfg;
      int_pin_cfg.pin_type = BMI2_INT1;
      int_pin_cfg.int_latch = BMI2_INT_NON_LATCH;
      int_pin_cfg.pin_cfg[0].lvl = BMI2_INT_ACTIVE_HIGH;
      int_pin_cfg.pin_cfg[0].od = BMI2_INT_PUSH_PULL;
      int_pin_cfg.pin_cfg[0].output_en = BMI2_INT_OUTPUT_ENABLE;
      int_pin_cfg.pin_cfg[0].input_en = BMI2_INT_INPUT_DISABLE;

      struct bmi2_sens_config sens_cfg[2];
      sens_cfg[0].type = BMI2_ACCEL;
      sens_cfg[0].cfg.acc.bwp = BMI2_ACC_OSR2_AVG2;
      sens_cfg[0].cfg.acc.odr = BMI2_ACC_ODR_400HZ;
      sens_cfg[0].cfg.acc.filter_perf = BMI2_PERF_OPT_MODE;
      sens_cfg[0].cfg.acc.range = BMI2_ACC_RANGE_4G;
      sens_cfg[1].type = BMI2_GYRO;
      sens_cfg[1].cfg.gyr.filter_perf = BMI2_PERF_OPT_MODE;
      sens_cfg[1].cfg.gyr.bwp = BMI2_GYR_OSR2_MODE;
      sens_cfg[1].cfg.gyr.odr = BMI2_GYR_ODR_25HZ;
      sens_cfg[1].cfg.gyr.range = BMI2_GYR_RANGE_2000;
      sens_cfg[1].cfg.gyr.ois_range = BMI2_GYR_OIS_2000;

      rslt = bmi2_set_int_pin_config(&int_pin_cfg, dev);
      if (rslt != BMI2_OK)
        return rslt;

      rslt = bmi2_map_data_int(BMI2_DRDY_INT, BMI2_INT1, dev);
      if (rslt != BMI2_OK)
        return rslt;

      rslt = bmi2_set_sensor_config(sens_cfg, 2, dev);
      if (rslt != BMI2_OK)
        return rslt;

      rslt = bmi2_sensor_enable(sens_list, 2, dev);
      if (rslt != BMI2_OK)
        return rslt;

      return rslt;
    }
};

MyBoschSensor myIMU(Wire1);


float x, y, z;
volatile unsigned int count = 0;
unsigned int time_start;
void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  while (!Serial);
  myIMU.debug(Serial);
  myIMU.onInterrupt(print_data);
  myIMU.begin();

  Serial.print("Accelerometer sample rate = ");
  Serial.println(myIMU.accelerationSampleRate());
  time_start = millis();
}
void print_data() {
  // we can also read accelerometer / gyro data here!
  Serial.println("Got new data!");
  myIMU.readAcceleration(x, y, z);
  count +=1;
}

void loop() {
  if ((millis() - time_start) > 2000)
  {
    Serial.println(count/2);
    count = 0;
    time_start = millis();
  }
  }

Can't get the interrupts to work consistently

Hi, I'm trying to run the interrupts_subclassing example (with a small change: a bool flag instead of a print statement in the interrupt function) and I'm experiencing inconsistent behavior. When I upload the code to the board or push the button to restart the program, sometimes the interrupts will come in ("Got new data!" will be printed in my Serial monitor, as expected), sometimes they won't come in (nothing will be printed). I tried with a blinking led in the interrupt function, that results in the same observation (behavior is sometimes as I expect, sometimes nothing happens). I have tried on a different (brand new) board, the same happens.
I added my code below:

#include <Arduino.h>
#include <Arduino_BMI270_BMM150.h>

class MyBoschSensor: public BoschSensorClass {

  public:
    MyBoschSensor(TwoWire& wire = Wire) : BoschSensorClass(wire) {};

  protected:
    virtual int8_t configure_sensor(struct bmi2_dev *dev)
    {
      int8_t rslt;
      uint8_t sens_list[2] = { BMI2_ACCEL, BMI2_GYRO };

      struct bmi2_int_pin_config int_pin_cfg;
      int_pin_cfg.pin_type = BMI2_INT1;
      int_pin_cfg.int_latch = BMI2_INT_NON_LATCH;
      int_pin_cfg.pin_cfg[0].lvl = BMI2_INT_ACTIVE_HIGH;
      int_pin_cfg.pin_cfg[0].od = BMI2_INT_PUSH_PULL;
      int_pin_cfg.pin_cfg[0].output_en = BMI2_INT_OUTPUT_ENABLE;
      int_pin_cfg.pin_cfg[0].input_en = BMI2_INT_INPUT_DISABLE;

      struct bmi2_sens_config sens_cfg[2];
      sens_cfg[0].type = BMI2_ACCEL;
      sens_cfg[0].cfg.acc.bwp = BMI2_ACC_OSR2_AVG2;
      sens_cfg[0].cfg.acc.odr = BMI2_ACC_ODR_25HZ;
      sens_cfg[0].cfg.acc.filter_perf = BMI2_PERF_OPT_MODE;
      sens_cfg[0].cfg.acc.range = BMI2_ACC_RANGE_4G;
      sens_cfg[1].type = BMI2_GYRO;
      sens_cfg[1].cfg.gyr.filter_perf = BMI2_PERF_OPT_MODE;
      sens_cfg[1].cfg.gyr.bwp = BMI2_GYR_OSR2_MODE;
      sens_cfg[1].cfg.gyr.odr = BMI2_GYR_ODR_25HZ;
      sens_cfg[1].cfg.gyr.range = BMI2_GYR_RANGE_2000;
      sens_cfg[1].cfg.gyr.ois_range = BMI2_GYR_OIS_2000;

      rslt = bmi2_set_int_pin_config(&int_pin_cfg, dev);
      if (rslt != BMI2_OK)
        return rslt;

      rslt = bmi2_map_data_int(BMI2_DRDY_INT, BMI2_INT1, dev);
      if (rslt != BMI2_OK)
        return rslt;

      rslt = bmi2_set_sensor_config(sens_cfg, 2, dev);
      if (rslt != BMI2_OK)
        return rslt;

      rslt = bmi2_sensor_enable(sens_list, 2, dev);
      if (rslt != BMI2_OK)
        return rslt;

      return rslt;
    }
};

volatile bool interruptDetected;
MyBoschSensor customIMU(Wire1);

void handleInterrupt() {
  interruptDetected = true;
  //digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
}

void setup() {
  Serial.begin(9600);
  while (!Serial);

  //pinMode(LED_BUILTIN, OUTPUT);

  customIMU.debug(Serial);
  customIMU.onInterrupt(handleInterrupt);
  customIMU.begin();
}

void loop() {
  if (interruptDetected) {
    Serial.println("Got new data!");
    interruptDetected = false;
  }
}

Is anyone experiencing something similar, could it be something in my setup? I'm using platformio in VSCode, the following is my ini file:

[env:nano33ble]
platform = [email protected]
board = nano33ble
framework = arduino

board_build.mcu = nrf52840

monitor_speed = 9600

I'm using a Nano 33 BLE Sense Rev 2 obviously, should I change something in the ini file? I haven't found an option to select the sense rev 2 in platformIO.

Any clues on what might be going on are much appreciated !

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.