MPU6050 Sensor module
MPU6050 6-DoF Accelerometer and Gyro module for Micropython
Loading...
Searching...
No Matches
MPU6050 Class Reference

Driver class for the MPU6050 sensor. More...

Classes

class  AccelRange
 Accelerometer measurement range. More...
class  FilterBandwidth
 Digital Low Pass Filter bandwidth. More...
class  GyroRange
 Gyroscope measurement range. More...

Public Member Functions

 __init__ (self, I2C i2c, int address=_MPU6050_DEFAULT_ADDR)
 Initializes the MPU6050 sensor.
tuple[float, float, float] get_accel_data (self, bool as_g=False)
 Reads and converts the accelerometer data.
dict get_all_data (self)
 Reads all sensor data in a single, efficient transaction.
tuple[float, float, float] get_gyro_data (self)
 Reads and converts the gyroscope data in degrees per second.
float get_temp_data (self)
 Reads and converts the temperature data.
 reset (self)
 Resets sensor registers to their default values.
 set_accel_range (self, int accel_range)
 Sets the accelerometer measurement range.
 set_filter_bandwidth (self, int bandwidth)
 Sets the Digital Low-Pass Filter bandwidth.
 set_gyro_range (self, int gyro_range)
 Sets the gyroscope measurement range.

Public Attributes

 address = address
 i2c = i2c

Protected Member Functions

bytes _read_bytes (self, int register, int length)
int _read_u8 (self, int register)
 _write_u8 (self, int register, int value)

Protected Attributes

 _accel_range = self.AccelRange.RANGE_2_G
 _gyro_range = self.GyroRange.RANGE_250_DEG

Static Protected Attributes

dict _ACCEL_SCALES
dict _GYRO_SCALES

Detailed Description

Driver class for the MPU6050 sensor.

Allows reading of acceleration, gyroscope, and temperature data.

Constructor & Destructor Documentation

◆ __init__()

__init__ ( self,
I2C i2c,
int address = _MPU6050_DEFAULT_ADDR )

Initializes the MPU6050 sensor.

Parameters
i2cThe Micropython I2C object.
addressThe I2C address of the sensor (default is 0x68).

Member Function Documentation

◆ _read_bytes()

bytes _read_bytes ( self,
int register,
int length )
protected

◆ _read_u8()

int _read_u8 ( self,
int register )
protected

◆ _write_u8()

_write_u8 ( self,
int register,
int value )
protected

◆ get_accel_data()

tuple[float, float, float] get_accel_data ( self,
bool as_g = False )

Reads and converts the accelerometer data.

Parameters
as_gIf True, returns values in 'g'. Otherwise, returns in m/s^2 (default).
Returns
A tuple of 3 floats (x, y, z).

◆ get_all_data()

dict get_all_data ( self)

Reads all sensor data in a single, efficient transaction.

Returns
A dictionary containing 'accel' (m/s^2), 'gyro' (°/s), and 'temp' (°C).

◆ get_gyro_data()

tuple[float, float, float] get_gyro_data ( self)

Reads and converts the gyroscope data in degrees per second.

Returns
A tuple of 3 floats (x, y, z) in °/s.

◆ get_temp_data()

float get_temp_data ( self)

Reads and converts the temperature data.

Returns
The temperature in degrees Celsius.

◆ reset()

reset ( self)

Resets sensor registers to their default values.

◆ set_accel_range()

set_accel_range ( self,
int accel_range )

Sets the accelerometer measurement range.

Parameters
accel_rangeUse constants from MPU6050.AccelRange.

◆ set_filter_bandwidth()

set_filter_bandwidth ( self,
int bandwidth )

Sets the Digital Low-Pass Filter bandwidth.

Parameters
bandwidthUse constants from MPU6050.FilterBandwidth.

◆ set_gyro_range()

set_gyro_range ( self,
int gyro_range )

Sets the gyroscope measurement range.

Parameters
gyro_rangeUse constants from MPU6050.GyroRange.

Member Data Documentation

◆ _accel_range

_accel_range = self.AccelRange.RANGE_2_G
protected

◆ _ACCEL_SCALES

dict _ACCEL_SCALES
staticprotected
Initial value:
= {
AccelRange.RANGE_2_G: 16384.0,
AccelRange.RANGE_4_G: 8192.0,
AccelRange.RANGE_8_G: 4096.0,
AccelRange.RANGE_16_G: 2048.0,
}

◆ _gyro_range

_gyro_range = self.GyroRange.RANGE_250_DEG
protected

◆ _GYRO_SCALES

dict _GYRO_SCALES
staticprotected
Initial value:
= {
GyroRange.RANGE_250_DEG: 131.0,
GyroRange.RANGE_500_DEG: 65.5,
GyroRange.RANGE_1000_DEG: 32.8,
GyroRange.RANGE_2000_DEG: 16.4,
}

◆ address

address = address

◆ i2c

i2c = i2c

The documentation for this class was generated from the following file: