MPU-9150 accelerometer/magnetometer/gyroscope¶
Device driver interface for the MPU-9150.
This driver provides [S]ensor [A]ctuator [U]ber [L]ayer capabilities.
-
MPU9150_MIN_SAMPLE_RATE
¶ 1
(4)
-
MPU9150_MAX_SAMPLE_RATE
¶ 1
(1000)
-
MPU9150_DEFAULT_SAMPLE_RATE
¶ 1
(50)
-
MPU9150_MIN_COMP_SMPL_RATE
¶ 1
(1)
-
MPU9150_MAX_COMP_SMPL_RATE
¶ 1
(100)
-
MPU9150_PWR_WAKEUP
¶ 1
(0x00)
-
MPU9150_PWR_PLL
¶ 1
(0x01)
-
MPU9150_PWR_RESET
¶ 1
(0x80)
-
MPU9150_PWR_GYRO
¶ 1
(0x07)
-
MPU9150_PWR_ACCEL
¶ 1
(0x38)
-
MPU9150_COMP_MODE_SLEEP_US
¶ 1
(1000)
-
MPU9150_BYPASS_SLEEP_US
¶ 1
(3000)
-
MPU9150_PWR_CHANGE_SLEEP_US
¶ 1
(50000)
-
MPU9150_RESET_SLEEP_US
¶ 1
(100000)
-
MPU9150_COMP_POWER_DOWN
¶ 1
(0x00)
-
MPU9150_COMP_SINGLE_MEASURE
¶ 1
(0x01)
-
MPU9150_COMP_SELF_TEST
¶ 1
(0x08)
-
MPU9150_COMP_FUSE_ROM
¶ 1
(0x0F)
-
MPU9150_COMP_WHOAMI_ANSWER
¶ 1
(0x48)
-
enum
mpu9150_pwr_t
¶ - MPU9150_SENSOR_PWR_OFF
= 0x00
- MPU9150_SENSOR_PWR_ON
= 0x01
- MPU9150_SENSOR_PWR_OFF
-
enum
mpu9150_hw_addr_t
¶ - MPU9150_HW_ADDR_HEX_68
= 0x68
- MPU9150_HW_ADDR_HEX_69
= 0x69
- MPU9150_HW_ADDR_HEX_68
-
enum
mpu9150_comp_addr_t
¶ - MPU9150_COMP_ADDR_HEX_0C
= 0x0C
- MPU9150_COMP_ADDR_HEX_0D
= 0x0D
- MPU9150_COMP_ADDR_HEX_0E
= 0x0E
- MPU9150_COMP_ADDR_HEX_0F
= 0x0F
- MPU9150_COMP_ADDR_HEX_0C
-
enum
mpu9150_gyro_ranges_t
¶ - MPU9150_GYRO_FSR_250DPS
= 0x00
- MPU9150_GYRO_FSR_500DPS
= 0x01
- MPU9150_GYRO_FSR_1000DPS
= 0x02
- MPU9150_GYRO_FSR_2000DPS
= 0x03
- MPU9150_GYRO_FSR_250DPS
-
enum
mpu9150_accel_ranges_t
¶ - MPU9150_ACCEL_FSR_2G
= 0x00
- MPU9150_ACCEL_FSR_4G
= 0x01
- MPU9150_ACCEL_FSR_8G
= 0x02
- MPU9150_ACCEL_FSR_16G
= 0x03
- MPU9150_ACCEL_FSR_2G
-
enum
mpu9150_lpf_t
¶ - MPU9150_FILTER_188HZ
= 0x01
- MPU9150_FILTER_98HZ
= 0x02
- MPU9150_FILTER_42HZ
= 0x03
- MPU9150_FILTER_20HZ
= 0x04
- MPU9150_FILTER_10HZ
= 0x05
- MPU9150_FILTER_5HZ
= 0x06
- MPU9150_FILTER_188HZ
-
int
mpu9150_init
(mpu9150_t * dev, const mpu9150_params_t * params)¶ Initialize the given MPU9150 device.
Parameters
dev: Initialized device descriptor of MPU9150 device params: Initialization parameters Return values
- 0 on success
- -1 if given I2C is not enabled in board config
-
int
mpu9150_set_accel_power
(mpu9150_t * dev,mpu9150.h::mpu9150_pwr_t
pwr_conf)¶ Enable or disable accelerometer power.
Parameters
dev: Device descriptor of MPU9150 device pwr_conf: Target power setting: PWR_ON or PWR_OFF Return values
- 0 on success
- -1 if given I2C is not enabled in board config
-
int
mpu9150_set_gyro_power
(mpu9150_t * dev,mpu9150.h::mpu9150_pwr_t
pwr_conf)¶ Enable or disable gyroscope power.
Parameters
dev: Device descriptor of MPU9150 device pwr_conf: Target power setting: PWR_ON or PWR_OFF Return values
- 0 on success
- -1 if given I2C is not enabled in board config
-
int
mpu9150_set_compass_power
(mpu9150_t * dev,mpu9150.h::mpu9150_pwr_t
pwr_conf)¶ Enable or disable compass power.
Parameters
dev: Device descriptor of MPU9150 device pwr_conf: Target power setting: PWR_ON or PWR_OFF Return values
- 0 on success
- -1 if given I2C is not enabled in board config
-
int
mpu9150_read_gyro
(const mpu9150_t * dev, mpu9150_results_t * output)¶ Read angular speed values from the given MPU9150 device, returned in dps.
The raw gyroscope data is read from the sensor and normalized with respect to the configured gyroscope full-scale range.
Parameters
dev: Device descriptor of MPU9150 device to read from output: Result vector in dps per axis Return values
- 0 on success
- -1 if device’s I2C is not enabled in board config
- -2 if gyro full-scale range is configured wrong
-
int
mpu9150_read_accel
(const mpu9150_t * dev, mpu9150_results_t * output)¶ Read acceleration values from the given MPU9150 device, returned in mG.
The raw acceleration data is read from the sensor and normalized with respect to the configured accelerometer full-scale range.
Parameters
dev: Device descriptor of MPU9150 device to read from output: Result vector in mG per axis Return values
- 0 on success
- -1 if device’s I2C is not enabled in board config
- -2 if accel full-scale range is configured wrong
-
int
mpu9150_read_compass
(const mpu9150_t * dev, mpu9150_results_t * output)¶ Read magnetic field values from the given MPU9150 device, returned in mikroT.
The raw compass data is read from the sensor and normalized with respect to the compass full-scale range (which can not be configured).
Parameters
dev: Device descriptor of MPU9150 device to read from output: Result vector in mikroT per axis Return values
- 0 on success
- -1 if device’s I2C is not enabled in board config
-
int
mpu9150_read_temperature
(const mpu9150_t * dev, int32_t * output)¶ Read temperature value from the given MPU9150 device, returned in m°C.
Note
The measured temperature is slightly higher than the real room temperature. Tests showed that the offset varied around 2-3 °C (but no warranties here).
Parameters
dev: Device descriptor of MPU9150 device to read from output: Temperature in m°C Return values
- 0 on success
- -1 if device’s I2C is not enabled in board config
-
int
mpu9150_set_gyro_fsr
(mpu9150_t * dev,mpu9150.h::mpu9150_gyro_ranges_t
fsr)¶ Set the full-scale range for raw gyroscope data.
Parameters
dev: Device descriptor of MPU9150 device fsr: Target full-scale range Return values
- 0 on success
- -1 if device’s I2C is not enabled in board config
- -2 if given full-scale target value is not valid
-
int
mpu9150_set_accel_fsr
(mpu9150_t * dev,mpu9150.h::mpu9150_accel_ranges_t
fsr)¶ Set the full-scale range for raw accelerometer data.
Parameters
dev: Device descriptor of MPU9150 device fsr: Target full-scale range Return values
- 0 on success
- -1 if device’s I2C is not enabled in board config
- -2 if given full-scale target value is not valid
-
int
mpu9150_set_sample_rate
(mpu9150_t * dev, uint16_t rate)¶ Set the rate at which the gyroscope and accelerometer data is sampled.
Sample rate can be chosen between 4 Hz and 1kHz. The actual set value might slightly differ. If necessary, check the actual set value in the device’s config member afterwards.
Parameters
dev: Device descriptor of MPU9150 device rate: Target sample rate in Hz Return values
- 0 on success
- -1 if device’s I2C is not enabled in board config
- -2 if given target sample rate is not valid
-
int
mpu9150_set_compass_sample_rate
(mpu9150_t * dev, uint8_t rate)¶ Set the rate at which the compass data is sampled.
Sample rate can be chosen between 1 Hz and 100 Hz but has to be a fraction of the configured accel/gyro sample rate. The actual set value might slightly differ. If necessary, check the actual set value in the device’s config member afterwards.
Parameters
dev: Device descriptor of MPU9150 device rate: Target sample rate in Hz Return values
- 0 on success
- -1 if device’s I2C is not enabled in board config
- -2 if given target sample rate is not valid
-
struct
mpu9150_results_t
¶ MPU-9150 result vector struct.
-
int16_t
x_axis
¶ X-Axis measurement result.
-
int16_t
y_axis
¶ Y-Axis measurement result.
-
int16_t
z_axis
¶ Z-Axis measurement result.
-
int16_t
-
struct
mpu9150_status_t
¶ Configuration struct for the MPU-9150 sensor.
-
mpu9150.h::mpu9150_pwr_t
accel_pwr
¶ Accel power status (on/off)
-
mpu9150.h::mpu9150_pwr_t
gyro_pwr
¶ Gyro power status (on/off)
-
mpu9150.h::mpu9150_pwr_t
compass_pwr
¶ Compass power status (on/off)
-
mpu9150.h::mpu9150_gyro_ranges_t
gyro_fsr
¶ Configured gyro full-scale range.
-
mpu9150.h::mpu9150_accel_ranges_t
accel_fsr
¶ Configured accel full-scale range.
-
uint16_t
sample_rate
¶ Configured sample rate for accel and gyro.
-
uint8_t
compass_sample_rate
¶ Configured compass sample rate.
-
uint8_t
compass_x_adj
¶ Compass X-Axis sensitivity adjustment value.
-
uint8_t
compass_y_adj
¶ Compass Y-Axis sensitivity adjustment value.
-
uint8_t
compass_z_adj
¶ Compass Z-Axis sensitivity adjustment value.
-
-
struct
mpu9150_params_t
¶ Device initialization parameters.
-
i2c.h::i2c_t
i2c
¶ I2C device which is used.
-
uint8_t
addr
¶ Hardware address of the MPU-9150.
-
uint8_t
comp_addr
¶ Address of the MPU-9150s compass.
-
uint16_t
sample_rate
¶ Sample rate.
-
-
struct
mpu9150_t
¶ Device descriptor for the MPU-9150 sensor.
-
mpu9150_params_t
params
¶ Device initialization parameters.
-
mpu9150_status_t
conf
¶ Device configuration.
-
mpu9150_params_t