I am doing a project on walking pattern analysis. My job is to record acclerometer and gyroscope raw data. I am unable to set sampling frequency of mpu 6050 to 100 Hz. Please help me out of this problem. My code is
#include "MPU6050.h"
#include
#include
#include
elapsedMillis timeElapsed;
SoftwareSerial Bluetooth(0, 1); // RX, TX
const int MPU_addr=0x68; // I2C address of the MPU-6050
MPU6050 mpu;
int16_t AcX,AcY,AcZ,GyX,GyY,GyZ;
/*#define MPU6050_ACCEL_FS_2 0x00
#define MPU6050_ACCEL_FS_4 0x01
#define MPU6050_ACCEL_FS_8 0x02
#define MPU6050_ACCEL_FS_16 0x03
#define MPU6050_GYRO_FS_250 0x00
#define MPU6050_GYRO_FS_500 0x01
#define MPU6050_GYRO_FS_1000 0x02
#define MPU6050_GYRO_FS_2000 0x03*/
uint8_t devStatus; // return status after each device operation (0 = success, !0 = error)
//unsigned long startTime;
//unsigned long elapsedTime;
void setup(){
Bluetooth.begin(9600);
Wire.begin();
Wire.beginTransmission(MPU_addr);
Wire.write(0x6B); // PWR_MGMT_1 register
Wire.write(0); // set to zero (wakes up the MPU-6050)
Wire.endTransmission(true);
Serial.begin(9600);
mpu.initialize();
// verify connection
Serial.println(F("Testing device connections..."));
Serial.println(mpu.testConnection() ? F("MPU6050 connection successful") : F("MPU6050 connection failed"));
// mpu.setFullScaleGyroRange(MPU6050_GYRO_FS_2000);
// mpu.setFullScaleAccelRange(MPU6050_ACCEL_FS_4);
mpu.setFullScaleGyroRange(3); //set the gyro range to 2000
mpu.setFullScaleAccelRange(2); //set the accelerometer sensibilty to 16g
Serial.println("Full scale gyro range : ");
Serial.println(mpu.getFullScaleGyroRange());
Serial.println(mpu.getFullScaleAccelRange());
mpu.setRate(9);
Serial.println("Sampling rate: ");
Serial.println(mpu.getRate());
}
void loop(){
Wire.begin();
Wire.setClock(400000L);
Wire.beginTransmission(MPU_addr);
Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H)
Wire.endTransmission(false);
Wire.requestFrom(MPU_addr,14,true); // request a total of 14 registers
//startTime = millis();
AcX=Wire.read()