Adafruit ICM20X Sensor Library
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
Adafruit_ICM20X Class Reference

Class that stores state and functions for interacting with the ST ICM20X 6-DoF Accelerometer and Gyro. More...

#include <Adafruit_ICM20X.h>

Inheritance diagram for Adafruit_ICM20X:
Adafruit_ICM20649 Adafruit_ICM20948

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_Accelerometeraccel_sensor
 Accelerometer data object. More...
 
Adafruit_ICM20X_Gyrogyro_sensor = NULL
 Gyro data object.
 
Adafruit_ICM20X_Magnetometermag_sensor
 Magnetometer sensor data object. More...
 
Adafruit_ICM20X_Temptemp_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
 

Detailed Description

Class that stores state and functions for interacting with the ST ICM20X 6-DoF Accelerometer and Gyro.

Member Function Documentation

◆ begin_SPI() [1/2]

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.

Parameters
cs_pinThe arduino pin # connected to chip select
theSPIThe SPI object to be used for SPI connections.
sensor_idAn 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.
Returns
True if initialization was successful, otherwise false.

◆ begin_SPI() [2/2]

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.

Parameters
cs_pinThe arduino pin # connected to chip select
sck_pinThe arduino pin # connected to SPI clock
miso_pinThe arduino pin # connected to SPI MISO
mosi_pinThe arduino pin # connected to SPI MOSI
sensor_idAn 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.
Returns
True if initialization was successful, otherwise false.

◆ getGyroRateDivisor()

uint8_t Adafruit_ICM20X::getGyroRateDivisor ( void  )

Get the gyro's data rate divisor.

Returns
The gyro's data rate divisor (uint8_t).

◆ setGyroRateDivisor()

void Adafruit_ICM20X::setGyroRateDivisor ( uint8_t  new_gyro_divisor)

Sets the gyro's data rate divisor.

Parameters
new_gyro_divisorThe gyro's data rate divisor (uint8_t).

◆ getAccelRateDivisor()

uint16_t Adafruit_ICM20X::getAccelRateDivisor ( void  )

Get the accelerometer's data rate divisor.

Returns
The accelerometer's data rate divisor (uint8_t).

◆ setAccelRateDivisor()

void Adafruit_ICM20X::setAccelRateDivisor ( uint16_t  new_accel_divisor)

Sets the accelerometer's data rate divisor.

Parameters
new_accel_divisorThe accelerometer's data rate divisor (uint16_t). This 12-bit value must be <= 4095

◆ enableAccelDLPF()

bool Adafruit_ICM20X::enableAccelDLPF ( bool  enable,
icm20x_accel_cutoff_t  cutoff_freq 
)

Enable or disable the accelerometer's Digital Low Pass Filter.

Parameters
enabletrue: enable false: disable
cutoff_freqSignals changing at a rate higher than the given cutoff frequency will be filtered out
Returns
true: success false: failure

◆ enableGyrolDLPF()

bool Adafruit_ICM20X::enableGyrolDLPF ( bool  enable,
icm20x_gyro_cutoff_t  cutoff_freq 
)

Enable or disable the gyro's Digital Low Pass Filter.

Parameters
enabletrue: enable false: disable
cutoff_freqSignals changing at a rate higher than the given cutoff frequency will be filtered out
Returns
true: success false: failure

◆ setInt1ActiveLow()

void Adafruit_ICM20X::setInt1ActiveLow ( bool  active_low)

Sets the polarity of the int1 pin.

Parameters
active_lowSet to true to make INT1 active low, false to make it active high

◆ setInt2ActiveLow()

void Adafruit_ICM20X::setInt2ActiveLow ( bool  active_low)

Sets the polarity of the INT2 pin.

Parameters
active_lowSet to true to make INT1 active low, false to make it active high

◆ getAccelerometerSensor()

Adafruit_Sensor * Adafruit_ICM20X::getAccelerometerSensor ( void  )

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

Returns
Adafruit_Sensor pointer to accelerometer sensor

◆ getGyroSensor()

Adafruit_Sensor * Adafruit_ICM20X::getGyroSensor ( void  )

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

Returns
Adafruit_Sensor pointer to gyro sensor

◆ getMagnetometerSensor()

Adafruit_Sensor * Adafruit_ICM20X::getMagnetometerSensor ( void  )

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

