From 087a70fdcc28ec1338053d741c87d8ef21a886b2 Mon Sep 17 00:00:00 2001 From: SquirtleSquadLeader <112285567+SquirtleSquadLeader@users.noreply.github.com> Date: Sun, 30 Oct 2022 18:38:21 -0400 Subject: [PATCH 01/16] Removed test script at bottome ... maybe this is it? --- adafruit_mpu6050.py | 245 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 213 insertions(+), 32 deletions(-) diff --git a/adafruit_mpu6050.py b/adafruit_mpu6050.py index 291da94..9bf5bfe 100644 --- a/adafruit_mpu6050.py +++ b/adafruit_mpu6050.py @@ -8,6 +8,10 @@ CircuitPython helper library for the MPU6050 6-DoF Accelerometer and Gyroscope +WARNING: Reference(s) to "Master" / "Slave" used only to match original documentation + by the manufacturer, TDK Invnesense. Please feel free to rename these to + something more agreeable like Leader/Follower if you feel so inclined. + * Author(s): Bryan Siepert @@ -29,6 +33,19 @@ * Adafruit's Register library: https://github.com/adafruit/Adafruit_CircuitPython_Register + +* Registers added without seeing concise documenation on their + implementation. Please use at your own risk until further + development allows for safe usage. + + ** Datasheets, Register Maps, etc... ** + +* Datasheet: https://invensense.tdk.com/wp-content/uploads/2015/02/MPU-6000-Datasheet1.pdf + +* Register Map: https://invensense.tdk.com/wp-content/uploads/2015/02/MPU-6000-Register-Map1.pdf + +* Offet Register Document: https://www.digikey.com/en/pdf/i/invensense/mpu-hardware-offset-registers + """ # imports @@ -50,29 +67,175 @@ except ImportError: pass -_MPU6050_DEFAULT_ADDRESS = 0x68 # MPU6050 default i2c address w/ AD0 low -_MPU6050_DEVICE_ID = 0x68 # The correct MPU6050_WHO_AM_I value - -_MPU6050_SELF_TEST_X = 0x0D # Self test factory calibrated values register -_MPU6050_SELF_TEST_Y = 0x0E # Self test factory calibrated values register -_MPU6050_SELF_TEST_Z = 0x0F # Self test factory calibrated values register -_MPU6050_SELF_TEST_A = 0x10 # Self test factory calibrated values register -_MPU6050_SMPLRT_DIV = 0x19 # sample rate divisor register -_MPU6050_CONFIG = 0x1A # General configuration register -_MPU6050_GYRO_CONFIG = 0x1B # Gyro specfic configuration register -_MPU6050_ACCEL_CONFIG = 0x1C # Accelerometer specific configration register -_MPU6050_INT_PIN_CONFIG = 0x37 # Interrupt pin configuration register -_MPU6050_ACCEL_OUT = 0x3B # base address for sensor data reads -_MPU6050_TEMP_OUT = 0x41 # Temperature data high byte register -_MPU6050_GYRO_OUT = 0x43 # base address for sensor data reads -_MPU6050_SIG_PATH_RESET = 0x68 # register to reset sensor signal paths -_MPU6050_USER_CTRL = 0x6A # FIFO and I2C Master control register -_MPU6050_PWR_MGMT_1 = 0x6B # Primary power/sleep control register -_MPU6050_PWR_MGMT_2 = 0x6C # Secondary power/sleep control register -_MPU6050_WHO_AM_I = 0x75 # Divice ID register +_MPU6050_DEVICE_ID_AD0_LO = 0x68 +_MPU6050_DEVICE_ID_AD0_HI = 0x69 -STANDARD_GRAVITY = 9.80665 +""" +_MPU6050_XG_OFFS_TC = 0x00 +_MPU6050_YG_OFFS_TC = 0x01 +_MPU6050_ZG_OFFS_TC = 0x02 # FURTHER DEVELOPMENT NEEDED TO ENABLE THESE +_MPU6050_FINE_GAIN = 0x03 +_MPU6050_Y_FINE_GAIN = 0x04 +_MPU6050_Z_FINE_GAIN = 0x05 +""" + +# Accelerometer Offset Registers +_MPU6050_XA_OFFS_USRH = 0x06 +_MPU6050_XA_OFFS_USRL = 0x07 +_MPU6050_YA_OFFS_USRH = 0x08 +_MPU6050_YA_OFFS_USRL = 0x09 +_MPU6050_ZA_OFFS_USRH = 0x0A +_MPU6050_ZA_OFFS_USRL = 0x0B + +# Self Test Registers +_MPU6050_SELF_TEST_X = 0x0D +_MPU6050_SELF_TEST_Y = 0x0E +_MPU6050_SELF_TEST_Z = 0x0F +_MPU6050_SELF_TEST_A = 0x10 + +# Gyroscope Offset Registers +_MPU6050_XG_OFFS_USRH = 0x13 +_MPU6050_XG_OFFS_USRL = 0x14 +_MPU6050_YG_OFFS_USRH = 0x15 +_MPU6050_YG_OFFS_USRL = 0x16 +_MPU6050_ZG_OFFS_USRH = 0x17 +_MPU6050_ZG_OFFS_USRL = 0x18 + +# Configuration Registers +_MPU6050_SMPLRT_DIV = 0x19 +_MPU6050_CONFIG = 0x1A +_MPU6050_GYRO_CONFIG = 0x1B +_MPU6050_ACCEL_CONFIG = 0x1C + +""" +# Freefall +_MPU6050_FF_THR = 0x1D # FURTHER DEVELOPMENT NEEDED TO ENABLE THESE +_MPU6050_FF_DUR = 0x1E + +# Motion Detection +_MPU6050_MOT_DET_THRSHLD = 0x1F +_MPU6050_MOT_DET_DURATION = 0x20 +_MPU6050_ZRMOT_THR = 0x21 +_MPU6050_ZRMOT_DUR = 0x22 +""" +# FIFO Enable +_MPU6050_FIFO_EN = 0x23 + +""" +# I2C Master/Slave Bus Control +_MPU6050_I2C_MST_CTRL = 0x24 # FURTHER DEVELOPMENT NEEDED TO ENABLE THESE +_MPU6050_I2C_SLV0_ADDR = 0x25 +_MPU6050_I2C_SLV0_REG = 0x26 +_MPU6050_I2C_SLV0_CTRL = 0x27 +_MPU6050_I2C_SLV1_ADDR = 0x28 +_MPU6050_I2C_SLV1_REG = 0x29 +_MPU6050_I2C_SLV1_CTRL = 0x2A +_MPU6050_I2C_SLV2_ADDR = 0x2B +_MPU6050_I2C_SLV2_REG = 0x2C +_MPU6050_I2C_SLV2_CTRL = 0x2D +_MPU6050_I2C_SLV3_ADDR = 0x2E +_MPU6050_I2C_SLV3_REG = 0x2F +_MPU6050_I2C_SLV3_CTRL = 0x30 +_MPU6050_I2C_SLV4_ADDR = 0x31 +_MPU6050_I2C_SLV4_REG = 0x32 +_MPU6050_I2C_SLV4_DO = 0x33 +_MPU6050_I2C_SLV4_CTRL = 0x34 +_MPU6050_I2C_SLV4_DI = 0x35 +_MPU6050_I2C_MST_STATUS = 0x36 +""" + +# Interrupt Configuration +_MPU6050_INT_PIN_CFG = 0x37 +_MPU6050_INT_ENABLE = 0x38 + +# _DMP_INT_STATUS = 0x39 +_MPU6050_INT_STATUS = 0x3A + +# Sensor Outputs +_MPU6050_ACCEL_XOUT_H = 0x3B +_MPU6050_ACCEL_XOUT_L = 0x3C +_MPU6050_ACCEL_YOUT_H = 0x3D +_MPU6050_ACCEL_YOUT_L = 0x3E +_MPU6050_ACCEL_ZOUT_H = 0x3F +_MPU6050_ACCEL_ZOUT_L = 0x40 +_MPU6050_TEMP_OUT_H = 0x41 +_MPU6050_TEMP_OUT_L = 0x42 +_MPU6050_GYRO_XOUT_H = 0x43 +_MPU6050_GYRO_XOUT_L = 0x44 +_MPU6050_GYRO_YOUT_H = 0x45 +_MPU6050_GYRO_YOUT_L = 0x46 +_MPU6050_GYRO_ZOUT_H = 0x47 +_MPU6050_GYRO_ZOUT_L = 0x48 + +""" +# External Sensor Data More development needed to enable these +_MPU6050_EXT_SENS_DATA_00 = 0x49 +_MPU6050_EXT_SENS_DATA_01 = 0x4A +_MPU6050_EXT_SENS_DATA_02 = 0x4B +_MPU6050_EXT_SENS_DATA_03 = 0x4C +_MPU6050_EXT_SENS_DATA_04 = 0x4D +_MPU6050_EXT_SENS_DATA_05 = 0x4E +_MPU6050_EXT_SENS_DATA_06 = 0x4F +_MPU6050_EXT_SENS_DATA_07 = 0x50 +_MPU6050_EXT_SENS_DATA_08 = 0x51 +_MPU6050_EXT_SENS_DATA_09 = 0x52 +_MPU6050_EXT_SENS_DATA_10 = 0x53 +_MPU6050_EXT_SENS_DATA_11 = 0x54 +_MPU6050_EXT_SENS_DATA_12 = 0x55 +_MPU6050_EXT_SENS_DATA_13 = 0x56 +_MPU6050_EXT_SENS_DATA_14 = 0x57 +_MPU6050_EXT_SENS_DATA_15 = 0x58 +_MPU6050_EXT_SENS_DATA_16 = 0x59 +_MPU6050_EXT_SENS_DATA_17 = 0x5A +_MPU6050_EXT_SENS_DATA_18 = 0x5B +_MPU6050_EXT_SENS_DATA_19 = 0x5C +_MPU6050_EXT_SENS_DATA_20 = 0x5D +_MPU6050_EXT_SENS_DATA_21 = 0x5E +_MPU6050_EXT_SENS_DATA_22 = 0x5F +_MPU6050_EXT_SENS_DATA_23 = 0x60 + +# Motion Detect Status +# _MPU6050_MOT_DETECT_STATUS = 0x61 + + +# I2C Slave DO +_MPU6050_I2C_SLV0_DO = 0x63 +_MPU6050_I2C_SLV1_DO = 0x64 +_MPU6050_I2C_SLV2_DO = 0x65 +_MPU6050_I2C_SLV3_DO = 0x66 + +# I2C Master Delay Control +_MPU6050_I2C_MT_DELAY_CTRL = 0x67 +""" + +# Resets / Enables +_MPU6050_SIGNAL_PATH_RESET = 0x68 + +# _MPU6050_MOT_DETECT_CTRL = 0x69 + +_MPU6050_USER_CTRL = 0x6A +_MPU6050_PWR_MGMT_1 = 0x6B +_MPU6050_PWR_MGMT_2 = 0x6C + +""" +# DMP +_MPU6050_BANK_SEL = const(0x6D) +_MPU6050_MEM_START_ADDR = const(0x6E) +_MPU6050_MEM_R_W = const(0x6F) # FURTHER DEVELOPMENT NEEDED TO ENABLE THESE +_MPU6050_DMP_CFG_1 = const(0x70) +_MPU6050_DMP_CFG_2 = const(0x71) +""" + +# FIFO Buffer Count +_MPU6050_FIFO_COUNTH = 0x72 +_MPU6050_FIFO_COUNTL = 0x73 +_MPU6050_FIFO_R_W = 0x74 + +# Who am I? "To be... or not to be? That -is- the question" +_MPU6050_WHO_AM_I = 0x75 + +STANDARD_GRAVITY = 9.80665 class Range: # pylint: disable=too-few-public-methods """Allowed values for `accelerometer_range`. @@ -178,12 +341,29 @@ class MPU6050: """ - def __init__(self, i2c_bus: I2C, address: int = _MPU6050_DEFAULT_ADDRESS) -> None: + def __init__(self, i2c_bus: I2C, address) -> None: + + # Check user input for correctness correctness + if address is not _MPU6050_DEVICE_ID_AD0_LO and address is not _MPU6050_DEVICE_ID_AD0_HI: + raise RuntimeError("MPU6050 address passed in is incorrect. Expecting " + "0x68 OR 0x69 (104 OR 105). See Data Sheet / Register Map for details") + + # Verify i2c_bus is not already locked to prevent a hang + i2c_bus.unlock() + + # Attempt to establish an I2CDevice object self.i2c_device = i2c_device.I2CDevice(i2c_bus, address) - - if self._device_id != _MPU6050_DEVICE_ID: - raise RuntimeError("Failed to find MPU6050 - check your wiring!") - + + # Verify WHO_AM_I (register 0x75) responds with value of 104, regardless of AD0 state. + # This double checks the device responding is a MPU6050 + if self._who_am_i[0][0] is _MPU6050_DEVICE_ID_AD0_LO: + print("Communication to MPU6050 @", address, " confirmed.") + else: + raise RuntimeError("MPU6050 @ ", address, " invalid response from \"Who Am I\" " + "(104 0x68) not found. Possible a device, other than MPU6050, responding " + "from the same address. Check for I2C address conflicts on the same " + "I2C bus and try again.") + self.reset() self._sample_rate_divisor = 0 @@ -210,17 +390,18 @@ def reset(self) -> None: _device_id = ROUnaryStruct(_MPU6050_WHO_AM_I, ">B") _reset = RWBit(_MPU6050_PWR_MGMT_1, 7, 1) - _signal_path_reset = RWBits(3, _MPU6050_SIG_PATH_RESET, 3) + _signal_path_reset = RWBits(3, _MPU6050_SIGNAL_PATH_RESET, 3) _gyro_range = RWBits(2, _MPU6050_GYRO_CONFIG, 3) _accel_range = RWBits(2, _MPU6050_ACCEL_CONFIG, 3) _filter_bandwidth = RWBits(2, _MPU6050_CONFIG, 3) - _raw_accel_data = StructArray(_MPU6050_ACCEL_OUT, ">h", 3) - _raw_gyro_data = StructArray(_MPU6050_GYRO_OUT, ">h", 3) - _raw_temp_data = ROUnaryStruct(_MPU6050_TEMP_OUT, ">h") - + _raw_accel_data = StructArray(_MPU6050_ACCEL_XOUT_H, ">h", 3) + _raw_gyro_data = StructArray(_MPU6050_GYRO_XOUT_H, ">h", 3) + _raw_temp_data = ROUnaryStruct(_MPU6050_TEMP_OUT_H, ">h") + + _who_am_i = StructArray(_MPU6050_WHO_AM_I,'B',1) _cycle = RWBit(_MPU6050_PWR_MGMT_1, 5) _cycle_rate = RWBits(2, _MPU6050_PWR_MGMT_2, 6, 1) @@ -346,4 +527,4 @@ def cycle_rate(self, value: int) -> None: if (value < 0) or (value > 3): raise ValueError("cycle_rate must be a Rate") self._cycle_rate = value - sleep(0.01) + sleep(0.01) \ No newline at end of file From dd037a9e80b4432d2ba9206cb14a4962a0491618 Mon Sep 17 00:00:00 2001 From: SquirtleSquadLeader <112285567+SquirtleSquadLeader@users.noreply.github.com> Date: Fri, 4 Nov 2022 20:06:29 -0400 Subject: [PATCH 02/16] Integrated Clock Source selection 1) Added Clksel class to store options similar to previous author 2) Changed Register name to match Register Map documentation 3) Added Getter/Setter property to negotiate transactions 4) Changed MPU6050 __init()__ to reflect the new syntax to match the others 5) Pre-written te Third time is a charm --- adafruit_mpu6050.py | 321 +++++++++++++++----------------------------- 1 file changed, 111 insertions(+), 210 deletions(-) diff --git a/adafruit_mpu6050.py b/adafruit_mpu6050.py index 9bf5bfe..1ed275f 100644 --- a/adafruit_mpu6050.py +++ b/adafruit_mpu6050.py @@ -8,10 +8,6 @@ CircuitPython helper library for the MPU6050 6-DoF Accelerometer and Gyroscope -WARNING: Reference(s) to "Master" / "Slave" used only to match original documentation - by the manufacturer, TDK Invnesense. Please feel free to rename these to - something more agreeable like Leader/Follower if you feel so inclined. - * Author(s): Bryan Siepert @@ -33,19 +29,11 @@ * Adafruit's Register library: https://github.com/adafruit/Adafruit_CircuitPython_Register - -* Registers added without seeing concise documenation on their - implementation. Please use at your own risk until further - development allows for safe usage. - - ** Datasheets, Register Maps, etc... ** - -* Datasheet: https://invensense.tdk.com/wp-content/uploads/2015/02/MPU-6000-Datasheet1.pdf - -* Register Map: https://invensense.tdk.com/wp-content/uploads/2015/02/MPU-6000-Register-Map1.pdf - -* Offet Register Document: https://www.digikey.com/en/pdf/i/invensense/mpu-hardware-offset-registers + Change log: + 1) Added Clksel class to store options similar to previous author + 2) Changed Register name to match Register Map documentation + 3) Added Getter/Setter property to negotiate transactions """ # imports @@ -67,175 +55,52 @@ except ImportError: pass -_MPU6050_DEVICE_ID_AD0_LO = 0x68 -_MPU6050_DEVICE_ID_AD0_HI = 0x69 - -""" -_MPU6050_XG_OFFS_TC = 0x00 -_MPU6050_YG_OFFS_TC = 0x01 -_MPU6050_ZG_OFFS_TC = 0x02 # FURTHER DEVELOPMENT NEEDED TO ENABLE THESE -_MPU6050_FINE_GAIN = 0x03 -_MPU6050_Y_FINE_GAIN = 0x04 -_MPU6050_Z_FINE_GAIN = 0x05 -""" - -# Accelerometer Offset Registers -_MPU6050_XA_OFFS_USRH = 0x06 -_MPU6050_XA_OFFS_USRL = 0x07 -_MPU6050_YA_OFFS_USRH = 0x08 -_MPU6050_YA_OFFS_USRL = 0x09 -_MPU6050_ZA_OFFS_USRH = 0x0A -_MPU6050_ZA_OFFS_USRL = 0x0B - -# Self Test Registers -_MPU6050_SELF_TEST_X = 0x0D -_MPU6050_SELF_TEST_Y = 0x0E -_MPU6050_SELF_TEST_Z = 0x0F -_MPU6050_SELF_TEST_A = 0x10 - -# Gyroscope Offset Registers -_MPU6050_XG_OFFS_USRH = 0x13 -_MPU6050_XG_OFFS_USRL = 0x14 -_MPU6050_YG_OFFS_USRH = 0x15 -_MPU6050_YG_OFFS_USRL = 0x16 -_MPU6050_ZG_OFFS_USRH = 0x17 -_MPU6050_ZG_OFFS_USRL = 0x18 - -# Configuration Registers -_MPU6050_SMPLRT_DIV = 0x19 -_MPU6050_CONFIG = 0x1A -_MPU6050_GYRO_CONFIG = 0x1B -_MPU6050_ACCEL_CONFIG = 0x1C - -""" -# Freefall -_MPU6050_FF_THR = 0x1D # FURTHER DEVELOPMENT NEEDED TO ENABLE THESE -_MPU6050_FF_DUR = 0x1E - -# Motion Detection -_MPU6050_MOT_DET_THRSHLD = 0x1F -_MPU6050_MOT_DET_DURATION = 0x20 -_MPU6050_ZRMOT_THR = 0x21 -_MPU6050_ZRMOT_DUR = 0x22 -""" - -# FIFO Enable -_MPU6050_FIFO_EN = 0x23 - -""" -# I2C Master/Slave Bus Control -_MPU6050_I2C_MST_CTRL = 0x24 # FURTHER DEVELOPMENT NEEDED TO ENABLE THESE -_MPU6050_I2C_SLV0_ADDR = 0x25 -_MPU6050_I2C_SLV0_REG = 0x26 -_MPU6050_I2C_SLV0_CTRL = 0x27 -_MPU6050_I2C_SLV1_ADDR = 0x28 -_MPU6050_I2C_SLV1_REG = 0x29 -_MPU6050_I2C_SLV1_CTRL = 0x2A -_MPU6050_I2C_SLV2_ADDR = 0x2B -_MPU6050_I2C_SLV2_REG = 0x2C -_MPU6050_I2C_SLV2_CTRL = 0x2D -_MPU6050_I2C_SLV3_ADDR = 0x2E -_MPU6050_I2C_SLV3_REG = 0x2F -_MPU6050_I2C_SLV3_CTRL = 0x30 -_MPU6050_I2C_SLV4_ADDR = 0x31 -_MPU6050_I2C_SLV4_REG = 0x32 -_MPU6050_I2C_SLV4_DO = 0x33 -_MPU6050_I2C_SLV4_CTRL = 0x34 -_MPU6050_I2C_SLV4_DI = 0x35 -_MPU6050_I2C_MST_STATUS = 0x36 -""" - -# Interrupt Configuration -_MPU6050_INT_PIN_CFG = 0x37 -_MPU6050_INT_ENABLE = 0x38 - -# _DMP_INT_STATUS = 0x39 -_MPU6050_INT_STATUS = 0x3A - -# Sensor Outputs -_MPU6050_ACCEL_XOUT_H = 0x3B -_MPU6050_ACCEL_XOUT_L = 0x3C -_MPU6050_ACCEL_YOUT_H = 0x3D -_MPU6050_ACCEL_YOUT_L = 0x3E -_MPU6050_ACCEL_ZOUT_H = 0x3F -_MPU6050_ACCEL_ZOUT_L = 0x40 -_MPU6050_TEMP_OUT_H = 0x41 -_MPU6050_TEMP_OUT_L = 0x42 -_MPU6050_GYRO_XOUT_H = 0x43 -_MPU6050_GYRO_XOUT_L = 0x44 -_MPU6050_GYRO_YOUT_H = 0x45 -_MPU6050_GYRO_YOUT_L = 0x46 -_MPU6050_GYRO_ZOUT_H = 0x47 -_MPU6050_GYRO_ZOUT_L = 0x48 +_MPU6050_DEFAULT_ADDRESS = 0x68 # MPU6050 default i2c address w/ AD0 low +_MPU6050_DEVICE_ID = 0x68 # The correct MPU6050_WHO_AM_I value + +_MPU6050_SELF_TEST_X = 0x0D # Self test factory calibrated values register +_MPU6050_SELF_TEST_Y = 0x0E # Self test factory calibrated values register +_MPU6050_SELF_TEST_Z = 0x0F # Self test factory calibrated values register +_MPU6050_SELF_TEST_A = 0x10 # Self test factory calibrated values register +_MPU6050_SMPLRT_DIV = 0x19 # sample rate divisor register +_MPU6050_CONFIG = 0x1A # General configuration register +_MPU6050_GYRO_CONFIG = 0x1B # Gyro specfic configuration register +_MPU6050_ACCEL_CONFIG = 0x1C # Accelerometer specific configration register +_MPU6050_INT_PIN_CONFIG = 0x37 # Interrupt pin configuration register +_MPU6050_ACCEL_OUT = 0x3B # base address for sensor data reads +_MPU6050_TEMP_OUT = 0x41 # Temperature data high byte register +_MPU6050_GYRO_OUT = 0x43 # base address for sensor data reads +_MPU6050_SIG_PATH_RESET = 0x68 # register to reset sensor signal paths +_MPU6050_USER_CTRL = 0x6A # FIFO and I2C Master control register +_MPU6050_PWR_MGMT_1 = 0x6B # Primary power/sleep control register +_MPU6050_PWR_MGMT_2 = 0x6C # Secondary power/sleep control register +_MPU6050_WHO_AM_I = 0x75 # Divice ID register -""" -# External Sensor Data More development needed to enable these -_MPU6050_EXT_SENS_DATA_00 = 0x49 -_MPU6050_EXT_SENS_DATA_01 = 0x4A -_MPU6050_EXT_SENS_DATA_02 = 0x4B -_MPU6050_EXT_SENS_DATA_03 = 0x4C -_MPU6050_EXT_SENS_DATA_04 = 0x4D -_MPU6050_EXT_SENS_DATA_05 = 0x4E -_MPU6050_EXT_SENS_DATA_06 = 0x4F -_MPU6050_EXT_SENS_DATA_07 = 0x50 -_MPU6050_EXT_SENS_DATA_08 = 0x51 -_MPU6050_EXT_SENS_DATA_09 = 0x52 -_MPU6050_EXT_SENS_DATA_10 = 0x53 -_MPU6050_EXT_SENS_DATA_11 = 0x54 -_MPU6050_EXT_SENS_DATA_12 = 0x55 -_MPU6050_EXT_SENS_DATA_13 = 0x56 -_MPU6050_EXT_SENS_DATA_14 = 0x57 -_MPU6050_EXT_SENS_DATA_15 = 0x58 -_MPU6050_EXT_SENS_DATA_16 = 0x59 -_MPU6050_EXT_SENS_DATA_17 = 0x5A -_MPU6050_EXT_SENS_DATA_18 = 0x5B -_MPU6050_EXT_SENS_DATA_19 = 0x5C -_MPU6050_EXT_SENS_DATA_20 = 0x5D -_MPU6050_EXT_SENS_DATA_21 = 0x5E -_MPU6050_EXT_SENS_DATA_22 = 0x5F -_MPU6050_EXT_SENS_DATA_23 = 0x60 - -# Motion Detect Status -# _MPU6050_MOT_DETECT_STATUS = 0x61 - - -# I2C Slave DO -_MPU6050_I2C_SLV0_DO = 0x63 -_MPU6050_I2C_SLV1_DO = 0x64 -_MPU6050_I2C_SLV2_DO = 0x65 -_MPU6050_I2C_SLV3_DO = 0x66 - -# I2C Master Delay Control -_MPU6050_I2C_MT_DELAY_CTRL = 0x67 -""" +STANDARD_GRAVITY = 9.80665 -# Resets / Enables -_MPU6050_SIGNAL_PATH_RESET = 0x68 -# _MPU6050_MOT_DETECT_CTRL = 0x69 +class Clksel: # pylint: disable=too-few-public-methods + """Allowed values for `_clksel` Register object. -_MPU6050_USER_CTRL = 0x6A -_MPU6050_PWR_MGMT_1 = 0x6B -_MPU6050_PWR_MGMT_2 = 0x6C + * :attr:'Clksel.CLKSEL_INTERNAL_8MHz + * :attr:'Clksel.CLKSEL_INTERNAL_X + * :attr:'Clksel.CLKSEL_INTERNAL_Y + * :attr:'Clksel.CLKSEL_INTERNAL_Z + * :attr:'Clksel.CLKSEL_EXTERNAL_32 + * :attr:'Clksel.CLKSEL_EXTERNAL_19 + * :attr:'Clksel.CLKSEL_RESERVED + * :attr:'Clksel.CLKSEL_STOP + """ -""" -# DMP -_MPU6050_BANK_SEL = const(0x6D) -_MPU6050_MEM_START_ADDR = const(0x6E) -_MPU6050_MEM_R_W = const(0x6F) # FURTHER DEVELOPMENT NEEDED TO ENABLE THESE -_MPU6050_DMP_CFG_1 = const(0x70) -_MPU6050_DMP_CFG_2 = const(0x71) -""" - -# FIFO Buffer Count -_MPU6050_FIFO_COUNTH = 0x72 -_MPU6050_FIFO_COUNTL = 0x73 -_MPU6050_FIFO_R_W = 0x74 - -# Who am I? "To be... or not to be? That -is- the question" -_MPU6050_WHO_AM_I = 0x75 + CLKSEL_INTERNAL_8MHz = 0 # Internal 8MHz oscillator + CLKSEL_INTERNAL_X = 1 # PLL with X Axis gyroscope reference + CLKSEL_INTERNAL_Y = 2 # PLL with Y Axis gyroscope reference + CLKSEL_INTERNAL_Z = 3 # PLL with Z Axis gyroscope reference + CLKSEL_EXTERNAL_32 = 4 # External 32.768 kHz reference + CLKSEL_EXTERNAL_19 = 5 # External 19.2 MHz reference + CLKSEL_RESERVED = 6 # Reserved + CLKSEL_STOP = 7 # Stops the clock, constant reset mode -STANDARD_GRAVITY = 9.80665 class Range: # pylint: disable=too-few-public-methods """Allowed values for `accelerometer_range`. @@ -339,31 +204,54 @@ class MPU6050: gyro_x, gyro_y, gyro_z = sensor.gyro temperature = sensor.temperature + === Test Script === + # What I used to get everything going + #import busio + #i2c = busio.I2C(scl=board.A1, sda=board.A0) + #imu = MPU6050(i2c, 0x69) + + # What I presume testers will use + import board + i2c = board.I2C() + imu = (i2c) + + + # Test Class value assignments + print("Test of Class assigments") + imu.clock_source = Clksel.CLKSEL_INTERNAL_8MHz + print("Clock source is: ", imu.clock_source) + imu.clock_source = Clksel.CLKSEL_INTERNAL_X + print("Clock source is: ", imu.clock_source) + imu.clock_source = Clksel.CLKSEL_INTERNAL_Y + print("Clock source is: ", imu.clock_source) + imu.clock_source = Clksel.CLKSEL_INTERNAL_Z + print("Clock source is: ", imu.clock_source) + imu.clock_source = Clksel.CLKSEL_EXTERNAL_32 + print("Clock source is: ", imu.clock_source) + imu.clock_source = Clksel.CLKSEL_EXTERNAL_19 + print("Clock source is: ", imu.clock_source) + imu.clock_source = Clksel.CLKSEL_RESERVED + print("Clock source is: ", imu.clock_source) + imu.clock_source = Clksel.CLKSEL_STOP + print("Clock source is: ", imu.clock_source) + + # Test integer Assignments + print("Test Integer assignments") + for x in range(0,8): + imu.clock_source=x + print("Clock source is: ", imu.clock_source) + + # Produce an error - comment out as needed + imu.clock_source = -1 + imu.clock_source = 8 """ - def __init__(self, i2c_bus: I2C, address) -> None: - - # Check user input for correctness correctness - if address is not _MPU6050_DEVICE_ID_AD0_LO and address is not _MPU6050_DEVICE_ID_AD0_HI: - raise RuntimeError("MPU6050 address passed in is incorrect. Expecting " - "0x68 OR 0x69 (104 OR 105). See Data Sheet / Register Map for details") - - # Verify i2c_bus is not already locked to prevent a hang - i2c_bus.unlock() - - # Attempt to establish an I2CDevice object + def __init__(self, i2c_bus: I2C, address: int = _MPU6050_DEFAULT_ADDRESS) -> None: self.i2c_device = i2c_device.I2CDevice(i2c_bus, address) - - # Verify WHO_AM_I (register 0x75) responds with value of 104, regardless of AD0 state. - # This double checks the device responding is a MPU6050 - if self._who_am_i[0][0] is _MPU6050_DEVICE_ID_AD0_LO: - print("Communication to MPU6050 @", address, " confirmed.") - else: - raise RuntimeError("MPU6050 @ ", address, " invalid response from \"Who Am I\" " - "(104 0x68) not found. Possible a device, other than MPU6050, responding " - "from the same address. Check for I2C address conflicts on the same " - "I2C bus and try again.") - + + if self._device_id != _MPU6050_DEVICE_ID: + raise RuntimeError("Failed to find MPU6050 - check your wiring!") + self.reset() self._sample_rate_divisor = 0 @@ -371,7 +259,9 @@ def __init__(self, i2c_bus: I2C, address) -> None: self._gyro_range = GyroRange.RANGE_500_DPS self._accel_range = Range.RANGE_2_G sleep(0.100) - self._clock_source = 1 # set to use gyro x-axis as reference + self.clock_source = ( + Clksel.CLKSEL_INTERNAL_X + ) # set to use gyro x-axis as reference sleep(0.100) self.sleep = False sleep(0.010) @@ -386,22 +276,21 @@ def reset(self) -> None: _signal_path_reset = 0b111 # reset all sensors sleep(0.100) - _clock_source = RWBits(3, _MPU6050_PWR_MGMT_1, 0) + _clksel = RWBits(3, _MPU6050_PWR_MGMT_1, 0) _device_id = ROUnaryStruct(_MPU6050_WHO_AM_I, ">B") _reset = RWBit(_MPU6050_PWR_MGMT_1, 7, 1) - _signal_path_reset = RWBits(3, _MPU6050_SIGNAL_PATH_RESET, 3) + _signal_path_reset = RWBits(3, _MPU6050_SIG_PATH_RESET, 3) _gyro_range = RWBits(2, _MPU6050_GYRO_CONFIG, 3) _accel_range = RWBits(2, _MPU6050_ACCEL_CONFIG, 3) _filter_bandwidth = RWBits(2, _MPU6050_CONFIG, 3) - _raw_accel_data = StructArray(_MPU6050_ACCEL_XOUT_H, ">h", 3) - _raw_gyro_data = StructArray(_MPU6050_GYRO_XOUT_H, ">h", 3) - _raw_temp_data = ROUnaryStruct(_MPU6050_TEMP_OUT_H, ">h") - - _who_am_i = StructArray(_MPU6050_WHO_AM_I,'B',1) + _raw_accel_data = StructArray(_MPU6050_ACCEL_OUT, ">h", 3) + _raw_gyro_data = StructArray(_MPU6050_GYRO_OUT, ">h", 3) + _raw_temp_data = ROUnaryStruct(_MPU6050_TEMP_OUT, ">h") + _cycle = RWBit(_MPU6050_PWR_MGMT_1, 5) _cycle_rate = RWBits(2, _MPU6050_PWR_MGMT_2, 6, 1) @@ -527,4 +416,16 @@ def cycle_rate(self, value: int) -> None: if (value < 0) or (value > 3): raise ValueError("cycle_rate must be a Rate") self._cycle_rate = value - sleep(0.01) \ No newline at end of file + sleep(0.01) + + @property + def clock_source(self) -> int: + """Returns current CLKSEL value, Reg Map Pg 40""" + return self._clksel + + @clock_source.setter + def clock_source(self, value: int) -> None: + """Sets CLKSEL value, Reg Map Pg 40""" + if (value < 0) or (value > 7): + raise ValueError("clock_source must be Clksel value, integer from 0 - 7.") + self._clksel = value From 9efab5d09456ca390ab9cbfd28ab38bd209e7375 Mon Sep 17 00:00:00 2001 From: SquirtleSquadLeader <112285567+SquirtleSquadLeader@users.noreply.github.com> Date: Fri, 4 Nov 2022 21:26:09 -0400 Subject: [PATCH 03/16] Removed test from comment --- adafruit_mpu6050.py | 41 ----------------------------------------- 1 file changed, 41 deletions(-) diff --git a/adafruit_mpu6050.py b/adafruit_mpu6050.py index 1ed275f..dd31228 100644 --- a/adafruit_mpu6050.py +++ b/adafruit_mpu6050.py @@ -203,47 +203,6 @@ class MPU6050: acc_x, acc_y, acc_z = sensor.acceleration gyro_x, gyro_y, gyro_z = sensor.gyro temperature = sensor.temperature - - === Test Script === - # What I used to get everything going - #import busio - #i2c = busio.I2C(scl=board.A1, sda=board.A0) - #imu = MPU6050(i2c, 0x69) - - # What I presume testers will use - import board - i2c = board.I2C() - imu = (i2c) - - - # Test Class value assignments - print("Test of Class assigments") - imu.clock_source = Clksel.CLKSEL_INTERNAL_8MHz - print("Clock source is: ", imu.clock_source) - imu.clock_source = Clksel.CLKSEL_INTERNAL_X - print("Clock source is: ", imu.clock_source) - imu.clock_source = Clksel.CLKSEL_INTERNAL_Y - print("Clock source is: ", imu.clock_source) - imu.clock_source = Clksel.CLKSEL_INTERNAL_Z - print("Clock source is: ", imu.clock_source) - imu.clock_source = Clksel.CLKSEL_EXTERNAL_32 - print("Clock source is: ", imu.clock_source) - imu.clock_source = Clksel.CLKSEL_EXTERNAL_19 - print("Clock source is: ", imu.clock_source) - imu.clock_source = Clksel.CLKSEL_RESERVED - print("Clock source is: ", imu.clock_source) - imu.clock_source = Clksel.CLKSEL_STOP - print("Clock source is: ", imu.clock_source) - - # Test integer Assignments - print("Test Integer assignments") - for x in range(0,8): - imu.clock_source=x - print("Clock source is: ", imu.clock_source) - - # Produce an error - comment out as needed - imu.clock_source = -1 - imu.clock_source = 8 """ def __init__(self, i2c_bus: I2C, address: int = _MPU6050_DEFAULT_ADDRESS) -> None: From 565201c79120df128a3be595475a0ec6a4f04039 Mon Sep 17 00:00:00 2001 From: SquirtleSquadLeader <112285567+SquirtleSquadLeader@users.noreply.github.com> Date: Fri, 4 Nov 2022 21:27:06 -0400 Subject: [PATCH 04/16] Update adafruit_mpu6050.py --- adafruit_mpu6050.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/adafruit_mpu6050.py b/adafruit_mpu6050.py index dd31228..860e075 100644 --- a/adafruit_mpu6050.py +++ b/adafruit_mpu6050.py @@ -30,10 +30,6 @@ * Adafruit's Register library: https://github.com/adafruit/Adafruit_CircuitPython_Register - Change log: - 1) Added Clksel class to store options similar to previous author - 2) Changed Register name to match Register Map documentation - 3) Added Getter/Setter property to negotiate transactions """ # imports From a9289a2f612e445ecd4dae6823d5bcb222feb594 Mon Sep 17 00:00:00 2001 From: SquirtleSquadLeader <112285567+SquirtleSquadLeader@users.noreply.github.com> Date: Fri, 4 Nov 2022 21:39:03 -0400 Subject: [PATCH 05/16] Update adafruit_mpu6050.py --- adafruit_mpu6050.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_mpu6050.py b/adafruit_mpu6050.py index 860e075..3800f89 100644 --- a/adafruit_mpu6050.py +++ b/adafruit_mpu6050.py @@ -76,7 +76,7 @@ class Clksel: # pylint: disable=too-few-public-methods - """Allowed values for `_clksel` Register object. + """Allowed values for `clock_source` * :attr:'Clksel.CLKSEL_INTERNAL_8MHz * :attr:'Clksel.CLKSEL_INTERNAL_X From 43285385983b501bf9f9a4d4a1ca77d0ccd4d02c Mon Sep 17 00:00:00 2001 From: SquirtleSquadLeader <112285567+SquirtleSquadLeader@users.noreply.github.com> Date: Fri, 4 Nov 2022 21:50:06 -0400 Subject: [PATCH 06/16] Update adafruit_mpu6050.py --- adafruit_mpu6050.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_mpu6050.py b/adafruit_mpu6050.py index 3800f89..48a60af 100644 --- a/adafruit_mpu6050.py +++ b/adafruit_mpu6050.py @@ -76,7 +76,7 @@ class Clksel: # pylint: disable=too-few-public-methods - """Allowed values for `clock_source` + """Allowed values for py:attr:`clock_source`. * :attr:'Clksel.CLKSEL_INTERNAL_8MHz * :attr:'Clksel.CLKSEL_INTERNAL_X From d6da4ef6a45f9cd68c05ff57d0f83f8659362b2d Mon Sep 17 00:00:00 2001 From: SquirtleSquadLeader <112285567+SquirtleSquadLeader@users.noreply.github.com> Date: Fri, 4 Nov 2022 23:40:34 -0400 Subject: [PATCH 07/16] Update adafruit_mpu6050.py --- adafruit_mpu6050.py | 62 ++++++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/adafruit_mpu6050.py b/adafruit_mpu6050.py index 48a60af..3c76357 100644 --- a/adafruit_mpu6050.py +++ b/adafruit_mpu6050.py @@ -78,14 +78,14 @@ class Clksel: # pylint: disable=too-few-public-methods """Allowed values for py:attr:`clock_source`. - * :attr:'Clksel.CLKSEL_INTERNAL_8MHz - * :attr:'Clksel.CLKSEL_INTERNAL_X - * :attr:'Clksel.CLKSEL_INTERNAL_Y - * :attr:'Clksel.CLKSEL_INTERNAL_Z - * :attr:'Clksel.CLKSEL_EXTERNAL_32 - * :attr:'Clksel.CLKSEL_EXTERNAL_19 - * :attr:'Clksel.CLKSEL_RESERVED - * :attr:'Clksel.CLKSEL_STOP + * py:attr:'Clksel.CLKSEL_INTERNAL_8MHz + * py:attr:'Clksel.CLKSEL_INTERNAL_X + * py:attr:'Clksel.CLKSEL_INTERNAL_Y + * py:attr:'Clksel.CLKSEL_INTERNAL_Z + * py:attr:'Clksel.CLKSEL_EXTERNAL_32 + * py:attr:'Clksel.CLKSEL_EXTERNAL_19 + * py:attr:'Clksel.CLKSEL_RESERVED + * py:attr:'Clksel.CLKSEL_STOP """ CLKSEL_INTERNAL_8MHz = 0 # Internal 8MHz oscillator @@ -99,12 +99,12 @@ class Clksel: # pylint: disable=too-few-public-methods class Range: # pylint: disable=too-few-public-methods - """Allowed values for `accelerometer_range`. + """Allowed values for py:attr:`accelerometer_range`. - * :attr:`Range.RANGE_2_G` - * :attr:`Range.RANGE_4_G` - * :attr:`Range.RANGE_8_G` - * :attr:`Range.RANGE_16_G` + * py:attr:`Range.RANGE_2_G` + * py:attr:`Range.RANGE_4_G` + * py:attr:`Range.RANGE_8_G` + * py:attr:`Range.RANGE_16_G` """ @@ -115,12 +115,12 @@ class Range: # pylint: disable=too-few-public-methods class GyroRange: # pylint: disable=too-few-public-methods - """Allowed values for `gyro_range`. + """Allowed values for py:attr:`gyro_range`. - * :attr:`GyroRange.RANGE_250_DPS` - * :attr:`GyroRange.RANGE_500_DPS` - * :attr:`GyroRange.RANGE_1000_DPS` - * :attr:`GyroRange.RANGE_2000_DPS` + * py:attr:`GyroRange.RANGE_250_DPS` + * py:attr:`GyroRange.RANGE_500_DPS` + * py:attr:`GyroRange.RANGE_1000_DPS` + * py:attr:`GyroRange.RANGE_2000_DPS` """ @@ -131,15 +131,15 @@ class GyroRange: # pylint: disable=too-few-public-methods class Bandwidth: # pylint: disable=too-few-public-methods - """Allowed values for `filter_bandwidth`. + """Allowed values for py:attr:`filter_bandwidth`. - * :attr:`Bandwidth.BAND_260_HZ` - * :attr:`Bandwidth.BAND_184_HZ` - * :attr:`Bandwidth.BAND_94_HZ` - * :attr:`Bandwidth.BAND_44_HZ` - * :attr:`Bandwidth.BAND_21_HZ` - * :attr:`Bandwidth.BAND_10_HZ` - * :attr:`Bandwidth.BAND_5_HZ` + * py:attr:`Bandwidth.BAND_260_HZ` + * py:attr:`Bandwidth.BAND_184_HZ` + * py:attr:`Bandwidth.BAND_94_HZ` + * py:attr:`Bandwidth.BAND_44_HZ` + * py:attr:`Bandwidth.BAND_21_HZ` + * py:attr:`Bandwidth.BAND_10_HZ` + * py:attr:`Bandwidth.BAND_5_HZ` """ @@ -153,12 +153,12 @@ class Bandwidth: # pylint: disable=too-few-public-methods class Rate: # pylint: disable=too-few-public-methods - """Allowed values for `cycle_rate`. + """Allowed values for py:attr:`cycle_rate`. - * :attr:`Rate.CYCLE_1_25_HZ` - * :attr:`Rate.CYCLE_5_HZ` - * :attr:`Rate.CYCLE_20_HZ` - * :attr:`Rate.CYCLE_40_HZ` + * py:attr:`Rate.CYCLE_1_25_HZ` + * py:attr:`Rate.CYCLE_5_HZ` + * py:attr:`Rate.CYCLE_20_HZ` + * py:attr:`Rate.CYCLE_40_HZ` """ From e33f3ea6878cf3a1b29a9d7e2966df8f31b4f59c Mon Sep 17 00:00:00 2001 From: SquirtleSquadLeader <112285567+SquirtleSquadLeader@users.noreply.github.com> Date: Sat, 5 Nov 2022 11:12:55 -0400 Subject: [PATCH 08/16] Passed all checks via pre-commit --- adafruit_mpu6050.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_mpu6050.py b/adafruit_mpu6050.py index 3c76357..8564e01 100644 --- a/adafruit_mpu6050.py +++ b/adafruit_mpu6050.py @@ -76,7 +76,7 @@ class Clksel: # pylint: disable=too-few-public-methods - """Allowed values for py:attr:`clock_source`. + """Allowed values for py:attr:`clock_source`. * py:attr:'Clksel.CLKSEL_INTERNAL_8MHz * py:attr:'Clksel.CLKSEL_INTERNAL_X From 3c1f0e26c2ce4298b9b8335ee71ad59fe151a970 Mon Sep 17 00:00:00 2001 From: SquirtleSquadLeader <112285567+SquirtleSquadLeader@users.noreply.github.com> Date: Sat, 5 Nov 2022 11:39:19 -0400 Subject: [PATCH 09/16] Removed py:attr: decorators in some spots I added py:attr: to some original module Classes... maybe that was messing up linting/black --- adafruit_mpu6050.py | 46 ++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/adafruit_mpu6050.py b/adafruit_mpu6050.py index 8564e01..41a66c1 100644 --- a/adafruit_mpu6050.py +++ b/adafruit_mpu6050.py @@ -99,12 +99,12 @@ class Clksel: # pylint: disable=too-few-public-methods class Range: # pylint: disable=too-few-public-methods - """Allowed values for py:attr:`accelerometer_range`. + """Allowed values for `accelerometer_range`. - * py:attr:`Range.RANGE_2_G` - * py:attr:`Range.RANGE_4_G` - * py:attr:`Range.RANGE_8_G` - * py:attr:`Range.RANGE_16_G` + * :attr:`Range.RANGE_2_G` + * :attr:`Range.RANGE_4_G` + * :attr:`Range.RANGE_8_G` + * :attr:`Range.RANGE_16_G` """ @@ -115,12 +115,12 @@ class Range: # pylint: disable=too-few-public-methods class GyroRange: # pylint: disable=too-few-public-methods - """Allowed values for py:attr:`gyro_range`. + """Allowed values for `gyro_range`. - * py:attr:`GyroRange.RANGE_250_DPS` - * py:attr:`GyroRange.RANGE_500_DPS` - * py:attr:`GyroRange.RANGE_1000_DPS` - * py:attr:`GyroRange.RANGE_2000_DPS` + * :attr:`GyroRange.RANGE_250_DPS` + * :attr:`GyroRange.RANGE_500_DPS` + * :attr:`GyroRange.RANGE_1000_DPS` + * :attr:`GyroRange.RANGE_2000_DPS` """ @@ -131,15 +131,15 @@ class GyroRange: # pylint: disable=too-few-public-methods class Bandwidth: # pylint: disable=too-few-public-methods - """Allowed values for py:attr:`filter_bandwidth`. + """Allowed values for `filter_bandwidth`. - * py:attr:`Bandwidth.BAND_260_HZ` - * py:attr:`Bandwidth.BAND_184_HZ` - * py:attr:`Bandwidth.BAND_94_HZ` - * py:attr:`Bandwidth.BAND_44_HZ` - * py:attr:`Bandwidth.BAND_21_HZ` - * py:attr:`Bandwidth.BAND_10_HZ` - * py:attr:`Bandwidth.BAND_5_HZ` + * :attr:`Bandwidth.BAND_260_HZ` + * :attr:`Bandwidth.BAND_184_HZ` + * :attr:`Bandwidth.BAND_94_HZ` + * :attr:`Bandwidth.BAND_44_HZ` + * :attr:`Bandwidth.BAND_21_HZ` + * :attr:`Bandwidth.BAND_10_HZ` + * :attr:`Bandwidth.BAND_5_HZ` """ @@ -153,12 +153,12 @@ class Bandwidth: # pylint: disable=too-few-public-methods class Rate: # pylint: disable=too-few-public-methods - """Allowed values for py:attr:`cycle_rate`. + """Allowed values for `cycle_rate`. - * py:attr:`Rate.CYCLE_1_25_HZ` - * py:attr:`Rate.CYCLE_5_HZ` - * py:attr:`Rate.CYCLE_20_HZ` - * py:attr:`Rate.CYCLE_40_HZ` + * :attr:`Rate.CYCLE_1_25_HZ` + * :attr:`Rate.CYCLE_5_HZ` + * :attr:`Rate.CYCLE_20_HZ` + * :attr:`Rate.CYCLE_40_HZ` """ From 6c1d94505262853b2080f0e28ddce669a29591ad Mon Sep 17 00:00:00 2001 From: SquirtleSquadLeader <112285567+SquirtleSquadLeader@users.noreply.github.com> Date: Sat, 5 Nov 2022 11:51:13 -0400 Subject: [PATCH 10/16] Added :py:attr: decorators --- adafruit_mpu6050.py | 66 ++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/adafruit_mpu6050.py b/adafruit_mpu6050.py index 41a66c1..5eb8d1d 100644 --- a/adafruit_mpu6050.py +++ b/adafruit_mpu6050.py @@ -76,16 +76,16 @@ class Clksel: # pylint: disable=too-few-public-methods - """Allowed values for py:attr:`clock_source`. - - * py:attr:'Clksel.CLKSEL_INTERNAL_8MHz - * py:attr:'Clksel.CLKSEL_INTERNAL_X - * py:attr:'Clksel.CLKSEL_INTERNAL_Y - * py:attr:'Clksel.CLKSEL_INTERNAL_Z - * py:attr:'Clksel.CLKSEL_EXTERNAL_32 - * py:attr:'Clksel.CLKSEL_EXTERNAL_19 - * py:attr:'Clksel.CLKSEL_RESERVED - * py:attr:'Clksel.CLKSEL_STOP + """Allowed values for :py:attr:`clock_source`. + + * :py:attr:'Clksel.CLKSEL_INTERNAL_8MHz + * :py:attr:'Clksel.CLKSEL_INTERNAL_X + * :py:attr:'Clksel.CLKSEL_INTERNAL_Y + * :py:attr:'Clksel.CLKSEL_INTERNAL_Z + * :py:attr:'Clksel.CLKSEL_EXTERNAL_32 + * :py:attr:'Clksel.CLKSEL_EXTERNAL_19 + * :py:attr:'Clksel.CLKSEL_RESERVED + * :py:attr:'Clksel.CLKSEL_STOP """ CLKSEL_INTERNAL_8MHz = 0 # Internal 8MHz oscillator @@ -99,12 +99,12 @@ class Clksel: # pylint: disable=too-few-public-methods class Range: # pylint: disable=too-few-public-methods - """Allowed values for `accelerometer_range`. + """Allowed values for :py:attr:`accelerometer_range`. - * :attr:`Range.RANGE_2_G` - * :attr:`Range.RANGE_4_G` - * :attr:`Range.RANGE_8_G` - * :attr:`Range.RANGE_16_G` + * :py:attr:`Range.RANGE_2_G` + * :py:attr:`Range.RANGE_4_G` + * :py:attr:`Range.RANGE_8_G` + * :py:attr:`Range.RANGE_16_G` """ @@ -115,12 +115,12 @@ class Range: # pylint: disable=too-few-public-methods class GyroRange: # pylint: disable=too-few-public-methods - """Allowed values for `gyro_range`. + """Allowed values for :py:attr:`gyro_range`. - * :attr:`GyroRange.RANGE_250_DPS` - * :attr:`GyroRange.RANGE_500_DPS` - * :attr:`GyroRange.RANGE_1000_DPS` - * :attr:`GyroRange.RANGE_2000_DPS` + * :py:attr:`GyroRange.RANGE_250_DPS` + * :py:attr:`GyroRange.RANGE_500_DPS` + * :py:attr:`GyroRange.RANGE_1000_DPS` + * :py:attr:`GyroRange.RANGE_2000_DPS` """ @@ -131,15 +131,15 @@ class GyroRange: # pylint: disable=too-few-public-methods class Bandwidth: # pylint: disable=too-few-public-methods - """Allowed values for `filter_bandwidth`. + """Allowed values for :py:attr:`filter_bandwidth`. - * :attr:`Bandwidth.BAND_260_HZ` - * :attr:`Bandwidth.BAND_184_HZ` - * :attr:`Bandwidth.BAND_94_HZ` - * :attr:`Bandwidth.BAND_44_HZ` - * :attr:`Bandwidth.BAND_21_HZ` - * :attr:`Bandwidth.BAND_10_HZ` - * :attr:`Bandwidth.BAND_5_HZ` + * :py:attr:`Bandwidth.BAND_260_HZ` + * :py:attr:`Bandwidth.BAND_184_HZ` + * :py:attr:`Bandwidth.BAND_94_HZ` + * :py:attr:`Bandwidth.BAND_44_HZ` + * :py:attr:`Bandwidth.BAND_21_HZ` + * :py:attr:`Bandwidth.BAND_10_HZ` + * :py:attr:`Bandwidth.BAND_5_HZ` """ @@ -153,12 +153,12 @@ class Bandwidth: # pylint: disable=too-few-public-methods class Rate: # pylint: disable=too-few-public-methods - """Allowed values for `cycle_rate`. + """Allowed values for :py:attr:`cycle_rate`. - * :attr:`Rate.CYCLE_1_25_HZ` - * :attr:`Rate.CYCLE_5_HZ` - * :attr:`Rate.CYCLE_20_HZ` - * :attr:`Rate.CYCLE_40_HZ` + * :py:attr:`Rate.CYCLE_1_25_HZ` + * :py:attr:`Rate.CYCLE_5_HZ` + * :py:attr:`Rate.CYCLE_20_HZ` + * :py:attr:`Rate.CYCLE_40_HZ` """ From c84e840d7f1af9c0d24d1193adef5cea05c9553f Mon Sep 17 00:00:00 2001 From: SquirtleSquadLeader <112285567+SquirtleSquadLeader@users.noreply.github.com> Date: Sat, 5 Nov 2022 12:09:17 -0400 Subject: [PATCH 11/16] Clksel class now ClockSource Changed references throughout module too --- adafruit_mpu6050.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/adafruit_mpu6050.py b/adafruit_mpu6050.py index 5eb8d1d..ed8ae31 100644 --- a/adafruit_mpu6050.py +++ b/adafruit_mpu6050.py @@ -75,17 +75,17 @@ STANDARD_GRAVITY = 9.80665 -class Clksel: # pylint: disable=too-few-public-methods +class CLockSource: # pylint: disable=too-few-public-methods """Allowed values for :py:attr:`clock_source`. - * :py:attr:'Clksel.CLKSEL_INTERNAL_8MHz - * :py:attr:'Clksel.CLKSEL_INTERNAL_X - * :py:attr:'Clksel.CLKSEL_INTERNAL_Y - * :py:attr:'Clksel.CLKSEL_INTERNAL_Z - * :py:attr:'Clksel.CLKSEL_EXTERNAL_32 - * :py:attr:'Clksel.CLKSEL_EXTERNAL_19 - * :py:attr:'Clksel.CLKSEL_RESERVED - * :py:attr:'Clksel.CLKSEL_STOP + * :py:attr:'CLockSource.CLKSEL_INTERNAL_8MHz + * :py:attr:'CLockSource.CLKSEL_INTERNAL_X + * :py:attr:'CLockSource.CLKSEL_INTERNAL_Y + * :py:attr:'CLockSource.CLKSEL_INTERNAL_Z + * :py:attr:'CLockSource.CLKSEL_EXTERNAL_32 + * :py:attr:'CLockSource.CLKSEL_EXTERNAL_19 + * :py:attr:'CLockSource.CLKSEL_RESERVED + * :py:attr:'CLockSource.CLKSEL_STOP """ CLKSEL_INTERNAL_8MHz = 0 # Internal 8MHz oscillator @@ -215,7 +215,7 @@ def __init__(self, i2c_bus: I2C, address: int = _MPU6050_DEFAULT_ADDRESS) -> Non self._accel_range = Range.RANGE_2_G sleep(0.100) self.clock_source = ( - Clksel.CLKSEL_INTERNAL_X + CLockSource.CLKSEL_INTERNAL_X ) # set to use gyro x-axis as reference sleep(0.100) self.sleep = False @@ -375,12 +375,14 @@ def cycle_rate(self, value: int) -> None: @property def clock_source(self) -> int: - """Returns current CLKSEL value, Reg Map Pg 40""" + """Returns current CLockSource value, Reg Map Pg 40""" return self._clksel @clock_source.setter def clock_source(self, value: int) -> None: """Sets CLKSEL value, Reg Map Pg 40""" if (value < 0) or (value > 7): - raise ValueError("clock_source must be Clksel value, integer from 0 - 7.") + raise ValueError( + "clock_source must be CLockSource value, integer from 0 - 7." + ) self._clksel = value From 9b9c0a6714036922232e6f48280287302f87b0c1 Mon Sep 17 00:00:00 2001 From: SquirtleSquadLeader <112285567+SquirtleSquadLeader@users.noreply.github.com> Date: Sat, 5 Nov 2022 12:56:57 -0400 Subject: [PATCH 12/16] Added method description Hopefully these comments are suitable. --- adafruit_mpu6050.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_mpu6050.py b/adafruit_mpu6050.py index ed8ae31..141ddba 100644 --- a/adafruit_mpu6050.py +++ b/adafruit_mpu6050.py @@ -375,12 +375,12 @@ def cycle_rate(self, value: int) -> None: @property def clock_source(self) -> int: - """Returns current CLockSource value, Reg Map Pg 40""" + """Returns current clock source selection""" return self._clksel @clock_source.setter def clock_source(self, value: int) -> None: - """Sets CLKSEL value, Reg Map Pg 40""" + """Select between Internal/External clock sources""" if (value < 0) or (value > 7): raise ValueError( "clock_source must be CLockSource value, integer from 0 - 7." From 71bc025033d85f8a465c61952ca0a066da58aeec Mon Sep 17 00:00:00 2001 From: SquirtleSquadLeader <112285567+SquirtleSquadLeader@users.noreply.github.com> Date: Sun, 6 Nov 2022 09:28:37 -0500 Subject: [PATCH 13/16] Update adafruit_mpu6050.py Co-authored-by: Alec Delaney <89490472+tekktrik@users.noreply.github.com> --- adafruit_mpu6050.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_mpu6050.py b/adafruit_mpu6050.py index 141ddba..9c5ddd8 100644 --- a/adafruit_mpu6050.py +++ b/adafruit_mpu6050.py @@ -381,7 +381,7 @@ def clock_source(self) -> int: @clock_source.setter def clock_source(self, value: int) -> None: """Select between Internal/External clock sources""" - if (value < 0) or (value > 7): + if value not in range(8) raise ValueError( "clock_source must be CLockSource value, integer from 0 - 7." ) From 3142b7f42fa20f68c0aac9443b94ce1fde742667 Mon Sep 17 00:00:00 2001 From: SquirtleSquadLeader <112285567+SquirtleSquadLeader@users.noreply.github.com> Date: Sun, 6 Nov 2022 09:33:22 -0500 Subject: [PATCH 14/16] Added missing semi colon --- adafruit_mpu6050.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_mpu6050.py b/adafruit_mpu6050.py index 9c5ddd8..bfee981 100644 --- a/adafruit_mpu6050.py +++ b/adafruit_mpu6050.py @@ -381,7 +381,7 @@ def clock_source(self) -> int: @clock_source.setter def clock_source(self, value: int) -> None: """Select between Internal/External clock sources""" - if value not in range(8) + if value not in range(8): raise ValueError( "clock_source must be CLockSource value, integer from 0 - 7." ) From b53fec580d847df3043fc4daa2b9cceb40eda879 Mon Sep 17 00:00:00 2001 From: SquirtleSquadLeader <112285567+SquirtleSquadLeader@users.noreply.github.com> Date: Sun, 6 Nov 2022 14:03:56 -0500 Subject: [PATCH 15/16] Corrections - Fixed capitol L's - Getter/Setter more clearly stated --- adafruit_mpu6050.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/adafruit_mpu6050.py b/adafruit_mpu6050.py index bfee981..0cf5dfc 100644 --- a/adafruit_mpu6050.py +++ b/adafruit_mpu6050.py @@ -75,17 +75,17 @@ STANDARD_GRAVITY = 9.80665 -class CLockSource: # pylint: disable=too-few-public-methods +class ClockSource: # pylint: disable=too-few-public-methods """Allowed values for :py:attr:`clock_source`. - * :py:attr:'CLockSource.CLKSEL_INTERNAL_8MHz - * :py:attr:'CLockSource.CLKSEL_INTERNAL_X - * :py:attr:'CLockSource.CLKSEL_INTERNAL_Y - * :py:attr:'CLockSource.CLKSEL_INTERNAL_Z - * :py:attr:'CLockSource.CLKSEL_EXTERNAL_32 - * :py:attr:'CLockSource.CLKSEL_EXTERNAL_19 - * :py:attr:'CLockSource.CLKSEL_RESERVED - * :py:attr:'CLockSource.CLKSEL_STOP + * :py:attr:'ClockSource.CLKSEL_INTERNAL_8MHz + * :py:attr:'ClockSource.CLKSEL_INTERNAL_X + * :py:attr:'ClockSource.CLKSEL_INTERNAL_Y + * :py:attr:'ClockSource.CLKSEL_INTERNAL_Z + * :py:attr:'ClockSource.CLKSEL_EXTERNAL_32 + * :py:attr:'ClockSource.CLKSEL_EXTERNAL_19 + * :py:attr:'ClockSource.CLKSEL_RESERVED + * :py:attr:'ClockSource.CLKSEL_STOP """ CLKSEL_INTERNAL_8MHz = 0 # Internal 8MHz oscillator @@ -215,7 +215,7 @@ def __init__(self, i2c_bus: I2C, address: int = _MPU6050_DEFAULT_ADDRESS) -> Non self._accel_range = Range.RANGE_2_G sleep(0.100) self.clock_source = ( - CLockSource.CLKSEL_INTERNAL_X + ClockSource.CLKSEL_INTERNAL_X ) # set to use gyro x-axis as reference sleep(0.100) self.sleep = False @@ -375,7 +375,7 @@ def cycle_rate(self, value: int) -> None: @property def clock_source(self) -> int: - """Returns current clock source selection""" + """Getter/Setter property for clock source selection""" return self._clksel @clock_source.setter @@ -383,6 +383,6 @@ def clock_source(self, value: int) -> None: """Select between Internal/External clock sources""" if value not in range(8): raise ValueError( - "clock_source must be CLockSource value, integer from 0 - 7." + "clock_source must be ClockSource value, integer from 0 - 7." ) self._clksel = value From 805cad691dc862acd94b2235c2e2bb3eac432a23 Mon Sep 17 00:00:00 2001 From: SquirtleSquadLeader <112285567+SquirtleSquadLeader@users.noreply.github.com> Date: Sun, 6 Nov 2022 19:51:17 -0500 Subject: [PATCH 16/16] Update adafruit_mpu6050.py Co-authored-by: Alec Delaney <89490472+tekktrik@users.noreply.github.com> --- adafruit_mpu6050.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_mpu6050.py b/adafruit_mpu6050.py index 0cf5dfc..9be50d4 100644 --- a/adafruit_mpu6050.py +++ b/adafruit_mpu6050.py @@ -375,7 +375,7 @@ def cycle_rate(self, value: int) -> None: @property def clock_source(self) -> int: - """Getter/Setter property for clock source selection""" + """The clock source for the sensor""" return self._clksel @clock_source.setter