.. module:: MPU6050 ************** MPU6050 Module ************** .. _datasheet: https://invensense.tdk.com/wp-content/uploads/2015/02/MPU-6000-Datasheet1.pdf https://invensense.tdk.com/wp-content/uploads/2015/02/MPU-6000-Register-Map1.pdf http://www.i2cdevlib.com/devices/mpu6050#registers This module contains the Zerynth driver for MPU6050 digital motion sensor. The MPU6050 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. Additional features include an embedded temperature sensor. =============== MPU6050 class =============== .. class:: MPU6050(drvname, addr=0x68, clk=400000) Creates an intance of the MPU6050 class. :param drvname: I2C Bus used '( I2C0, ... )' :param addr: Slave address, default 0x68 :param clk: Clock speed, default 400kHz Temperature, accelerometer and gyroscope value can be easily obtained from the sensor: :: from invensense.mpu6050 import mpu6050 ... mpu = mpu6050.MPU6050(I2C0) temp, acc, gyro = mpu.get_values() .. method:: set_dlpf_mode(dlpf) **Parameters**: **dlpf**: is the DLPF mode to set. Values range accepted are 0-7 (see datasheet). Set the DLPF mode. .. method:: set_dhpf_mode(dhpf) **Parameters**: **dhpf**: is the DHPF mode to set. Values accepted are 0, 1, 2, 3, 4 or 7. ======== ===================== dhpf DHPF mode ======== ===================== 0 Reset 1 On @ 5 Hz 2 On @ 2.5 Hz 3 On @ 1.25 Hz 4 On @ 0.63 Hz 7 Hold ======== ===================== Set the DHPF mode. .. method:: get_clock_source() Return the clock source the sensor is set to. .. method:: set_clock_source(clksel) **Parameters**: **clksel**: is the clock source to set. Values accepted are 0, 1, 2, 3, 4, 5 or 7. ======== ===================== clksel Clock source ======== ===================== 0 Internal 8MHz oscillator 1 PLL with X axis gyroscope reference 2 PLL with Y axis gyroscope reference 3 PLL with Z axis gyroscope reference 4 PLL with external 32.768kHz reference 5 PLL with external 19.2MHz reference 6 Reserved 7 Stops the clock and keeps the timing generator ======== ===================== Set the clock source. .. method:: get_temp() Return the temperature in degrees Celsius. .. method:: set_accel_fullscale(full_scale) :param full_scale: is the full-scale range to set the accelerometer to. Possible values are 2, 4, 8 or 16. Set the full-scale range of the accelerometer. .. method:: get_accel_fullscale() Return the full-scale value the accelerometer is set to. When something went wrong, it returns -1. .. method:: get_accel_values(g = False) :param g: is the format of accelerometer values. If g = False is m/s^2, otherwise is g. Default value is False. Return the X, Y and Z accelerometer values in a dictionary. .. method:: set_gyro_fullscale(full_scale) :param full_scale: is the full-scale range to set the gyroscope to. Values accepted: 250, 500, 1000 or 2000. Set the full-scale range of the gyroscope. .. method:: get_gyro_fullscale() Return the full-scale value the gyroscope is set to. When something went wrong, it returns -1. .. method:: get_gyro_values() Return the X, Y and Z gyroscope values in a dictionary. .. method:: get_values(g = False) :param g: is the format of accelerometer values. If g = False is m/s^2, otherwise is g. Default value is False. Return the values of temperature, gyroscope and accelerometer in a list [temp, accel, gyro]. .. method:: is_motion_detected() Return 1 if a motion has been detected, otherwise 0. .. method:: is_data_ready() Return 1 if data is ready, otherwise 0. .. method:: setup_motion() Set the configuration for motion detection.