fusion_hat.modules.mpu6050 module
This code is based on Martijn’s(martijn@mrtijn.nl) project mpu6050. Follow the MIT protocol.
https://github.com/m-rtijn/mpu6050
- class fusion_hat.modules.mpu6050.MPU6050(address=104, bus=1)[source]
Bases:
object- I2C_ADDRESS = 104
- GRAVITIY_MS2 = 9.80665
- ACCEL_SCALE_MODIFIER_2G = 16384.0
- ACCEL_SCALE_MODIFIER_4G = 8192.0
- ACCEL_SCALE_MODIFIER_8G = 4096.0
- ACCEL_SCALE_MODIFIER_16G = 2048.0
- GYRO_SCALE_MODIFIER_250DEG = 131.0
- GYRO_SCALE_MODIFIER_500DEG = 65.5
- GYRO_SCALE_MODIFIER_1000DEG = 32.8
- GYRO_SCALE_MODIFIER_2000DEG = 16.4
- ACCEL_RANGE_2G = 0
- ACCEL_RANGE_4G = 8
- ACCEL_RANGE_8G = 16
- ACCEL_RANGE_16G = 24
- GYRO_RANGE_250DEG = 0
- GYRO_RANGE_500DEG = 8
- GYRO_RANGE_1000DEG = 16
- GYRO_RANGE_2000DEG = 24
- FILTER_BW_256 = 0
- FILTER_BW_188 = 1
- FILTER_BW_98 = 2
- FILTER_BW_42 = 3
- FILTER_BW_20 = 4
- FILTER_BW_10 = 5
- FILTER_BW_5 = 6
- PWR_MGMT_1 = 107
- PWR_MGMT_2 = 108
- ACCEL_XOUT0 = 59
- ACCEL_YOUT0 = 61
- ACCEL_ZOUT0 = 63
- TEMP_OUT0 = 65
- GYRO_XOUT0 = 67
- GYRO_YOUT0 = 69
- GYRO_ZOUT0 = 71
- ACCEL_CONFIG = 28
- GYRO_CONFIG = 27
- MPU_CONFIG = 26
- REG_INT_PIN_CFG = 55
- REG_USER_CTRL = 106
- REG_WHO_AM_I = 117
- address = None
- bus = None
- read_i2c_word(register)[source]
Read two i2c registers and combine them.
register – the first register to read from. Returns the combined read results.
- get_temp()[source]
Reads the temperature from the onboard temperature sensor of the MPU-6050.
Returns the temperature in degrees Celcius.
- set_accel_range(accel_range)[source]
Sets the range of the accelerometer to range.
accel_range – the range to set the accelerometer to. Using a pre-defined range is advised.
- read_accel_range(raw=False)[source]
Reads the range the accelerometer is set to.
If raw is True, it will return the raw value from the ACCEL_CONFIG register If raw is False, it will return an integer: -1, 2, 4, 8 or 16. When it returns -1 something went wrong.
- get_accel_data(g=False)[source]
Gets and returns the X, Y and Z values from the accelerometer.
If g is True, it will return the data in g If g is False, it will return the data in m/s^2 Returns a dictionary with the measurement results.
- set_gyro_range(gyro_range)[source]
Sets the range of the gyroscope to range.
gyro_range – the range to set the gyroscope to. Using a pre-defined range is advised.
- read_gyro_range(raw=False)[source]
Reads the range the gyroscope is set to.
If raw is True, it will return the raw value from the GYRO_CONFIG register. If raw is False, it will return 250, 500, 1000, 2000 or -1. If the returned value is equal to -1 something went wrong.