MPU6050 sample rate 100 Hz

Hello,

I'm working on a sketch that save the values ??obtained by the GPS (5 Hz), and the values ??obtained by the accelerometer (MPU6050), in a SD card.
The problem is that the MPU6050 is working about the 300 Hz and I just want to do to 100 Hz.
Is possible set the sample rate of the accelerometer (MPU6050) to 100 hz?

If I use many Serial.println() in the code, the sample rate is changing. Many Serial.print() = less sample rate...

Thanks.

Can you give a link to the library you use and the example sketch ?
Can you upload your sketch between code tags ?

Sorry for the delay... :~

I use this library: i2cdevlib/Arduino/MPU6050 at master · jrowberg/i2cdevlib · GitHub

And the code is https://github.com/jrowberg/i2cdevlib/blob/master/Arduino/MPU6050/Examples/MPU6050_raw/MPU6050_raw.ino

I want that this program "print" 100 samples per second and now the program work about 300 hz.

Thanks

I want that this program "print" 100 samples per second

Printing is a slow process, you will struggle to get output that fast, do you want this displayed on a computer, again the computer will struggle to do that for you. And if Microsoft are involved anywhere along the line then just forget it.

¿¿¿???

My problem is that MPU6050 is working about 300Hz but I want to work at 100Hz, therefore, I want to work more slowly.

My problem is that MPU6050 is working about 300Hz

Then why are you reading it at that rate.
Look at the blink without delay example and use the millis() timer to read it at the interval that you want.

#include "Wire.h"

#include "I2Cdev.h"
#include "MPU6050.h"

// class default I2C address is 0x68
// specific I2C addresses may be passed as a parameter here
// AD0 low = 0x68 (default for InvenSense evaluation board)
// AD0 high = 0x69
MPU6050 accelgyro;

long timeToSample = 10;
long lastTime;
int16_t ax, ay, az;
int16_t gx, gy, gz;

#define LED_PIN 13
bool blinkState = false;

void setup() {
    // join I2C bus (I2Cdev library doesn't do this automatically)
    Wire.begin();

    // initialize serial communication
    // (38400 chosen because it works as well at 8MHz as it does at 16MHz, but
    // it's really up to you depending on your project)
    Serial.begin(38400);

    // initialize device
    Serial.println("Initializing I2C devices...");
    accelgyro.initialize();

    // verify connection
    Serial.println("Testing device connections...");
    Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed");

    // configure Arduino LED for
    pinMode(LED_PIN, OUTPUT);
    lastTime = millis();
}

void loop() {
  if(millis() - lastTime > timeToSample) {
    lastTime = millis();
    // read raw accel/gyro measurements from device
    accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
    // display tab-separated accel/gyro x/y/z values
    Serial.print("a/g:\t");
    Serial.print(ax); Serial.print("\t");
    Serial.print(ay); Serial.print("\t");
    Serial.print(az); Serial.print("\t");
    Serial.print(gx); Serial.print("\t");
    Serial.print(gy); Serial.print("\t");
    Serial.println(gz);

    // blink LED to indicate activity
    blinkState = !blinkState;
    digitalWrite(LED_PIN, blinkState);
  }
  
}

The i2C MPU6050 library has parameters that set the sample rate of the accelerometer and gyro.