Driver for the MPU6050 accelerometer and gyroscope. More...
#include <MPU6050.h>
Public Member Functions | |
MPU6050 () | |
Construct an MPU6050 handler. | |
virtual | ~MPU6050 () |
Destory the class instance. | |
short | getAccelX () const |
Get the X acceleration value. | |
short | getAccelY () const |
Get the Y acceleration value. | |
short | getAccelZ () const |
Get the Z acceleration value. | |
short | getGyroX () const |
Get the X gyroscopic value. | |
short | getGyroY () const |
Get the Y gyroscopic value. | |
short | getGyroZ () const |
Get the Z gyroscopic value. | |
uint32_t | getMagnitude () |
Get the magnitude of the acceleration. More... | |
void | init (gpio_num_t sdaPin=I2C::DEFAULT_SDA_PIN, gpio_num_t clkPin=I2C::DEFAULT_CLK_PIN) |
Initialize the MPU6050. More... | |
void | readAccel () |
Read the acceleration value from the device. More... | |
void | readGyro () |
Read the gyroscopic values from the device. More... | |
Driver for the MPU6050 accelerometer and gyroscope.
The MPU6050 uses I2C as the communication between the master and the slave. The class stores the last read values as class instance local data. The data can be retrieved from the class using the appropriate getters. The readAccel() and readGyro() methods cause communication with the device to retrieve and locally hold the values from the device.
A call to init() must precede all other API calls.
|
inline |
Get the magnitude of the acceleration.
Since acceleration is a vector quantity, it has both direction and magnitude. This method returns the currently known magnitude of the last read data.
void MPU6050::init | ( | gpio_num_t | sdaPin = I2C::DEFAULT_SDA_PIN , |
gpio_num_t | clkPin = I2C::DEFAULT_CLK_PIN |
||
) |
Initialize the MPU6050.
[in] | sdaPin | The GPIO pin to use for I2C SDA. |
[in] | clkPin | The GPIO pin to use for I2C CLK. |
This method must be called before any other methods.
void MPU6050::readAccel | ( | ) |
Read the acceleration value from the device.
Calling this method results in communication with the device to retrieve the acceleration data that is then stored in the class instance ready for retrieval.
void MPU6050::readGyro | ( | ) |
Read the gyroscopic values from the device.
Calling this method results in communication with the device to retrieve the gyroscopic data that is then stored in the class instance ready for retrieval.