THIS HAS BEEN SOLVED BY ME AFTER MANY HOURS OF GOOGLE. See bottom of post for solution
By default, the MPU6050 is set to +-2g for the accelerometer. I need to change this to 8g for my project.
I`m using the code supplied by TKJ Electronics, Kristian Lauszus. It includes a Kalman Filter and calculates lots of angles and keeps the gyro from drifting. I cannot seem to change the accelerometer sensitivity, which is default =-2g.
Using other code found online, and the well known MPU6050 class from Jeff Rowberg, I am able to change the sensitivity simply by writing
accelgyro.setFullScaleAccelRange(MPU6050_ACCEL_FS_8);
However, this does not apply with the Kalman filter code, and I have no idea why. I hope someone here can help me.
The code I am using looks like this, and the accelerometer sensitivity is initialized in line 46. It looks like this:
i2cData[3] = 0x00; // Set Accelerometer Full Scale Range to ±2g
Based on the data sheet for the MPU6050, I should be able to change the sensitivity by changing the registry Hex 1C or Decimal 28.
To change the sensitivity, I need to write the value of 0, 1, 2, or 3 to the registry corresponding to +-2g, +-4g, +-8g, or +-16g of sensitivity.
However the sensitivity is simply unchanged when I run the code and print the raw values.
Here is a sample of the code (I cannot post it all, forum says it's too big). I have no idea what i2cData[] is, I don't see it initialized anywhere. As you can probably tell, I am a very beginner for this kind of stuff. Any help would be greatly appreciated!
#include <Wire.h>
#include "Kalman.h" // Source: https://github.com/TKJElectronics/KalmanFilter
void setup() {
Serial.begin(115200);
Wire.begin();
TWBR = ((F_CPU / 400000L) - 16) / 2; // Set I2C frequency to 400kHz
i2cData[0] = 7; // Set the sample rate to 1000Hz - 8kHz/(7+1) = 1000Hz
i2cData[1] = 0x00; // Disable FSYNC and set 260 Hz Acc filtering, 256 Hz Gyro filtering, 8 KHz sampling
i2cData[2] = 0x00; // Set Gyro Full Scale Range to ±250deg/s
i2cData[3] = 0x02; // Set Accelerometer Full Scale Range ( ±2g = 0x00 ±4g=0x01 ±8g=0x02, ±16g = 0x03 )
while (i2cWrite(0x19, i2cData, 4, false)); // Write to all four registers at once
while (i2cWrite(0x6B, 0x01, true)); // PLL with X axis gyroscope reference and disable sleep mode
****SOLUTION
I need to write to the registry 0x1c or Decimal 28, I need to write the value 2, which is 00010000 = 0x10 so the line of code that changes the acceleration sensitivity to +-8g is:
i2cData[3] = 0x10; // Set Accelerometer Full Scale Range ( ±2g = 0x00 ±4g=0x01 ±8g=0x10, ±16g = 0x11 )