Code Monkey home page Code Monkey logo

Comments (3)

flybrianfly avatar flybrianfly commented on September 26, 2024

Can you post more information:

  • What version of the library are you using?
  • What microcontroller?
  • What breakoutboard? Are you using SPI or I2C?
  • Post the simplest example code that demonstrates the problem.

from invensense-imu.

ErfanMoosaviMonazzah avatar ErfanMoosaviMonazzah commented on September 26, 2024

Can you post more information:

  • What version of the library are you using?
  • What microcontroller?
  • What breakoutboard? Are you using SPI or I2C?
  • Post the simplest example code that demonstrates the problem.

I'm using the following MPU connected to a WeMOS D1 mini through SPI connection.
sen-03-005-3
The following libraries are installed using PIO library manager.
bolderflight/Bolder Flight Systems Eigen@^3.0.0
bolderflight/Bolder Flight Systems Unit Conversions@^4.1.0
bolderflight/Bolder Flight Systems MPU9250@^1.0.2

I uploaded the following code to test readSensor() which is a slightly modified version of the example provided at here:

#include <Arduino.h>
/*
Basic_SPI.ino
Brian R Taylor
[email protected]

Copyright (c) 2017 Bolder Flight Systems

Permission is hereby granted, free of charge, to any person obtaining a copy of this software 
and associated documentation files (the "Software"), to deal in the Software without restriction, 
including without limitation the rights to use, copy, modify, merge, publish, distribute, 
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or 
substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#include "MPU9250.h"

// an MPU9250 object with the MPU-9250 sensor on SPI bus 0 and chip select pin 10
MPU9250 IMU(SPI,16);
int status;

void setup() {
  // serial to display data
  Serial.begin(115200);
  while(!Serial) {}

  // start communication with IMU 
  status = IMU.begin();
  if (status < 0) {
    Serial.println("IMU initialization unsuccessful");
    Serial.println("Check IMU wiring or try cycling power");
    Serial.print("Status: ");
    Serial.println(status);
    while(1) {}
  }

  IMU.setSrd(9);

}

long time_flag1 = 0;
long time_flag2 = 0;
long time_sum = 0;
float record_counter = 0;

void loop() {
  // read the sensor
  if(IMU.readSensor())
  {
      // display the data
      IMU.getAccelX_mss();
      IMU.getAccelY_mss();
      IMU.getAccelZ_mss();
      IMU.getGyroX_rads();
      IMU.getGyroY_rads();
      IMU.getGyroZ_rads();
      IMU.getMagX_uT();
      IMU.getMagY_uT();
      IMU.getMagZ_uT();
      IMU.getTemperature_C();
      time_flag1 = time_flag2;
      time_flag2 = millis();
      time_sum += time_flag2 - time_flag1;
      record_counter++;
      Serial.printf("%f, %f\n", record_counter, time_sum / record_counter);
  }
  else Serial.println("Data not ready");
  //delay(100);
}

Since I'm pretty sure that the loop is running way faster than 100hz, I expected to face "Data not ready" very often on the serial output (considering that setSrd() affect the readSensor()), but not a single such case happended.
Also I've added some variables to determine the frequency of running and this is what I faced after a couple of thousand loop iterations:

.
.
.
46287.000000, 2.070279
46288.000000, 2.070277
46289.000000, 2.070276
46290.000000, 2.070274
46291.000000, 2.070273
46292.000000, 2.070271
46293.000000, 2.070270

The second value supposed to converge to the (1/frequency) milliseconds which in case of srd = 9 means 10 milliseconds but
as I tested it for multiple times using different values for srd, no changes happened.
But the same code except using interrupt instead of loop works fine. (Has the same frequency as intended)

from invensense-imu.

flybrianfly avatar flybrianfly commented on September 26, 2024

I'm not sure what version fixed it, but the SRD works as expected in the current version of the library, v5.6.0

from invensense-imu.

Related Issues (20)

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.