COSA
An Object-Oriented Platform for Arduino Programming
MPU6050 Class Reference

#include <MPU6050.hh>

Inheritance diagram for MPU6050:
Inheritance graph
Collaboration diagram for MPU6050:
Collaboration graph

Classes

union  accel_config_t
 
union  config_t
 
union  fifo_en_t
 
union  gyro_config_t
 
union  int_enable_t
 
union  int_pin_cfg_t
 
union  int_status_t
 
struct  motion_t
 
union  pwr_mgmt_1_t
 
union  pwr_mgmt_2_t
 
struct  sample_t
 
union  signal_path_reset_t
 
union  user_ctrl_t
 

Public Member Functions

 MPU6050 (uint8_t subaddr=0)
 
bool begin (uint8_t clksel=CLKSEL_PLL_GYRO_X_REF)
 
bool end ()
 
int16_t read_temperature ()
 
void read_motion (motion_t &m)
 
void read_accelerometer (sample_t &s)
 
void read_gyroscope (sample_t &s)
 

Protected Types

enum  Register {
  SELF_TEST_X = 0x0d, SELF_TEST_Y = 0x0e, SELF_TEST_Z = 0x0f, SELF_TEST_A = 0x10,
  SMPRT_DIV = 0x19, CONFIG = 0x1a, GYRO_CONFIG = 0x1b, ACCEL_CONFIG = 0x1c,
  FIFO_EN = 0x23, I2C_MST_CTRL = 0x24, I2C_SLV0_ADDR = 0x25, I2C_SLV0_REG = 0x26,
  I2C_SLV0_CTRL = 0x27, I2C_SLV1_ADDR = 0x28, I2C_SLV1_REG = 0x29, I2C_SLV1_CTRL = 0x2a,
  I2C_SLV2_ADDR = 0x2b, I2C_SLV2_REG = 0x2c, I2C_SLV2_CTRL = 0x2d, I2C_SLV3_ADDR = 0x2e,
  I2C_SLV3_REG = 0x2f, I2C_SLV3_CTRL = 0x30, I2C_SLV4_ADDR = 0x31, I2C_SLV4_REG = 0x32,
  I2C_SLV4_DO = 0x33, I2C_SLV4_CTRL = 0x34, I2C_SLV4_DI = 0x35, I2C_MST_STATUS = 0x36,
  INT_PIN_CFG = 0x37, INT_ENABLE = 0x38, INT_STATUS = 0x3a, ACCEL_OUT = 0x3b,
  ACCEL_XOUT = 0x3b, ACCEL_XOUT_H = 0x3b, ACCEL_XOUT_L = 0x3c, ACCEL_YOUT = 0x3d,
  ACCEL_YOUT_H = 0x3d, ACCEL_YOUT_L = 0x3e, ACCEL_ZOUT = 0x3f, ACCEL_ZOUT_H = 0x3f,
  ACCEL_ZOUT_L = 0x40, TEMP_OUT = 0x41, TEMP_OUT_H = 0x41, TEMP_OUT_L = 0x42,
  GYRO_OUT = 0x43, GYRO_XOUT = 0x43, GYRO_XOUT_H = 0x43, GYRO_XOUT_L = 0x44,
  GYRO_YOUT = 0x45, GYRO_YOUT_H = 0x45, GYRO_YOUT_L = 0x46, GYRO_ZOUT = 0x47,
  GYRO_ZOUT_H = 0x47, GYRO_ZOUT_L = 0x48, EXT_SENS_DATA = 0x49, I2C_SLV0_DO = 0x63,
  I2C_SLV1_DO = 0x64, I2C_SLV2_DO = 0x65, I2C_SLV3_DO = 0x66, I2C_MST_DELAY_CTRL = 0x67,
  SIGNAL_PATH_RESET = 0x68, USER_CTRL = 0x6a, PWR_MGMT_1 = 0x6b, PWR_MGMT_2 = 0x6c,
  FIFO_COUNT = 0x72, FIFO_COUNT_H = 0x72, FIFO_COUNT_L = 0x73, FIFO_R_W = 0x74,
  WHO_AM_I = 0x75
}
 
enum  { FS_RANGE_250, FS_RANGE_500, FS_RANGE_1000, FS_RANGE_2000 }
 
enum  { AFS_RANGE_2G, AFS_RANGE_4G, AFS_RANGE_8G, AFS_RANGE_16G }
 
enum  {
  CLKSEL_INTERNAL_8MHZ, CLKSEL_PLL_GYRO_X_REF, CLKSEL_PLL_GYRO_Y_REF, CLKSEL_PLL_GYRO_Z_REF,
  CLKSEL_PLL_EXT_32KHZ_REF, CLKSEL_PLL_EXT_19MHZ_REF, CLKSEL_RESERVED, CLKSEL_STOP_CLOCKS
}
 
