MPU-6050¶
-
class
electronics.devices.mpu6050.
MPU6050I2C
(bus, address=104)¶ Interface to a MPU-6050 Six-Axis (Gyro + Accelerometer) MEMS MotionTracking™ Device
Usage: - Use set_range() to specify the measurement range of to accel and gyro sensor
- Use wakeup() to start the MEMS units in the sensor or use instance of this class as a new context
- Use temperature(), acceleration() and angular_rate() to read the sensor values
Example: >>> sensor = MPU6050I2C(gw) >>> sensor.set_range(accel=MPU6050I2C.RANGE_ACCEL_2G, gyro=MPU6050I2C.RANGE_GYRO_250DEG) >>> >>> # Read a value >>> sensor.wakeup() >>> sensor.temperature() 37.29 >>> sensor.sleep() >>> >>> # Read a value using a context manager instead of wakeup() and sleep() >>> with sensor: ... sensor.temperature() 38.8
-
acceleration
()¶ Return the acceleration in G’s
Returns: Acceleration for every axis as a tuple Example: >>> sensor = MPU6050I2C(gw) >>> sensor.wakeup() >>> sensor.acceleration() (0.6279296875, 0.87890625, 1.1298828125)
-
angular_rate
()¶ Return the angular rate for every axis in degree/second.
Returns: Angular rate for every axis as a tuple Example: >>> sensor = MPU6050I2C(gw) >>> sensor.wakeup() >>> sensor.angular_rate() (1.380859375, 1.6318359375, 1.8828125)
-
set_range
(accel=1, gyro=1)¶ Set the measurement range for the accel and gyro MEMS. Higher range means less resolution.
Parameters: - accel – a RANGE_ACCEL_* constant
- gyro – a RANGE_GYRO_* constant
Example: sensor = MPU6050I2C(gateway_class_instance) sensor.set_range( accel=MPU6050I2C.RANGE_ACCEL_2G, gyro=MPU6050I2C.RANGE_GYRO_250DEG )
-
set_slave_bus_bypass
(enable)¶ Put the aux i2c bus on the MPU-6050 in bypass mode, thus connecting it to the main i2c bus directly
Dont forget to use wakeup() or else the slave bus is unavailable :param enable: :return:
-
sleep
()¶ Put the sensor back to sleep.
-
temperature
()¶ Read the value for the internal temperature sensor.
Returns: Temperature in degree celcius as float Example: >>> sensor = MPU6050I2C(gw) >>> sensor.wakeup() >>> sensor.temperature() 49.38
-
wakeup
()¶ Wake the sensor from sleep.