Returns
Adafruit_Sensor pointer to magnetometer sensor

◆ getTemperatureSensor()

Adafruit_Sensor * Adafruit_ICM20X::getTemperatureSensor ( void  )

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

Returns
Adafruit_Sensor pointer to temperature sensor

◆ getEvent()

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.

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 gyro event data.
magPointer to an Adafruit Unified sensor_event_t object to be filled with magnetometer event data.
tempPointer to an Adafruit Unified sensor_event_t object to be filled with temperature event data.
Returns
True on successful read

◆ readExternalRegister()

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.

Parameters
slv_addrthe 7-bit I2C address of the slave device
reg_addrthe register address to read from
Returns
the requested register value

◆ writeExternalRegister()

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.

Parameters
slv_addrthe 7-bit I2C address of the slave device
reg_addrthe register address to write to
valuethe value to write
Returns
true
false

◆ configureI2CMaster()

bool Adafruit_ICM20X::configureI2CMaster ( void  )

Set the I2C clock rate for the auxillary I2C bus to 345.60kHz and disable repeated start.

Returns
true: success false: failure

◆ enableI2CMaster()

bool Adafruit_ICM20X::enableI2CMaster ( bool  enable_i2c_master)

Enable or disable the I2C mastercontroller.

Parameters
enable_i2c_mastertrue: enable false: disable
Returns
true: success false: error

◆ setI2CBypass()

void Adafruit_ICM20X::setI2CBypass ( bool  bypass_i2c)

Sets the bypass status of the I2C master bus support.

Parameters
bypass_i2cSet 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

◆ begin_I2C()

bool Adafruit_ICM20X::begin_I2C ( uint8_t  i2c_address,
TwoWire *  wire,
int32_t  sensor_id 
)
protectedvirtual

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_idAn 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.
Returns
True if initialization was successful, otherwise false.

Reimplemented in Adafruit_ICM20948, and Adafruit_ICM20649.

◆ _init()

bool Adafruit_ICM20X::_init ( int32_t  sensor_id)
protected

Initilizes the sensor.

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

◆ _setBank()

void Adafruit_ICM20X::_setBank ( uint8_t  bank_number)
protected

Sets register bank.

Parameters
bank_numberThe bank to set to active

◆ readAccelRange()

uint8_t Adafruit_ICM20X::readAccelRange ( void  )
protected

Get the accelerometer's measurement range.

Returns
The accelerometer's measurement range (icm20x_accel_range_t).

◆ writeAccelRange()

void Adafruit_ICM20X::writeAccelRange ( uint8_t  new_accel_range)
protected

Sets the accelerometer's measurement range.

Parameters
new_accel_rangeMeasurement range to be set. Must be an icm20x_accel_range_t.

◆ readGyroRange()

uint8_t Adafruit_ICM20X::readGyroRange ( void  )
protected

Get the gyro's measurement range.

Returns
The gyro's measurement range (icm20x_gyro_range_t).

◆ writeGyroRange()

void Adafruit_ICM20X::writeGyroRange ( uint8_t  new_gyro_range)
protected

Sets the gyro's measurement range.

Parameters
new_gyro_rangeMeasurement range to be set. Must be an icm20x_gyro_range_t.

Friends And Related Function Documentation

◆ Adafruit_ICM20X_Accelerometer

friend class Adafruit_ICM20X_Accelerometer
friend

Gives access to private members to Accelerometer data object

◆ Adafruit_ICM20X_Gyro

friend class Adafruit_ICM20X_Gyro
friend

Gives access to private members to Gyro data object

◆ Adafruit_ICM20X_Magnetometer

friend class Adafruit_ICM20X_Magnetometer
friend

Gives access to private members to Magnetometer data object

◆ Adafruit_ICM20X_Temp

friend class Adafruit_ICM20X_Temp
friend

Gives access to private members to Temp data object

Member Data Documentation

◆ accel_sensor

Adafruit_ICM20X_Accelerometer* Adafruit_ICM20X::accel_sensor
protected
Initial value:
=
NULL

Accelerometer data object.

◆ mag_sensor

Adafruit_ICM20X_Magnetometer* Adafruit_ICM20X::mag_sensor
protected
Initial value:
=
NULL

Magnetometer sensor data object.


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