enum  { LP_WAKE_CTRL_1_25HZ, LP_WAKE_CTRL_5HZ, LP_WAKE_CTRL_20HZ, LP_WAKE_CTRL_40HZ }
 

Protected Member Functions

void write (Register reg, uint8_t value)
 
void write (Register reg, void *buffer, size_t count)
 
uint8_t read (Register reg)
 
void read (Register reg, void *buffer, size_t count)
 

Private Member Functions

bool is_async () const
 
void sync_request ()
 
void async_request ()
 
virtual void on_completion (uint8_t type, int count)
 

Private Attributes

uint8_t m_addr
 
bool m_async
 

Detailed Description

Cosa TWI driver for InvenSense, MPU6050, Motion Processing Unit, 6-axis motion processor solution with gyroscope, accelerator and extended I2C slave bus.

Circuit

The MPU6050 module ITG/MPU with pull-up resistors (4K7) for TWI signals and 3V3 internal voltage converter.

ITG/MPU
+------------+
(VCC)---------------1-|VCC |
(GND)---------------2-|GND |
(A5/SCL)------------3-|SCL |
(A4/SDA)------------4-|SDA |
6-|XDA |
7-|XCL |
8-|AD0 |
9-|INT |
+------------+

References

  1. MPU-6000 and MPU-6050 Register Map and Description, Rev. 4.2. http://invensense.com/mems/gyro/documents/RM-MPU-6000A-00v4.2.pdf

Definition at line 53 of file MPU6050.hh.

Member Enumeration Documentation

anonymous enum
protected

Full scale range of the gyroscope (pp. 14).

Enumerator
FS_RANGE_250 
FS_RANGE_500 
FS_RANGE_1000 
FS_RANGE_2000 

Definition at line 242 of file MPU6050.hh.

anonymous enum
protected

Full scale range of the accelerometer (pp. 15).

Enumerator
AFS_RANGE_2G 
AFS_RANGE_4G 
AFS_RANGE_8G 
AFS_RANGE_16G 

Definition at line 274 of file MPU6050.hh.

anonymous enum
protected

Clock Source (pp. 40).

Enumerator
CLKSEL_INTERNAL_8MHZ 
CLKSEL_PLL_GYRO_X_REF 
CLKSEL_PLL_GYRO_Y_REF 
CLKSEL_PLL_GYRO_Z_REF 
CLKSEL_PLL_EXT_32KHZ_REF 
CLKSEL_PLL_EXT_19MHZ_REF 
CLKSEL_RESERVED 
CLKSEL_STOP_CLOCKS 

Definition at line 447 of file MPU6050.hh.

anonymous enum
protected

Wake-up Frequency (pp. 42).

Enumerator
LP_WAKE_CTRL_1_25HZ 
LP_WAKE_CTRL_5HZ 
LP_WAKE_CTRL_20HZ 
LP_WAKE_CTRL_40HZ 

Definition at line 485 of file MPU6050.hh.

enum MPU6050::Register
protected

Register address map (See chap. 3 Register Map, pp. 6-7).

Enumerator
SELF_TEST_X 

Self Test Registers.

SELF_TEST_Y 

Self Test Registers.

SELF_TEST_Z 

Self Test Registers.

SELF_TEST_A 

Self Test Registers.

SMPRT_DIV 

Sample Rate Divider.

CONFIG 

Configuration.

GYRO_CONFIG 

Gyroscope Configuration.

ACCEL_CONFIG 

Accelerometer Configuration.

FIFO_EN 

FIFO Enable.

I2C_MST_CTRL 

I2C Master Control.

I2C_SLV0_ADDR 

I2C Slave 0 Address.

I2C_SLV0_REG 

I2C Slave 0 Register.

I2C_SLV0_CTRL 

I2C Slave 0 Control.

I2C_SLV1_ADDR 

I2C Slave 1 Address.

I2C_SLV1_REG 

I2C Slave 1 Register.

I2C_SLV1_CTRL 

I2C Slave 1 Control.

I2C_SLV2_ADDR 

I2C Slave 2 Address.

I2C_SLV2_REG 

I2C Slave 2 Register.

I2C_SLV2_CTRL 

I2C Slave 2 Control.

I2C_SLV3_ADDR 

I2C Slave 3 Address.

I2C_SLV3_REG 

I2C Slave 3 Register.

I2C_SLV3_CTRL 

I2C Slave 3 Control.

I2C_SLV4_ADDR 

I2C Slave 4 Address.

I2C_SLV4_REG 

I2C Slave 4 Register.

I2C_SLV4_DO 

I2C Slave 4 Data Out.

I2C_SLV4_CTRL 

I2C Slave 4 Control.

I2C_SLV4_DI 

I2C Slave 4 Data In.

I2C_MST_STATUS 

I2C Master Status.

INT_PIN_CFG 

