imu for l432kc

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

MPU6050 Class Reference

MPU6050 Class Reference

MPU6050 IMU library. More...

#include <MPU6050.h>

Public Member Functions

 MPU6050 (PinName sda, PinName scl)
 Constructor.
bool testConnection (void)
 Tests the I2C connection by reading the WHO_AM_I register.
void setBW (char BW)
 Sets the bandwidth of the digital low-pass filter.
void setI2CBypass (bool state)
 Sets the auxiliary I2C bus in bypass mode to read the sensors behind the MPU6050 (useful for eval board, otherwise just connect them to primary I2C bus)
void setAcceleroRange (char range)
 Sets the Accelero full-scale range.
int getAcceleroRawX (void)
 Reads the accelero x-axis.
int getAcceleroRawY (void)
 Reads the accelero y-axis.
int getAcceleroRawZ (void)
 Reads the accelero z-axis.
void getAcceleroRaw (int *data)
 Reads all accelero data.
void getAccelero (float *data)
 Reads all accelero data, gives the acceleration in m/s2.
void setGyroRange (char range)
 Sets the Gyro full-scale range.
int getGyroRawX (void)
 Reads the gyro x-axis.
int getGyroRawY (void)
 Reads the gyro y-axis.
int getGyroRawZ (void)
 Reads the gyro z-axis.
void getGyroRaw (int *data)
 Reads all gyro data.
void getGyro (float *data)
 Reads all gyro data, gives the gyro in rad/s.
int getTempRaw (void)
 Reads temperature data.
float getTemp (void)
 Returns current temperature.
void setSleepMode (bool state)
 Sets the sleep mode of the MPU6050.
void write (char address, char data)
 Writes data to the device, could be private, but public is handy so you can transmit directly to the MPU.
char read (char adress)
 Read data from the device, could be private, but public is handy so you can transmit directly to the MPU.
void read (char adress, char *data, int length)
 Read multtiple regigsters from the device, more efficient than using multiple normal reads.
bool I2C_finder ()
 Find all I2C devices and print all devices I2C + update MPU6050_ADDRESS (choice between 0x68 and 0X69)

Detailed Description

MPU6050 IMU library.

Example:

 Later, maybe

Definition at line 86 of file MPU6050.h.


Constructor & Destructor Documentation

MPU6050 ( PinName  sda,
PinName  scl 
)

Constructor.

Includes.

Sleep mode of MPU6050 is immediatly disabled

Parameters:
sda- mbed pin to use for the SDA I2C line.
scl- mbed pin to use for the SCL I2C line.

Definition at line 6 of file MPU6050.cpp.


Member Function Documentation

void getAccelero ( float *  data )

Reads all accelero data, gives the acceleration in m/s2.

Function uses the last setup value of the full scale range, if you manually set in another range, this won't work.

Parameters:
data- pointer to float array with length three: data[0] = X, data[1] = Y, data[2] = Z

Definition at line 158 of file MPU6050.cpp.

void getAcceleroRaw ( int *  data )

Reads all accelero data.

Parameters:
data- pointer to signed integer array with length three: data[0] = X, data[1] = Y, data[2] = Z

Definition at line 150 of file MPU6050.cpp.

int getAcceleroRawX ( void   )

Reads the accelero x-axis.

Returns:
16-bit signed integer x-axis accelero data

Definition at line 126 of file MPU6050.cpp.

int getAcceleroRawY ( void   )

Reads the accelero y-axis.

Returns:
16-bit signed integer y-axis accelero data

Definition at line 134 of file MPU6050.cpp.

int getAcceleroRawZ ( void   )

Reads the accelero z-axis.

Returns:
16-bit signed integer z-axis accelero data

Definition at line 142 of file MPU6050.cpp.

void getGyro ( float *  data )

Reads all gyro data, gives the gyro in rad/s.

Function uses the last setup value of the full scale range, if you manually set in another range, this won't work.

Parameters:
data- pointer to float array with length three: data[0] = X, data[1] = Y, data[2] = Z

Definition at line 234 of file MPU6050.cpp.

