public class MPU6050 extends I2CComponent
[datasheet - p.7] Product Overview
The MPU-60X0 is the world’s first integrated 6-axis MotionTracking device that combines a 3-axis gyroscope, 3-axis accelerometer, and a Digital Motion Processor™ (DMP) all in a small 4x4x0.9mm package. With its dedicated I2C sensor bus, it directly accepts inputs from an external 3-axis compass to provide a complete 9-axis MotionFusion™ output.
The MPU-60X0 features three 16-bit analog-to-digital converters (ADCs) for digitizing the gyroscope outputs and three 16-bit ADCs for digitizing the accelerometer outputs. For precision tracking of both fast and slow motions, the parts feature a user-programmable gyroscope full-scale range of ±250, ±500, ±1000, and ±2000°/sec (dps) and a user-programmable accelerometer full-scale range of ±2g, ±4g, ±8g, and ±16g.
Communication with all registers of the device is performed using I2C at 400kHz.
For power supply flexibility, the MPU-60X0 operates from VDD power supply voltage range of 2.375V-3.46V. Additionally, the MPU-6050 provides a VLOGIC reference pin (in addition to its analog supply pin: VDD), which sets the logic levels of its I2C interface. The VLOGIC voltage may be 1.8V±5% or VDD.
[datasheet - p.10-11] Features
Datasheet: MPU6050 (part 1), MPU6050 (part 2 - registers map and descriptions)
Note: the datasheet informations related to this sensor are about ~100 pages long. We don't implemented all the features in this driver, but we provide you the updateRegisterValue(int registerAddress, int registerValue) method from which you can easily update the content of a register, and the readRegisterValue(int registerAddress) method from which you can easily read the content of a register of the component. Enjoy ! :)
Example of use: MPU6050Example
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_DLPF_CFG
Default value for the digital low pass filter (DLPF) setting
for both gyroscope and accelerometer.
|
static int |
DEFAULT_MPU6050_ADDRESS
Default address of the MPU6050 device.
|
static int |
DEFAULT_SMPLRT_DIV
Default value for the sample rate divider.
|
static int |
MPU6050_REG_ADDR_ACCEL_CONFIG
[datasheet 2 - p.15] Accelerometer Configuration
|
static int |
MPU6050_REG_ADDR_ACCEL_XOUT_H
[datasheet 2 - p.29] Accelerometer Measurements
|
static int |
MPU6050_REG_ADDR_ACCEL_XOUT_L
[datasheet 2 - p.29] Accelerometer Measurements
|
static int |
MPU6050_REG_ADDR_ACCEL_YOUT_H
[datasheet 2 - p.29] Accelerometer Measurements
|
static int |
MPU6050_REG_ADDR_ACCEL_YOUT_L
[datasheet 2 - p.29] Accelerometer Measurements
|
static int |
MPU6050_REG_ADDR_ACCEL_ZOUT_H
[datasheet 2 - p.29] Accelerometer Measurements
|
static int |
MPU6050_REG_ADDR_ACCEL_ZOUT_L
[datasheet 2 - p.29] Accelerometer Measurements
|
static int |
MPU6050_REG_ADDR_CONFIG
[datasheet 2 - p.13] Configuration
|
static int |
MPU6050_REG_ADDR_GYRO_CONFIG
[datasheet 2 - p.14] Gyroscope Configuration
|
static int |
MPU6050_REG_ADDR_GYRO_XOUT_H
[datasheet 2 - p.31] Gyroscope Measurements
|
static int |
MPU6050_REG_ADDR_GYRO_XOUT_L
[datasheet 2 - p.31] Gyroscope Measurements
|
static int |
MPU6050_REG_ADDR_GYRO_YOUT_H
[datasheet 2 - p.31] Gyroscope Measurements
|
static int |
MPU6050_REG_ADDR_GYRO_YOUT_L
[datasheet 2 - p.31] Gyroscope Measurements
|
static int |
MPU6050_REG_ADDR_GYRO_ZOUT_H
[datasheet 2 - p.31] Gyroscope Measurements
|
static int |
MPU6050_REG_ADDR_GYRO_ZOUT_L
[datasheet 2 - p.31] Gyroscope Measurements
|
static int |
MPU6050_REG_ADDR_INT_ENABLE
[datasheet 2 - p.27] Interrupt Enable
|
static int |
MPU6050_REG_ADDR_PWR_MGMT_1
[datasheet 2 - p.40] Power Management 1
|
static int |
MPU6050_REG_ADDR_PWR_MGMT_2
[datasheet 2 - p.42] Power Management 2
|
static int |
MPU6050_REG_ADDR_SMPRT_DIV
[datasheet 2 - p.11] Sample Rate Divider
|
static int |
MPU6050_REG_ADDR_TEMP_OUT_H
[datasheet 2 - p.30] Temperature Measurement
|
static int |
MPU6050_REG_ADDR_TEMP_OUT_L
[datasheet 2 - p.30] Temperature Measurement
|
static double |
RADIAN_TO_DEGREE
Coefficient to convert an angle value from radians to degrees.
|
device, MAX_I2C_ADDRESS, MIN_I2C_ADDRESS
Constructor and Description |
---|
MPU6050()
Constructor for a new MPU6050 using the default i2c address
and the default value for the DLPF setting.
|
MPU6050(int i2cAddress,
int dlpfCfg,
int smplrtDiv)
Constructor for a new MPU6050 using a specific i2c address
and a specific value for the DLPF setting.
|
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
accelToString(double accel)
Returns the String representation of an acceleration value, in the "x.xxxxxxg" format.
|
static java.lang.String |
angleToString(double angle)
Returns the String representation of an angle, in the "x.xxxx°" format.
|
static java.lang.String |
angularSpeedToString(double angularSpeed)
Returns the String representation of an angular speed value, in the "x.xxxx°/s" format.
|
double[] |
getAccelAccelerations()
Get the last acceleration values, in g, retrieved from the accelerometer,
for the x, y and z axis.
|
double[] |
getAccelAngles()
Get the last angle values, in °, retrieved from the accelerometer,
for the x, y and z axis.
|
double[] |
getFilteredAngles()
Last angle value, in °, calculated from the accelerometer and the gyroscope,
for the x, y and z axis.
|
double[] |
getGyroAngles()
Get the last angles values, in °, retrieved from the gyroscope,
for the x, y and z axis.
|
double[] |
getGyroAngularSpeeds()
Get the last angular speed values, in °/sec, retrieved from the gyroscope,
for the x, y and z axis.
|
double[] |
getGyroAngularSpeedsOffsets()
Get the calculated offsets for the angular speeds from the gyroscope,
for the x, y and z axis.
|
int |
getSampleRate()
Returns the Sample Rate of the MPU6050.
|
double[] |
readScaledAccelerometerValues()
Reads the most recent accelerometer values on MPU6050 for X, Y and Z axis,
and calculates the corresponding accelerations in g, according to the
selected AFS_SEL mode.
|
double[] |
readScaledGyroscopeValues()
Reads the most recent gyroscope values on the MPU6050 for X, Y and Z axis,
and calculates the corresponding angular speeds in degrees/sec,
according to the selected FS_SEL mode.
|
void |
setDLPFConfig(int dlpfConfig)
Sets the value of the DLPF config, according to the datasheet informations.
|
void |
startUpdatingThread()
Starts the thread responsible to update MPU6050 values in background.
|
void |
stopUpdatingThread()
Stops the thread responsible to update MPU6050 values in background.
|
void |
updateRegisterValue(int address,
int value)
This method updates the value of a specific register with a specific value.
|
static java.lang.String |
xyzValuesToString(java.lang.String x,
java.lang.String y,
java.lang.String z)
Returns a String representation of a triplet of values, in the "x: X\t y: Y\t z: Z" format.
|
getDevice, getType, readSignedRegisterValue, readTwoSignedRegsiters, readTwoUnsignedRegisters, readUnsignedRegisterValue, writeUnsignedValueDirectlyToI2CDevice, writeUnsignedValueToRegister
public static final int DEFAULT_MPU6050_ADDRESS
public static final int DEFAULT_DLPF_CFG
public static final int DEFAULT_SMPLRT_DIV
public static final double RADIAN_TO_DEGREE
public static final int MPU6050_REG_ADDR_SMPRT_DIV
This register specifies the divider from the gyroscope output rate used to generate the Sample Rate for the MPU-60X0.
public static final int MPU6050_REG_ADDR_CONFIG
This register configures the external Frame Synchronization (FSYNC) pin sampling and the Digital Low Pass Filter (DLPF) setting for both the gyroscopes and accelerometers.
public static final int MPU6050_REG_ADDR_GYRO_CONFIG
This register is used to trigger gyroscope self-test and configure the gyroscopes’ full scale range
public static final int MPU6050_REG_ADDR_ACCEL_CONFIG
This register is used to trigger accelerometer self test and configure the accelerometer full scale range. This register also configures the Digital High Pass Filter (DHPF).
public static final int MPU6050_REG_ADDR_INT_ENABLE
This register enables interrupt generation by interrupt sources.
public static final int MPU6050_REG_ADDR_PWR_MGMT_1
This register allows the user to configure the power mode and clock source. It also provides a bit for resetting the entire device, and a bit for disabling the temperature sensor.
public static final int MPU6050_REG_ADDR_PWR_MGMT_2
This register allows the user to configure the frequency of wake-ups in Accelerometer Only Low Power Mode. This register also allows the user to put individual axes of the accelerometer and gyroscope into standby mode.
public static final int MPU6050_REG_ADDR_ACCEL_XOUT_H
These registers store the most recent accelerometer measurements.
public static final int MPU6050_REG_ADDR_ACCEL_XOUT_L
These registers store the most recent accelerometer measurements.
public static final int MPU6050_REG_ADDR_ACCEL_YOUT_H
These registers store the most recent accelerometer measurements.
public static final int MPU6050_REG_ADDR_ACCEL_YOUT_L
These registers store the most recent accelerometer measurements.
public static final int MPU6050_REG_ADDR_ACCEL_ZOUT_H
These registers store the most recent accelerometer measurements.
public static final int MPU6050_REG_ADDR_ACCEL_ZOUT_L
These registers store the most recent accelerometer measurements.
public static final int MPU6050_REG_ADDR_TEMP_OUT_H
These registers store the most recent temperature sensor measurement.
MPU6050_REG_ADDR_TEMP_OUT_L
,
Constant Field Valuespublic static final int MPU6050_REG_ADDR_TEMP_OUT_L
These registers store the most recent temperature sensor measurement.
MPU6050_REG_ADDR_TEMP_OUT_H
,
Constant Field Valuespublic static final int MPU6050_REG_ADDR_GYRO_XOUT_H
These registers store the most recent gyroscope measurements.
public static final int MPU6050_REG_ADDR_GYRO_XOUT_L
These registers store the most recent gyroscope measurements.
public static final int MPU6050_REG_ADDR_GYRO_YOUT_H
These registers store the most recent gyroscope measurements.
public static final int MPU6050_REG_ADDR_GYRO_YOUT_L
These registers store the most recent gyroscope measurements.
public static final int MPU6050_REG_ADDR_GYRO_ZOUT_H
These registers store the most recent gyroscope measurements.
public static final int MPU6050_REG_ADDR_GYRO_ZOUT_L
These registers store the most recent gyroscope measurements.
public MPU6050()
DEFAULT_MPU6050_ADDRESS
,
DEFAULT_DLPF_CFG
public MPU6050(int i2cAddress, int dlpfCfg, int smplrtDiv)
i2cAddress
- the i2c address of the MPU6050.dlpfCfg
- the value of the DLPF setting.smplrtDiv
- the value of the sample rate divider.DEFAULT_MPU6050_ADDRESS
,
DEFAULT_DLPF_CFG
public int getSampleRate()
public void setDLPFConfig(int dlpfConfig)
dlpfConfig
- the new DLPF_CFG value. Must be in the [0; 7] range,
where 0 and 7 are used to disable the DLPF.public double[] readScaledAccelerometerValues()
public double[] readScaledGyroscopeValues()
public void startUpdatingThread()
public void stopUpdatingThread() throws java.lang.InterruptedException
java.lang.InterruptedException
- if any thread has interrupted the current thread.
The interrupted status of the current thread is cleared when this exception is thrown.public double[] getAccelAccelerations()
(using the updating thread)
public double[] getAccelAngles()
(using the updating thread)
public double[] getGyroAngularSpeeds()
(using the updating thread)
public double[] getGyroAngles()
(using the updating thread)
public double[] getGyroAngularSpeedsOffsets()
(calculated with the calibration function)
public double[] getFilteredAngles()
(using the updating thread)
public void updateRegisterValue(int address, int value)
address
- the address of the register to update.value
- the new value to set in the register.public static java.lang.String angleToString(double angle)
angle
- the angle to convert.public static java.lang.String accelToString(double accel)
accel
- the acceleration to convert.public static java.lang.String angularSpeedToString(double angularSpeed)
angularSpeed
- the angular speed to convert.public static java.lang.String xyzValuesToString(java.lang.String x, java.lang.String y, java.lang.String z)
x
- the first value of the triplet.y
- the second value of the triplet.z
- the thirs value of the triplet.