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 ?
system
June 28, 2013, 6:25am
3
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.
system
June 28, 2013, 10:26am
5
¿¿¿???
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);
}
}
system
June 28, 2013, 3:44pm
7
The i2C MPU6050 library has parameters that set the sample rate of the accelerometer and gyro.
// I2Cdev library collection - MPU6050 I2C device class
// Based on InvenSense MPU-6050 register map document rev. 2.0, 5/19/2011 (RM-MPU-6000A-00)
// 8/24/2011 by Jeff Rowberg <jeff@rowberg.net>
// Updates should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib
//
// Changelog:
// 2021-09-27 - split implementations out of header files, finally
// 2019-07-08 - Added Auto Calibration routine
// ... - ongoing debug release
// NOTE: THIS IS ONLY A PARIAL RELEASE. THIS DEVICE CLASS IS CURRENTLY UNDERGOING ACTIVE
// DEVELOPMENT AND IS STILL MISSING SOME IMPORTANT FEATURES. PLEASE KEEP THIS IN MIND IF
// YOU DECIDE TO USE THIS PARTICULAR CODE FOR ANYTHING.
/* ============================================
I2Cdev device library code is placed under the MIT license
Copyright (c) 2012 Jeff Rowberg
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
This file has been truncated. show original