Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sampling rate/range configuration? #2

Open
mizasquare opened this issue Dec 6, 2019 · 2 comments
Open

sampling rate/range configuration? #2

mizasquare opened this issue Dec 6, 2019 · 2 comments

Comments

@mizasquare
Copy link

mizasquare commented Dec 6, 2019

is there a specific reason for fixing imu sampling ranges and rates?

@hstarmans
Copy link

hstarmans commented Feb 19, 2020

I had the same issues best is to use the sparkfun library
The library has options to change settings, like sampling rate etc.
If you compile this code with the default library it will complain about some statements in SPI, you need to comment these out.
You need to set initAccel, initGyro to public. Also, note that you can't have different frequencies for these if they are both enabled (see datasheet).
The Wire1 clock has to be changed to 400000 otherwise code won't work properly.
You can test below by changing sample rate. Note, that the Gyro overrules the accelerometer if it is enabled.

So your code would become;

#include <Wire.h>
#include <SPI.h>
#include <SparkFunLSM9DS1.h>


int int_received = 0;
unsigned long tijd;
LSM9DS1 imu;


void setup() {
  Serial.begin(115200);
  while (!Serial);
  Wire1.begin();
  Wire1.setClock(400000);
  while (imu.begin(0x6B, 0X1E, Wire1) == false) 
  {
    Serial.println("Failed to communicate with LSM9DS1.");
    Serial.println("Will retry in 1 second.");
    delay(1000);
  }
  imu.settings.accel.sampleRate = 6;
  imu.settings.gyro.sampleRate = 6;
  imu.initAccel();
  imu.initGyro();
}

void loop() {
    Serial.println("awaiting command");
    Serial.println(imu.settings.gyro.sampleRate);
    delay(1000);
    int_received = Serial.parseInt();
    switch(int_received) {
      case 0 : // parseInt polls and returns 0 if nothing is received so ignored
               break;
      case 1 : {Serial.println("One received");
               int total_time = 952;
               int iteration = 0;
               tijd = millis();
               while(iteration<total_time){
                if (imu.accelAvailable())
                {
                imu.readAccel();
                iteration = iteration + 1;
                }
               }
               unsigned long difference; 
               difference = millis()-tijd;
               if(difference>1100){
                  Serial.println("Test failed");
                  Serial.println(difference);
               }
               else{
                  Serial.println("Test succeeded in ms");
                  Serial.println(difference);
               }
               break;}
      default:{Serial.println(int_received); 
              Serial.println("Invalid command");
              break;}
    };
}

@FemmeVerbeek
Copy link

In operational mode 2 the gyro and accelerometer share their ODR. Both obey to the setting in the gyro register.
In operational mode 1 the gyro is switched off, the accelerometer ODR setting must be written in a different register.

I've written an update for this library with the full possibilities of changing and interrogating the chip's ODR, Full scale and bandwidth filter value. I made a pull request here and am awaiting the answer.
If you want to check it out
https://github.com/FemmeVerbeek/Arduino_LSM9DS1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants