Adafruit MPU6050 Sensor Library
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
Adafruit_MPU6050 Class Referencefinal

Class that stores state and functions for interacting with the MPU6050 I2C Digital Potentiometer. More...

#include <Adafruit_MPU6050.h>

Public Member Functions

 Adafruit_MPU6050 ()
 Instantiates a new MPU6050 class.
 
 ~Adafruit_MPU6050 ()
 Cleans up the MPU6050 class.
 
bool begin (uint8_t i2c_addr=MPU6050_I2CADDR_DEFAULT, TwoWire *wire=&Wire, int32_t sensorID=0)
 Sets up the hardware and initializes I2C. More...
 
bool getEvent (sensors_event_t *accel, sensors_event_t *gyro, sensors_event_t *temp)
 Gets the most recent sensor event, Adafruit Unified Sensor format. More...
 
mpu6050_accel_range_t getAccelerometerRange (void)
 Gets the acceleration measurement range. More...
 
void setAccelerometerRange (mpu6050_accel_range_t)
 Sets the accelerometer measurement range. More...
 
mpu6050_gyro_range_t getGyroRange (void)
 Gets the gyroscope measurement range. More...
 
void setGyroRange (mpu6050_gyro_range_t)
 Sets the gyroscope measurement range. More...
 
void setInterruptPinPolarity (bool active_low)
 Sets the polarity of the INT pin when active. More...
 
void setInterruptPinLatch (bool held)
 Sets the latch behavior of the INT pin when active. More...
 
void setFsyncSampleOutput (mpu6050_fsync_out_t fsync_output)
 Sets the location that the FSYNC pin sample is stored. More...
 
mpu6050_highpass_t getHighPassFilter (void)
 Gets bandwidth of the Digital High Pass Filter. More...
 
void setHighPassFilter (mpu6050_highpass_t bandwidth)
 Sets the bandwidth of the Digital High-Pass Filter. More...
 
void setMotionInterrupt (bool active)
 Sets the motion interrupt. More...
 
void setMotionDetectionThreshold (uint8_t thr)
 Sets the motion detection threshold. More...
 
void setMotionDetectionDuration (uint8_t dur)
 Sets the motion detection duration. More...
 
bool getMotionInterruptStatus (void)
 Gets motion interrupt status. More...
 
mpu6050_fsync_out_t getFsyncSampleOutput (void)
 Sets the location that the FSYNC pin sample is stored. More...
 
void setI2CBypass (bool bypass)
 Connects or disconects the I2C master pins to the main I2C pins. More...
 
void setClock (mpu6050_clock_select_t)
 Sets clock source. More...
 
mpu6050_clock_select_t getClock (void)
 Gets clock source. More...
 
void setFilterBandwidth (mpu6050_bandwidth_t bandwidth)
 Sets the bandwidth of the Digital Low-Pass Filter. More...
 
mpu6050_bandwidth_t getFilterBandwidth (void)
 Gets bandwidth of the Digital Low Pass Filter. More...
 
void setSampleRateDivisor (uint8_t)
 Sets the divisor used to divide the base clock rate into a measurement rate. More...
 
uint8_t getSampleRateDivisor (void)
 Gets the sample rate divisor. More...
 
bool enableSleep (bool enable)
 Controls the sleep state of the sensor. More...
 
bool enableCycle (bool enable)
 Controls sensor's 'Cycle' measurement mode. More...
 
void setCycleRate (mpu6050_cycle_rate_t rate)
 Sets the frequency of measurement in 'Cycle' mode. More...
 
mpu6050_cycle_rate_t getCycleRate (void)
 Gets the frequencey of measurements in 'Cycle' mode. More...
 
bool setGyroStandby (bool xAxisStandby, bool yAxisStandby, bool zAxisStandby)
 Sets standbye mode for each of the gyroscope axes. More...
 
bool setAccelerometerStandby (bool xAxisStandby, bool yAxisStandby, bool zAxisStandby)
 Sets standbye mode for each of the accelerometer axes. More...
 
bool setTemperatureStandby (bool enable)
 Sets disable mode for thermometer sensor. More...
 
void reset (void)
 Resets registers to their initial value and resets the sensors' analog and digital signal paths.
 
Adafruit_Sensor * getTemperatureSensor (void)
 Gets an Adafruit Unified Sensor object for the temp sensor component. More...
 
Adafruit_Sensor * getAccelerometerSensor (void)
 Gets an Adafruit Unified Sensor object for the accelerometer sensor component. More...
 
Adafruit_Sensor * getGyroSensor (void)
 Gets an Adafruit Unified Sensor object for the gyro sensor component. More...
 

Protected Member Functions

void _read (void)
 Updates the measurement data for all sensors simultaneously.
 
virtual bool _init (int32_t sensor_id)
 Initilizes the sensor. More...
 

Protected Attributes

float temperature
 Last reading's temperature (C)
 
float accX
 Last reading's accelerometer X axis m/s^2.
 
float accY
 Last reading's accelerometer Y axis m/s^2.
 
float accZ
 Last reading's accelerometer Z axis m/s^2.
 
float gyroX
 Last reading's gyro X axis in rad/s.
 
float gyroY
 Last reading's gyro Y axis in rad/s.
 
float gyroZ
 Last reading's gyro Z axis in rad/s.
 
Adafruit_I2CDevice * i2c_dev = NULL
 Pointer to I2C bus interface.
 
Adafruit_MPU6050_Temptemp_sensor = NULL
 Temp sensor data object.
 
Adafruit_MPU6050_Accelerometeraccel_sensor
 Accelerometer data object. More...
 
Adafruit_MPU6050_Gyrogyro_sensor = NULL
 Gyro data object.
 
uint16_t _sensorid_accel
 ID number for accelerometer.
 
uint16_t _sensorid_gyro
 ID number for gyro.
 
uint16_t _sensorid_temp
 ID number for temperature.
 

Friends

class Adafruit_MPU6050_Temp
 
class Adafruit_MPU6050_Accelerometer
 
class Adafruit_MPU6050_Gyro
 

Detailed Description

Class that stores state and functions for interacting with the MPU6050 I2C Digital Potentiometer.

Member Function Documentation

◆ begin()

bool Adafruit_MPU6050::begin ( uint8_t  i2c_address = MPU6050_I2CADDR_DEFAULT,
TwoWire *  wire = &Wire,
int32_t  sensor_id = 0 
)

Sets up the hardware and initializes I2C.

Parameters
i2c_addressThe I2C address to be used.
wireThe Wire object to be used for I2C connections.
sensor_idThe user-defined ID to differentiate different sensors
Returns
True if initialization was successful, otherwise false.

◆ getEvent()

bool Adafruit_MPU6050::getEvent ( sensors_event_t *  accel,
sensors_event_t *  gyro,
sensors_event_t *  temp 
)

Gets the most recent sensor event, Adafruit Unified Sensor format.

Parameters
accelPointer to an Adafruit Unified sensor_event_t object to be filled with acceleration event data.
gyroPointer to an Adafruit Unified sensor_event_t object to be filled with gyroscope event data.
tempPointer to an Adafruit Unified sensor_event_t object to be filled with temperature event data.
Returns
True on successful read

◆ getAccelerometerRange()

mpu6050_accel_range_t Adafruit_MPU6050::getAccelerometerRange ( void  )

Gets the acceleration measurement range.

Returns
The acceleration measurement range

◆ setAccelerometerRange()

void Adafruit_MPU6050::setAccelerometerRange ( mpu6050_accel_range_t  new_range)

Sets the accelerometer measurement range.

Parameters
new_rangeThe new range to set. Must be a mpu6050_accel_range_t

◆ getGyroRange()

mpu6050_gyro_range_t Adafruit_MPU6050::getGyroRange ( void  )

Gets the gyroscope measurement range.

Returns
The mpu6050_gyro_range_t gyroscope measurement range

◆ setGyroRange()

void Adafruit_MPU6050::setGyroRange ( mpu6050_gyro_range_t  new_range)

Sets the gyroscope measurement range.

Parameters
new_rangeThe new range to set. Must be a mpu6050_gyro_range_t

◆ setInterruptPinPolarity()

void Adafruit_MPU6050::setInterruptPinPolarity ( bool  active_low)

Sets the polarity of the INT pin when active.

Parameters
active_lowIf true the pin will be low when an interrupt is active If false the pin will be high when an interrupt is active

◆ setInterruptPinLatch()

void Adafruit_MPU6050::setInterruptPinLatch ( bool  held)

Sets the latch behavior of the INT pin when active.

Parameters
heldIf true the pin will remain held until cleared If false the pin will reset after a 50us pulse

◆ setFsyncSampleOutput()

void Adafruit_MPU6050::setFsyncSampleOutput ( mpu6050_fsync_out_t  fsync_output)

Sets the location that the FSYNC pin sample is stored.

Parameters
fsync_outputa mpu6050_fsync_out_t to specify the LSB of which data register should be used to store the state of the FSYNC pin

◆ getHighPassFilter()

mpu6050_highpass_t Adafruit_MPU6050::getHighPassFilter ( void  )

Gets bandwidth of the Digital High Pass Filter.

Returns
The current mpu6050_highpass_t filter bandwidth

◆ setHighPassFilter()

void Adafruit_MPU6050::setHighPassFilter ( mpu6050_highpass_t  bandwidth)

Sets the bandwidth of the Digital High-Pass Filter.

Parameters
bandwidththe new mpu6050_highpass_t bandwidth

◆ setMotionInterrupt()

void Adafruit_MPU6050::setMotionInterrupt ( bool  active)

Sets the motion interrupt.

Parameters
activeIf true motion interrupt will activate based on thr and dur If false motion interrupt will be disabled

◆ setMotionDetectionThreshold()

void Adafruit_MPU6050::setMotionDetectionThreshold ( uint8_t  thr)

Sets the motion detection threshold.

Parameters
thr

◆ setMotionDetectionDuration()

void Adafruit_MPU6050::setMotionDetectionDuration ( uint8_t  dur)

Sets the motion detection duration.

Parameters
dur

◆ getMotionInterruptStatus()

bool Adafruit_MPU6050::getMotionInterruptStatus ( void  )

Gets motion interrupt status.

Returns
motion_interrupt

◆ getFsyncSampleOutput()

mpu6050_fsync_out_t Adafruit_MPU6050::getFsyncSampleOutput ( void  )

Sets the location that the FSYNC pin sample is stored.

Returns
fsync_output

◆ setI2CBypass()

void Adafruit_MPU6050::setI2CBypass ( bool  bypass)

Connects or disconects the I2C master pins to the main I2C pins.

Parameters
bypassIf true the I2C Master pins are connected to the main I2C pins, bypassing the I2C Master functions of the sensor If false the I2C Master pins are controlled by the I2C master functions of the sensor

◆ setClock()

void Adafruit_MPU6050::setClock ( mpu6050_clock_select_t  new_clock)

Sets clock source.

Parameters
new_clockThe clock source to set. Must be a mpu6050_clock_select_t

◆ getClock()

mpu6050_clock_select_t Adafruit_MPU6050::getClock ( void  )

Gets clock source.

Returns
The current mpu6050_clock_select_t clock source

◆ setFilterBandwidth()

void Adafruit_MPU6050::setFilterBandwidth ( mpu6050_bandwidth_t  bandwidth)

Sets the bandwidth of the Digital Low-Pass Filter.

Parameters
bandwidththe new mpu6050_bandwidth_t bandwidth

◆ getFilterBandwidth()

mpu6050_bandwidth_t Adafruit_MPU6050::getFilterBandwidth ( void  )

Gets bandwidth of the Digital Low Pass Filter.

Returns
The current mpu6050_bandwidth_t filter bandwidth

◆ setSampleRateDivisor()

void Adafruit_MPU6050::setSampleRateDivisor ( uint8_t  divisor)

Sets the divisor used to divide the base clock rate into a measurement rate.

Parameters
divisorThe new clock divisor

◆ getSampleRateDivisor()

uint8_t Adafruit_MPU6050::getSampleRateDivisor ( void  )

Gets the sample rate divisor.

Returns
The sample rate divisor

◆ enableSleep()

bool Adafruit_MPU6050::enableSleep ( bool  enable)

Controls the sleep state of the sensor.

Parameters
enableIf true the sensor is put into a low power state and measurements are halted until sleep mode is deactivated Setting false wakes up the sensor from sleep mode, resuming measurements.
Returns
True or false on successful write

◆ enableCycle()

bool Adafruit_MPU6050::enableCycle ( bool  enable)

Controls sensor's 'Cycle' measurement mode.

Parameters
enableIf true the sensor will take measurements at the rate set by calling setCycleRate, sleeping between measurements. Setting the sensor into 'Cycle' mode will have no effect if the sensor has been put into a sleep state with enableSleep Setting false returns the sensor to the normal measurement mode.
Returns
True or false on successful write

◆ setCycleRate()

void Adafruit_MPU6050::setCycleRate ( mpu6050_cycle_rate_t  rate)

Sets the frequency of measurement in 'Cycle' mode.

Parameters
rateThe mpu6050_cycle_rate_t specifying the desired measurement rate

◆ getCycleRate()

mpu6050_cycle_rate_t Adafruit_MPU6050::getCycleRate ( void  )

Gets the frequencey of measurements in 'Cycle' mode.

Returns
The current 'Cycle' measurement frequency

◆ setGyroStandby()

bool Adafruit_MPU6050::setGyroStandby ( bool  xAxisStandby,
bool  yAxisStandby,
bool  zAxisStandby 
)

Sets standbye mode for each of the gyroscope axes.

Parameters
xAxisStandbyIf true the gyroscope stops sensing in the X-axis. Setting false resumes X-axis sensing.
yAxisStandbyIf true the gyroscope stops sensing in the Y-axis. Setting false resumes Y-axis sensing.
zAxisStandbyIf true the gyroscope stops sensing in the Z-axis. Setting false resumes Z-axis sensing.
Returns
True if setting was successful, otherwise false.

◆ setAccelerometerStandby()

bool Adafruit_MPU6050::setAccelerometerStandby ( bool  xAxisStandby,
bool  yAxisStandby,
bool  zAxisStandby 
)

Sets standbye mode for each of the accelerometer axes.

Parameters
xAxisStandbyIf true the accelerometer stops sensing in the X-axis. Setting false resumes X-axis sensing.
yAxisStandbyIf true the accelerometer stops sensing in the Y-axis. Setting false resumes Y-axis sensing.
zAxisStandbyIf true the accelerometer stops sensing in the Z-axis. Setting false resumes Z-axis sensing.
Returns
True if setting was successful, otherwise false.

◆ setTemperatureStandby()

bool Adafruit_MPU6050::setTemperatureStandby ( bool  enable)

Sets disable mode for thermometer sensor.

Parameters
enableIf true the temperature sensor will stop taking measurements. Setting false returns the temperature sensor to the normal measurement mode.
Returns
True if setting was successful, otherwise false.

◆ getTemperatureSensor()

Adafruit_Sensor * Adafruit_MPU6050::getTemperatureSensor ( void  )

Gets an Adafruit Unified Sensor object for the temp sensor component.

Returns
Adafruit_Sensor pointer to temperature sensor

◆ getAccelerometerSensor()

Adafruit_Sensor * Adafruit_MPU6050::getAccelerometerSensor ( void  )

Gets an Adafruit Unified Sensor object for the accelerometer sensor component.

Returns
Adafruit_Sensor pointer to accelerometer sensor

◆ getGyroSensor()

Adafruit_Sensor * Adafruit_MPU6050::getGyroSensor ( void  )

Gets an Adafruit Unified Sensor object for the gyro sensor component.

Returns
Adafruit_Sensor pointer to gyro sensor

◆ _init()

bool Adafruit_MPU6050::_init ( int32_t  sensor_id)
protectedvirtual

Initilizes the sensor.

Parameters
sensor_idOptional unique ID for the sensor set
Returns
True if chip identified and initialized

Friends And Related Function Documentation

◆ Adafruit_MPU6050_Temp

friend class Adafruit_MPU6050_Temp
friend

Gives access to private members to Temp data object

◆ Adafruit_MPU6050_Accelerometer

friend class Adafruit_MPU6050_Accelerometer
friend

Gives access to private members to Accelerometer data object

◆ Adafruit_MPU6050_Gyro

friend class Adafruit_MPU6050_Gyro
friend

Gives access to private members to Gyro data object

Member Data Documentation

◆ accel_sensor

Adafruit_MPU6050_Accelerometer* Adafruit_MPU6050::accel_sensor
protected
Initial value:
=
NULL

Accelerometer data object.


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