Adafruit ICM20X Sensor Library
|
Class that stores state and functions for interacting with the ST ICM20X 6-DoF Accelerometer and Gyro. More...
#include <Adafruit_ICM20X.h>
Public Member Functions | |
Adafruit_ICM20X () | |
Instantiates a new ICM20X class! | |
~Adafruit_ICM20X () | |
Cleans up the ICM20X. | |
bool | begin_SPI (uint8_t cs_pin, SPIClass *theSPI=&SPI, int32_t sensor_id=0) |
Sets up the hardware and initializes hardware SPI. More... | |
bool | begin_SPI (int8_t cs_pin, int8_t sck_pin, int8_t miso_pin, int8_t mosi_pin, int32_t sensor_id=0) |
Sets up the hardware and initializes software SPI. More... | |
uint8_t | getGyroRateDivisor (void) |
Get the gyro's data rate divisor. More... | |
void | setGyroRateDivisor (uint8_t new_gyro_divisor) |
Sets the gyro's data rate divisor. More... | |
uint16_t | getAccelRateDivisor (void) |
Get the accelerometer's data rate divisor. More... | |
void | setAccelRateDivisor (uint16_t new_accel_divisor) |
Sets the accelerometer's data rate divisor. More... | |
bool | enableAccelDLPF (bool enable, icm20x_accel_cutoff_t cutoff_freq) |
Enable or disable the accelerometer's Digital Low Pass Filter. More... | |
bool | enableGyrolDLPF (bool enable, icm20x_gyro_cutoff_t cutoff_freq) |
Enable or disable the gyro's Digital Low Pass Filter. More... | |
void | reset (void) |
Reset the internal registers and restores the default settings. | |
void | setInt1ActiveLow (bool active_low) |
Sets the polarity of the int1 pin. More... | |
void | setInt2ActiveLow (bool active_low) |
Sets the polarity of the INT2 pin. 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... | |
Adafruit_Sensor * | getMagnetometerSensor (void) |
Gets an Adafruit Unified Sensor object for the magnetometer sensor component. More... | |
Adafruit_Sensor * | getTemperatureSensor (void) |
Gets an Adafruit Unified Sensor object for the temp sensor component. More... | |
bool | getEvent (sensors_event_t *accel, sensors_event_t *gyro, sensors_event_t *temp, sensors_event_t *mag=NULL) |
Gets the most recent sensor event, Adafruit Unified Sensor format. More... | |
uint8_t | readExternalRegister (uint8_t slv_addr, uint8_t reg_addr) |
Read a single byte from a given register address for an I2C slave device on the auxiliary I2C bus. More... | |
bool | writeExternalRegister (uint8_t slv_addr, uint8_t reg_addr, uint8_t value) |
Write a single byte to a given register address for an I2C slave device on the auxiliary I2C bus. More... | |
bool | configureI2CMaster (void) |
Set the I2C clock rate for the auxillary I2C bus to 345.60kHz and disable repeated start. More... | |
bool | enableI2CMaster (bool enable_i2c_master) |
Enable or disable the I2C mastercontroller. More... | |
void | resetI2CMaster (void) |
Reset the I2C master. | |
void | setI2CBypass (bool bypass_i2c) |
Sets the bypass status of the I2C master bus support. More... | |
Protected Member Functions | |
void | _read (void) |
Updates the measurement data for all sensors simultaneously. | |
virtual void | scaleValues (void) |
Scales the raw variables based on the current measurement range. | |
virtual bool | begin_I2C (uint8_t i2c_add, TwoWire *wire, int32_t sensor_id) |
Sets up the hardware and initializes I2C. More... | |
bool | _init (int32_t sensor_id) |
Initilizes the sensor. More... | |
void | _setBank (uint8_t bank_number) |
Sets register bank. More... | |
uint8_t | readAccelRange (void) |
Get the accelerometer's measurement range. More... | |
void | writeAccelRange (uint8_t new_accel_range) |
Sets the accelerometer's measurement range. More... | |
uint8_t | readGyroRange (void) |
Get the gyro's measurement range. More... | |
void | writeGyroRange (uint8_t new_gyro_range) |
Sets the gyro's measurement range. 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. | |
float | magX |
Last reading's mag X axis in rad/s. | |
float | magY |
Last reading's mag Y axis in rad/s. | |
float | magZ |
Last reading's mag Z axis in rad/s. | |
Adafruit_I2CDevice * | i2c_dev = NULL |
Pointer to I2C bus interface. | |
Adafruit_SPIDevice * | spi_dev = NULL |
Pointer to SPI bus interface. | |
Adafruit_ICM20X_Accelerometer * | accel_sensor |
Accelerometer data object. More... | |
Adafruit_ICM20X_Gyro * | gyro_sensor = NULL |
Gyro data object. | |
Adafruit_ICM20X_Magnetometer * | mag_sensor |
Magnetometer sensor data object. More... | |
Adafruit_ICM20X_Temp * | temp_sensor = NULL |
Temp sensor data object. | |
uint16_t | _sensorid_accel |
ID number for accelerometer. | |
uint16_t | _sensorid_gyro |
ID number for gyro. | |
uint16_t | _sensorid_mag |
ID number for mag. | |
uint16_t | _sensorid_temp |
ID number for temperature. | |
int16_t | rawAccX |
temp variables | |
int16_t | rawAccY |
temp variables | |
int16_t | rawAccZ |
temp variables | |
int16_t | rawTemp |
temp variables | |
int16_t | rawGyroX |
temp variables | |
int16_t | rawGyroY |
temp variables | |
int16_t | rawGyroZ |
temp variables | |
int16_t | rawMagX |
temp variables | |
int16_t | rawMagY |
temp variables | |
int16_t | rawMagZ |
temp variables | |
uint8_t | current_accel_range |
accelerometer range cache | |
uint8_t | current_gyro_range |
gyro range cache | |
Friends | |
class | Adafruit_ICM20X_Accelerometer |
class | Adafruit_ICM20X_Gyro |
class | Adafruit_ICM20X_Magnetometer |
class | Adafruit_ICM20X_Temp |
Class that stores state and functions for interacting with the ST ICM20X 6-DoF Accelerometer and Gyro.
bool Adafruit_ICM20X::begin_SPI | ( | uint8_t | cs_pin, |
SPIClass * | theSPI = &SPI , |
||
int32_t | sensor_id = 0 |
||
) |
Sets up the hardware and initializes hardware SPI.
cs_pin | The arduino pin # connected to chip select |
theSPI | The SPI object to be used for SPI connections. |
sensor_id | An optional parameter to set the sensor ids to differentiate similar sensors The passed value is assigned to the accelerometer, the gyro gets +1, the magnetometer +2, and the temperature sensor +3. |
bool Adafruit_ICM20X::begin_SPI | ( | int8_t | cs_pin, |
int8_t | sck_pin, | ||
int8_t | miso_pin, | ||
int8_t | mosi_pin, | ||
int32_t | sensor_id = 0 |
||
) |
Sets up the hardware and initializes software SPI.
cs_pin | The arduino pin # connected to chip select |
sck_pin | The arduino pin # connected to SPI clock |
miso_pin | The arduino pin # connected to SPI MISO |
mosi_pin | The arduino pin # connected to SPI MOSI |
sensor_id | An optional parameter to set the sensor ids to differentiate similar sensors The passed value is assigned to the accelerometer, the gyro gets +1, the magnetometer +2, and the temperature sensor +3. |
uint8_t Adafruit_ICM20X::getGyroRateDivisor | ( | void | ) |
Get the gyro's data rate divisor.
uint8_t
). void Adafruit_ICM20X::setGyroRateDivisor | ( | uint8_t | new_gyro_divisor | ) |
Sets the gyro's data rate divisor.
new_gyro_divisor | The gyro's data rate divisor (uint8_t ). |
uint16_t Adafruit_ICM20X::getAccelRateDivisor | ( | void | ) |
Get the accelerometer's data rate divisor.
uint8_t
). void Adafruit_ICM20X::setAccelRateDivisor | ( | uint16_t | new_accel_divisor | ) |
Sets the accelerometer's data rate divisor.
new_accel_divisor | The accelerometer's data rate divisor (uint16_t ). This 12-bit value must be <= 4095 |
bool Adafruit_ICM20X::enableAccelDLPF | ( | bool | enable, |
icm20x_accel_cutoff_t | cutoff_freq | ||
) |
Enable or disable the accelerometer's Digital Low Pass Filter.
enable | true: enable false: disable |
cutoff_freq | Signals changing at a rate higher than the given cutoff frequency will be filtered out |
bool Adafruit_ICM20X::enableGyrolDLPF | ( | bool | enable, |
icm20x_gyro_cutoff_t | cutoff_freq | ||
) |
Enable or disable the gyro's Digital Low Pass Filter.
enable | true: enable false: disable |
cutoff_freq | Signals changing at a rate higher than the given cutoff frequency will be filtered out |
void Adafruit_ICM20X::setInt1ActiveLow | ( | bool | active_low | ) |
Sets the polarity of the int1 pin.
active_low | Set to true to make INT1 active low, false to make it active high |
void Adafruit_ICM20X::setInt2ActiveLow | ( | bool | active_low | ) |
Sets the polarity of the INT2 pin.
active_low | Set to true to make INT1 active low, false to make it active high |
Adafruit_Sensor * Adafruit_ICM20X::getAccelerometerSensor | ( | void | ) |
Gets an Adafruit Unified Sensor object for the accelerometer sensor component.
Adafruit_Sensor * Adafruit_ICM20X::getGyroSensor | ( | void | ) |
Gets an Adafruit Unified Sensor object for the gyro sensor component.
Adafruit_Sensor * Adafruit_ICM20X::getMagnetometerSensor | ( | void | ) |
Gets an Adafruit Unified Sensor object for the magnetometer sensor component.
Adafruit_Sensor * Adafruit_ICM20X::getTemperatureSensor | ( | void | ) |
Gets an Adafruit Unified Sensor object for the temp sensor component.
bool Adafruit_ICM20X::getEvent | ( | sensors_event_t * | accel, |
sensors_event_t * | gyro, | ||
sensors_event_t * | temp, | ||
sensors_event_t * | mag = NULL |
||
) |
Gets the most recent sensor event, Adafruit Unified Sensor format.
accel | Pointer to an Adafruit Unified sensor_event_t object to be filled with acceleration event data. |
gyro | Pointer to an Adafruit Unified sensor_event_t object to be filled with gyro event data. |
mag | Pointer to an Adafruit Unified sensor_event_t object to be filled with magnetometer event data. |
temp | Pointer to an Adafruit Unified sensor_event_t object to be filled with temperature event data. |
uint8_t Adafruit_ICM20X::readExternalRegister | ( | uint8_t | slv_addr, |
uint8_t | reg_addr | ||
) |
Read a single byte from a given register address for an I2C slave device on the auxiliary I2C bus.
slv_addr | the 7-bit I2C address of the slave device |
reg_addr | the register address to read from |
bool Adafruit_ICM20X::writeExternalRegister | ( | uint8_t | slv_addr, |
uint8_t | reg_addr, | ||
uint8_t | value | ||
) |
Write a single byte to a given register address for an I2C slave device on the auxiliary I2C bus.
slv_addr | the 7-bit I2C address of the slave device |
reg_addr | the register address to write to |
value | the value to write |
bool Adafruit_ICM20X::configureI2CMaster | ( | void | ) |
Set the I2C clock rate for the auxillary I2C bus to 345.60kHz and disable repeated start.
bool Adafruit_ICM20X::enableI2CMaster | ( | bool | enable_i2c_master | ) |
Enable or disable the I2C mastercontroller.
enable_i2c_master | true: enable false: disable |
void Adafruit_ICM20X::setI2CBypass | ( | bool | bypass_i2c | ) |
Sets the bypass status of the I2C master bus support.
bypass_i2c | Set to true to bypass the internal I2C master circuitry, connecting the external I2C bus to the main I2C bus. Set to false to re-connect |
|
protectedvirtual |
Sets up the hardware and initializes I2C.
i2c_address | The I2C address to be used. |
wire | The Wire object to be used for I2C connections. |
sensor_id | An optional parameter to set the sensor ids to differentiate similar sensors The passed value is assigned to the accelerometer, the gyro gets +1, the magnetometer +2, and the temperature sensor +3. |
Reimplemented in Adafruit_ICM20948, and Adafruit_ICM20649.
|
protected |
Initilizes the sensor.
sensor_id | Optional unique ID for the sensor set |
|
protected |
Sets register bank.
bank_number | The bank to set to active |
|
protected |
Get the accelerometer's measurement range.
icm20x_accel_range_t
).
|
protected |
Sets the accelerometer's measurement range.
new_accel_range | Measurement range to be set. Must be an icm20x_accel_range_t . |
|
protected |
Get the gyro's measurement range.
icm20x_gyro_range_t
).
|
protected |
Sets the gyro's measurement range.
new_gyro_range | Measurement range to be set. Must be an icm20x_gyro_range_t . |
|
friend |
Gives access to private members to Accelerometer data object
|
friend |
Gives access to private members to Gyro data object
|
friend |
Gives access to private members to Magnetometer data object
|
friend |
Gives access to private members to Temp data object
|
protected |
Accelerometer data object.
|
protected |
Magnetometer sensor data object.