INT Pin/Bypass Enable Configuration.

INT_ENABLE 

Interrupt Enable.

INT_STATUS 

Interrupt Status.

ACCEL_OUT 

Accelerometer Measurements.

ACCEL_XOUT 

X.

ACCEL_XOUT_H 

X MSB.

ACCEL_XOUT_L 

X LSB.

ACCEL_YOUT 

Y.

ACCEL_YOUT_H 

Y MSB.

ACCEL_YOUT_L 

Y LSB.

ACCEL_ZOUT 

Z.

ACCEL_ZOUT_H 

Z MSB.

ACCEL_ZOUT_L 

Z LSB.

TEMP_OUT 

Temperature Measurement.

TEMP_OUT_H 

Temp MSB.

TEMP_OUT_L 

Temp LSB.

GYRO_OUT 

Gyroscope Measurement.

GYRO_XOUT 

X.

GYRO_XOUT_H 

X MSB.

GYRO_XOUT_L 

X LSB.

GYRO_YOUT 

Y.

GYRO_YOUT_H 

Y MSB.

GYRO_YOUT_L 

Y LSB.

GYRO_ZOUT 

Z.

GYRO_ZOUT_H 

Z MSB.

GYRO_ZOUT_L 

Z LSB.

EXT_SENS_DATA 

External Sensor Data.

I2C_SLV0_DO 

I2C Slave 0 Data Out.

I2C_SLV1_DO 

I2C Slave 1 Data Out.

I2C_SLV2_DO 

I2C Slave 2 Data Out.

I2C_SLV3_DO 

I2C Slave 3 Data Out.

I2C_MST_DELAY_CTRL 

I2C Master Delay Control.

SIGNAL_PATH_RESET 

Signal Path Reset.

USER_CTRL 

User Control.

PWR_MGMT_1 

Power Management 1.

PWR_MGMT_2 

Power Management 2.

FIFO_COUNT 

FIFO Count Registers.

FIFO_COUNT_H 

FIFO Count Registers MSB.

FIFO_COUNT_L 

FIFO Count Registers LSB.

FIFO_R_W 

FIFO Read Write.

WHO_AM_I 

Who Am I.

Definition at line 125 of file MPU6050.hh.

Constructor & Destructor Documentation

MPU6050::MPU6050 ( uint8_t  subaddr = 0)
inline

Construct MPU6050 digital gyroscope driver with given sub-address. Default is zero(0).

Parameters
[in]subaddrsub-address (0..1, default 0)

Definition at line 60 of file MPU6050.hh.

Member Function Documentation

bool MPU6050::begin ( uint8_t  clksel = CLKSEL_PLL_GYRO_X_REF)

Start interaction with device. Turn on measurements.

Parameters
[in]clkselclock source (default PLL with X axis gyroscope)
Returns
true(1) if successful otherwise false(0)

Definition at line 60 of file MPU6050.cpp.

bool MPU6050::end ( )

Stop sequence of interaction with device. Turn off measurements and power down.

Returns
true(1) if successful otherwise false(0)

Definition at line 84 of file MPU6050.cpp.

uint8_t MPU6050::read ( Register  reg)
protected

Read contents of register.

Parameters
[in]regregister address.
Returns
register value.

Definition at line 40 of file MPU6050.cpp.

void MPU6050::read ( Register  reg,
void *  buffer,
size_t  count 
)
protected

Read contents of registers, multiple values from give address.

Parameters
[in]regregister address.
[in]bufferstorage.
[in]countnumber of bytes.

Definition at line 51 of file MPU6050.cpp.

void MPU6050::read_accelerometer ( sample_t s)

Read accelerometer and return values in given sample data structure.

Parameters
[in,out]ssample storage.

Definition at line 106 of file MPU6050.cpp.

void MPU6050::read_gyroscope ( sample_t s)

Read gyroscope and return values in given data structure

Parameters
[in,out]ssample storage.

Definition at line 113 of file MPU6050.cpp.

void MPU6050::read_motion ( motion_t m)

Read accelerometer and return values in given sample data structure.

Parameters
[in,out]msamples storage.

Definition at line 98 of file MPU6050.cpp.

int16_t MPU6050::read_temperature ( )

Read temperature and return value in scale 0.1 Celcius.

Returns
temperature

Definition at line 90 of file MPU6050.cpp.

void MPU6050::write ( Register  reg,
uint8_t  value 
)
protected

Write given value to register.

Parameters
[in]regregister address.
[in]valueregister value.

Definition at line 24 of file MPU6050.cpp.

void MPU6050::write ( Register  reg,
void *  buffer,
size_t  count 
)
protected

Write multiple registers with values from give address.

Parameters
[in]regregister address.
[in]bufferstorage.
[in]countnumber of bytes.

Definition at line 32 of file MPU6050.cpp.


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