HI FRIENDS
I WOULD LIKE TO KNOW HOW TO INCREASE THE DATA SAMPLING OF THE MPU 6050 , IM ACTUALLY USING THIS CODE ... AND I CAN JUST READ ABOUT 100 SAMPLES PER SECOND OF ACCELERATIONHK
AND I WOULD LIKE TO READ ABOUT 1000 SAMPLES PER SECOND , IS THIS POSSIBLE , I KNOW THAT THE SAMPLING FREQUENCY IS 1 KHZ OF THE ACCELEROMETER ...
#include <Wire.h>
long accelX, accelY, accelZ;
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
void setup() {
Wire.begin();
Serial.begin(115200);
setupMPU();
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
void loop() {
recordAccelRegisters();
printData();
delay(10);
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
void setupMPU() {
Wire.beginTransmission(0b1101000); //This is the I2C address of the MPU (b1101000/b1101001 for AC0 low/high datasheet sec. 9.2)
Wire.write(0x6B); //Accessing the register 6B - Power Management (Sec. 4.28)
Wire.write(0b00000000); //Setting SLEEP register to 0. (Required; see Note on p. 9)
Wire.endTransmission();
Wire.beginTransmission(0b1101000); //I2C address of the MPU
Wire.write(0x1B); //Accessing the register 1B - Gyroscope Configuration (Sec. 4.4)
Wire.write(0x00001000); //Setting the gyro to full scale //+- 250deg./s=00//+-500deg/s=01//+-1000deg/s=10//+-2000deg/s=11//
Wire.endTransmission();
Wire.beginTransmission(0b1101000); //I2C address of the MPU
Wire.write(0x1C); //Accessing the register 1C - Acccelerometer Configuration (Sec. 4.5)
Wire.write(0b00011000); //Setting the accel to //+/- 2g=00 //+-4g=01//+-8g=10//+-16g=11//
Wire.endTransmission();
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
void recordAccelRegisters() {
Wire.beginTransmission(0b1101000); //I2C address of the MPU
Wire.write(0x3B); //Starting register for Accel Readings
Wire.endTransmission();
Wire.requestFrom(0b1101000, 6); //Request Accel Registers (3B - 40)
while (Wire.available() < 6);
accelX = Wire.read() << 8 | Wire.read(); //Store first two bytes into accelX
accelY = Wire.read() << 8 | Wire.read(); //Store middle two bytes into accelY
accelZ = Wire.read() << 8 | Wire.read(); //Store last two bytes into accelZ
processAccelData();
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
void processAccelData() {///+-2 = 16384 lsb //+-4=8192 lsb //+-8=4096 lsb //+-16=2048 lsb//
gForceX = accelX / 2048.0;
gForceY = accelY / 2048.0;
gForceZ = (accelZ / 2048.0)-0.11;
}
void printData() {
Serial.println(gForceZ,3);
}