void getGyroRaw ( int *  data )

Reads all gyro data.

Parameters:
data- pointer to signed integer array with length three: data[0] = X, data[1] = Y, data[2] = Z

Definition at line 226 of file MPU6050.cpp.

int getGyroRawX ( void   )

Reads the gyro x-axis.

Returns:
16-bit signed integer x-axis gyro data

Definition at line 202 of file MPU6050.cpp.

int getGyroRawY ( void   )

Reads the gyro y-axis.

Returns:
16-bit signed integer y-axis gyro data

Definition at line 210 of file MPU6050.cpp.

int getGyroRawZ ( void   )

Reads the gyro z-axis.

Returns:
16-bit signed integer z-axis gyro data

Definition at line 218 of file MPU6050.cpp.

float getTemp ( void   )

Returns current temperature.

Returns:
float with the current temperature

Definition at line 269 of file MPU6050.cpp.

int getTempRaw ( void   )

Reads temperature data.

Returns:
16 bit signed integer with the raw temperature register value

Definition at line 261 of file MPU6050.cpp.

bool I2C_finder (  )

Find all I2C devices and print all devices I2C + update MPU6050_ADDRESS (choice between 0x68 and 0X69)

Definition at line 35 of file MPU6050.cpp.

void read ( char  adress,
char *  data,
int  length 
)

Read multtiple regigsters from the device, more efficient than using multiple normal reads.

Parameters:
adress- register address to write to
length- number of bytes to read
data- pointer where the data needs to be written to

Definition at line 70 of file MPU6050.cpp.

char read ( char  adress )

Read data from the device, could be private, but public is handy so you can transmit directly to the MPU.

Parameters:
adress- register address to write to
Returns:
- data from the register specified by RA

Definition at line 63 of file MPU6050.cpp.

void setAcceleroRange ( char  range )

Sets the Accelero full-scale range.

Macros: MPU6050_ACCELERO_RANGE_2G - MPU6050_ACCELERO_RANGE_4G - MPU6050_ACCELERO_RANGE_8G - MPU6050_ACCELERO_RANGE_16G

Parameters:
range- The two bits that set the full-scale range (use the predefined macros)

Definition at line 115 of file MPU6050.cpp.

void setBW ( char  BW )

Sets the bandwidth of the digital low-pass filter.

Macros: MPU6050_BW_256 - MPU6050_BW_188 - MPU6050_BW_98 - MPU6050_BW_42 - MPU6050_BW_20 - MPU6050_BW_10 - MPU6050_BW_5 Last number is the gyro's BW in Hz (accelero BW is virtually identical)

Parameters:
BW- The three bits that set the bandwidth (use the predefined macros)

Definition at line 92 of file MPU6050.cpp.

void setGyroRange ( char  range )

Sets the Gyro full-scale range.

Macros: MPU6050_GYRO_RANGE_250 - MPU6050_GYRO_RANGE_500 - MPU6050_GYRO_RANGE_1000 - MPU6050_GYRO_RANGE_2000

Parameters:
range- The two bits that set the full-scale range (use the predefined macros)

Definition at line 192 of file MPU6050.cpp.

void setI2CBypass ( bool  state )

Sets the auxiliary I2C bus in bypass mode to read the sensors behind the MPU6050 (useful for eval board, otherwise just connect them to primary I2C bus)

Parameters:
state- Enables/disables the I2C bypass mode

Definition at line 101 of file MPU6050.cpp.

void setSleepMode ( bool  state )

Sets the sleep mode of the MPU6050.

Parameters:
state- true for sleeping, false for wake up

Definition at line 75 of file MPU6050.cpp.

bool testConnection ( void   )

Tests the I2C connection by reading the WHO_AM_I register.

Returns:
True for a working connection, false for an error

Definition at line 85 of file MPU6050.cpp.

void write ( char  address,
char  data 
)

Writes data to the device, could be private, but public is handy so you can transmit directly to the MPU.

Parameters:
adress- register address to write to
data- data to write

Definition at line 55 of file MPU6050.cpp.