Reference

Principle

The ICG-20660L integrates a 3-axis accelerometer and a 3-axis gyroscope, each digitized through on-chip 16-bit ADCs. The accelerometer measures linear acceleration along the x, y, and z axes, while the gyroscope detects angular velocity across the same axes. These raw signals are converted into digital output through the internal ADCs, enabling precise motion sensing with low noise and ±1% initial sensitivity error.

API Description

/**
 * @brief The constructor of the ICG20660L sensor, using IIC communication.
 * @param addr:  7-bit IIC address, controlled by SDO pin.
 * @n     IIC_ADDR_SDO_H or 0x69:  SDO pull high.(default)
 * @n     IIC_ADDR_SDO_L or 0x68:  SDO pull down.
 * @param pWire:   TwoWire class pointer.
 */
DFRobot_ICG20660L_IIC(uint8_t addr = IIC_ADDR_SDO_H, TwoWire *pWire = &Wire);

/**
 * @brief The constructor of the ICG20660L sensor, using SPI communication.
 * @param csPin:  SPI chip select pin, connected to IO pin of MCU.
 * @param spi: SPIClass class pointer.
 */
DFRobot_ICG20660L_SPI(int csPin, SPIClass *spi);

/**
 * @brief Initialize the sensor, after initialization, all sensors are turned off, and the corresponding configuration
 * @n needs to be turned on through enableSensor.
 * @param mode: Enum variable,from eDataReadMode_t, configure to read sensor data from FIFO or register?
 * @n     eRegMode: Read sensor data from registers.
 * @n     eFIFOMode:Read sensor data from 512 bytes FIFO. Note: Read from FIFO, accelerometer, gyroscope and temperature must all be enabled, 
 * @n and the internal sampling rate must be configured to be consistent. 
 * @return status:
 * @n      0 :   Initialization success.
 * @n      -1:   Interface initialization failed(IIC or SPI).
 * @n      -2:   Failed to read the device ID, the ID is not 0x91
 */
int begin(eDataReadMode_t  mode = eRegMode);

/**
 * @brief Get device ID, ICG20660L is 0x91 (145).
 * @return  If device is ICG20660L, it will return 0x91.
 */
uint8_t readID();

/**
 * @brief Enable sensor, including Accel of xyz axis, Gyro of xyz, temperature. 
 * @param bit: 8-bit byte data. Each bit represents enabling a function bit, as shown in the following table:
 * @n -------------------------------------------------------------------------------------------------------------------
 * @n |       bit7      |     bit6     |      bit5   |    bit4     |     bit3    |     bit2   |    bit1    |    bit0    |
 * @n -------------------------------------------------------------------------------------------------------------------
 * @n |     reserve     |    reserve   | eAccelAxisX | eAccelAxisY | eAccelAxisZ | eGyroAxisX | eGyroAxisY | eGyroAxisZ |
 * @n |                                |            eAccelAxisXYZ                |           eGyroAxisXYZ               |
 * @n |                                |                                eAxisAll                                        |
 * @n -------------------------------------------------------------------------------------------------------------------
 * @n   bit0:  Z-axis of gyro and temperature.
 * @n   bit1:  Y-axis of gyro and temperature.
 * @n   bit2:  X-axis of gyro and temperature.
 * @n   bit3:  Z-axis of acceleration.
 * @n   bit4:  Z-axis of acceleration.
 * @n   bit5:  Z-axis of acceleration.
 * @n   bit6:  reserve.
 * @n   bit7:  reserve.
 * @n Note: Enabling any axis of the gyroscope will automatically enable the on-board temperature sensor.
 * @n   eGyroAxisZ: The bit0 of the bit, enable gyro's z axis and temperature.
 * @n   eGyroAxisY: The bit1 of the bit, enable gyro's y axis and temperature.
 * @n   eGyroAxisX: The bit2 of the bit, enable gyro's X axis and temperature.
 * @n   eAccelAxisZ: The bit3 of the bit, enable accel's z axis.
 * @n   eAccelAxisY: The bit4 of the bit, enable Accel's y axis.
 * @n   eAccelAxisX: The bit5 of the bit, enable Accel's X axis.
 * @n   eGyroAxisXYZ or eGyroAxisX|eGyroAxisY|eGyroAxisZ: The bit0/bit1/bit2 of the bit, enable gyro's xyz axis and temperature.
 * @n   eAccelAxisXYZ or eAccelAxisX|eAccelAxisY|eAccelAxisZ: The bit3/bit4/bit5 of the bit, enable Accel's xyz axis.
 * @n   eAxisAll or eGyroAxisX|eGyroAxisY|eGyroAxisZ|eAccelAxisX|eAccelAxisY|eAccelAxisZ: The bit0/bit1/bit2/bit3/bit4/bit5 of the bit,
 * @n enable temperature, Accel's and gyro's xyz axis. 
 */
void enableSensor(uint8_t bit);

/**
 * @brief Disable sensor, including Accel of xyz axis, Gyro of xyz, temperature. 
 * @param bit: 8-bit byte data. Each bit represents enabling a function bit, as shown in the following table:
 * @n -------------------------------------------------------------------------------------------------------------------
 * @n |       bit7      |     bit6     |      bit5   |    bit4     |     bit3    |     bit2   |    bit1    |    bit0    |
 * @n -------------------------------------------------------------------------------------------------------------------
 * @n |     reserve     |    reserve   | eAccelAxisX | eAccelAxisY | eAccelAxisZ | eGyroAxisX | eGyroAxisY | eGyroAxisZ |
 * @n |                                |            eAccelAxisXYZ                |           eGyroAxisXYZ               |
 * @n |                                |                                eAxisAll                                        |
 * @n -------------------------------------------------------------------------------------------------------------------
 * @n   bit0:  Z-axis of gyro and temperature.
 * @n   bit1:  Y-axis of gyro and temperature.
 * @n   bit2:  X-axis of gyro and temperature.
 * @n   bit3:  Z-axis of acceleration.
 * @n   bit4:  Z-axis of acceleration.
 * @n   bit5:  Z-axis of acceleration.
 * @n   bit6:  reserve.
 * @n   bit7:  reserve.
 * @n Note: Only when the X, Y, and Z axes of the gyroscope are all closed, the temperature sensor will be turned off. 
 * @n Any axis’s turning on will make the temperature sensor not be turned off.
 * @n   eGyroAxisZ: The bit0 of the bit, disable gyro's z axis.
 * @n   eGyroAxisY: The bit1 of the bit, disable gyro's y axis.
 * @n   eGyroAxisX: The bit2 of the bit, disable gyro's X axis.
 * @n   eAccelAxisZ: The bit3 of the bit, disable accel's z axis.
 * @n   eAccelAxisY: The bit4 of the bit, disable Accel's y axis.
 * @n   eAccelAxisX: The bit5 of the bit, disable Accel's X axis.
 * @n   eGyroAxisXYZ or eGyroAxisX|eGyroAxisY|eGyroAxisZ: The bit0/bit1/bit2 of the bit, disable gyro's xyz axis and temperature.
 * @n   eAccelAxisXYZ or eAccelAxisX|eAccelAxisY|eAccelAxisZ: The bit3/bit4/bit5 of the bit, disable Accel's xyz axis.
 * @n   eAxisAll or eGyroAxisX|eGyroAxisY|eGyroAxisZ|eAccelAxisX|eAccelAxisY|eAccelAxisZ: The bit0/bit1/bit2/bit3/bit4/bit5 of the bit, 
 * @n disable temperature, Accel's and gyro's xyz axis. 
 */
void disableSensor(uint8_t bit);

/**
 * @brief Config of gyro's full scale, dlpf bandwidth and internal sample rate. 
 * @param scale  The full scale of gyro, unit: dps(Degrees per second).
 * @n     eFSR_G_125DPS:  The full scale range is ±125 dps.
 * @n     eFSR_G_250DPS:  The full scale range is ±250 dps.
 * @n     eFSR_G_500DPS:  The full scale range is ±500 dps.
 * @param bd  Set 3-db bandwidth.
 * @n     eGyro_DLPF_8173_32KHZ: When the signal is equal to or greater than 8173Hz, there will be obvious attenuation, 3-db attenuation, and the internal sampling rate is 32KHz.
 * @n     eGyro_DLPF_3281_32KHZ: When the signal is equal to or greater than 3281Hz, there will be obvious attenuation, 3-db attenuation, and the internal sampling rate is 32KHz.
 * @n     eGyro_DLPF_250_8KHZ:   When the signal is equal to or greater than 250Hz, there will be obvious attenuation, 3-db attenuation, and the internal sampling rate is 8KHz.
 * @n     eGyro_DLPF_176_1KHZ:   When the signal is equal to or greater than 176Hz, there will be obvious attenuation, 3-db attenuation, and the internal sampling rate is 1KHz.
 * @n     eGyro_DLPF_92_1KHZ:    When the signal is equal to or greater than 92Hz, there will be obvious attenuation, 3-db attenuation, and the internal sampling rate is 1KHz.
 * @n     eGyro_DLPF_3281_8KHZ:  When the signal is equal to or greater than 3281Hz, there will be obvious attenuation, 3-db attenuation, and the internal sampling rate is 8KHz.
 * @n Note: When the gyroscope and accelerometer are both enabled, if the sensor data is read through the FIFO,
 * @n the internal sampling rate of the gyroscope and accelerometer must be the same.
 */
void configGyro(eGyroFSR_t scale, eGyroBandwidth_t  bd);
void configGyro(uint8_t scale, uint8_t  bd);

/**
 * @brief Config of accel's full scale, dlpf bandwidth and internal sample rate. 
 * @param scale  The full scale of accel, unit: g(1g = 9.80665 m/s²).
 * @n     eFSR_A_2G:  The full scale range is ±2g.
 * @n     eFSR_A_4G:  The full scale range is ±4g.
 * @n     eFSR_A_8G:  The full scale range is ±8g.
 * @n     eFSR_A_16G:  The full scale range is ±16g.
 * @param bd  Set 3-db bandwidth.
 * @n     eAccel_DLPF_5_1KHZ or 0:    When the signal is less than or equal to 5Hz, there will be obvious attenuation, 3-db attenuation, and the internal sampling rate is 1KHz.
 * @n     eAccel_DLPF_10_1KHZ or 1:   When the signal is less than or equal to 10Hz, there will be obvious attenuation, 3-db attenuation, and the internal sampling rate is 1KHz.
 * @n     eAccel_DLPF_21_1KHZ or 2:   When the signal is less than or equal to 21Hz, there will be obvious attenuation, 3-db attenuation, and the internal sampling rate is 1KHz.
 * @n     eAccel_DLPF_44_1KHZ or 3:   When the signal is less than or equal to 44Hz, there will be obvious attenuation, 3-db attenuation, and the internal sampling rate is 1KHz.
 * @n     eAccel_DLPF_99_1KHZ or 4:   When the signal is less than or equal to 99Hz, there will be obvious attenuation, 3-db attenuation, and the internal sampling rate is 1KHz.
 * @n     eAccel_DLPF_218_1KHZ or 5:  When the signal is less than or equal to 218Hz, there will be obvious attenuation, 3-db attenuation, and the internal sampling rate is 1KHz.  Support low power consumption mode
 * @n     eAccel_DLPF_420_1KHZ or 6:  When the signal is less than or equal to 420Hz, there will be obvious attenuation, 3-db attenuation, and the internal sampling rate is 1KHz. Support low power consumption mode
 * @n     eAccel_DLPF_1046_4KHZ or 7: When the signal is less than or equal to 1046Hz, there will be obvious attenuation, 3-db attenuation, and the internal sampling rate is 4KHz. Support low power consumption mode
 * @n     eAccel_DLPF_55_1KHZ or 8:   When the signal is less than or equal to 55Hz, there will be obvious attenuation, 3-db attenuation, and the internal sampling rate is 1KHz. Only support low power consumption mode
 * @n     eAccel_DLPF_110_1KHZ or 9:  When the signal is less than or equal to 110Hz, there will be obvious attenuation, 3-db attenuation, and the internal sampling rate is 1KHz.  Only support low power consumption mode
 * @n Note: When the gyroscope and accelerometer are both enabled, if the sensor data is read through the FIFO, 
 * @n the internal sampling rate of the gyroscope and accelerometer must be the same.
 * @param odr:  Set the frequency of waking up the chip to take a sample of accel data – the low power accel Output Data Rate.
 * @n     eODR_125Hz or 9:    The low power accel Output Data Rate: 125Hz
 * @n     eODR_250Hz or 10:   The low power accel Output Data Rate: 250Hz
 * @n     eODR_500Hz or 11:   The low power accel Output Data Rate: 500Hz
 * @param lowPowerFlag:  Whether to configure the Acceleration to low power mode.
 * @n     true:          Enter low power mode.
 * @n     false:         Not configure the Acceleration to low power mode.(default)
 */
void configAccel(eAccelFSR_t scale, eAccelBandwidth_t bd, eODR_t odr = eODR_0_24Hz, bool lowPowerFlag = false);
void configAccel(uint8_t scale, uint8_t bd, uint8_t odr = 0, bool lowPowerFlag = false);

/**
 * @brief Set sample rate divider. 
 * @param div  Sample rate divider, the range is 0~255.
 * @n     Sampling rate = internal sampling rate/(div+1)
 * @n Note:  If the accelerometer configuration is in low power consumption mode, that is, the formal parameter lowPowerFlag of the configAccel function is true, 
 * @n the sampling rate must match the output rate of the formal parameter odr of configAccel, as shown in the following table:
 * @n ----------------------------------------------------------------------------
 * @n |                           configAccel                    |  setSampleDiv  |
 * @n ----------------------------------------------------------------------------|
 * @n |            bd             |      odr      | lowPowerFlag |      div       |
 * @n ----------------------------------------------------------------------------|
 * @n |            X              |       X       |    false     |      0~255     |
 * @n ----------------------------------------------------------------------------|
 * @n |                           |  eODR_125Hz   |    true      |        7       |
 * @n |                           |-----------------------------------------------|
 * @n |bd of supporting low power consumption mode|  eODR_250Hz   |    true      |        3       |
 * @n |                           |-----------------------------------------------|
 * @n |                           |  eODR_500Hz   |    true      |        1       |
 * @n |---------------------------------------------------------------------------|
 */
 void setSampleDiv(uint8_t div);

/**
 * @brief Reset, the register will restore the initial value, and you need to call begin to configuration.
 */
void reset();

/**
 * @brief Entering sleep mode, it will reduce power consumption, and The gyroscope and acceleration will stop working.
 * @n You need to call wakeup function to wake up sensor.
 */
void sleep();

/**
 * @brief Wake up sensor from sleep, and you will restore the configuration before sleep.
 */
void wakeup();
  
/**
 * @brief Set the level polarity of the INT pin when the accelerometer sensor is triggered to wake up the motion interrupt.
 * @param polarity: the level signal of the sensor INT pin when the wake-up motion is triggered
 * @n     HIGH:The initial signal of the pin is LOW. When an accelerometer wake-up motion occurs, the level signal of the INT pin will change to HIGH. 
 * @n Then the readINTStatus function needs to be called to clear the signal and restore the initial signal.
 * @n     LOW: The initial signal of the pin is HIGH. When an accelerometer wake-up motion occurs, the level signal of the INT pin will change to LOW. 
 * @n Then the readINTStatus function needs to be called to clear the signal and restore the initial signal.
 * @n Note: After triggering the accelerometer wake-up motion, if the read_int_status function is not called to clear the sign, 
 * @n the INT pin will always maintain the level polarity when the motion is triggered.
 */
void setINTPinMotionTriggerPolarity(int polarity);
  
/**
 * @brief Get the polarity of the INT pin of sensor when the sensor INT pin triggers an interrupt.
 * @return The level signal when the INT pin triggers an interrupt.
 * @n      HIGH:  INT pin level held  HIGH LEVEL until interrupt status is cleared.
 * @n      LOW:   INT pin level held  LOW LEVEL until interrupt status is cleared.
 */
int getINTPinMotionTriggerPolarity();
  
/**
 * @brief Set the threshold value for the Wake on Motion Interrupt for accelerometer. 
 * @param level: WoM thresholds are expressed in fixed “mg” independent of the selected Range [0g : 1g]; Resolution 1g/256=~3.9mg
 * @n     level = 0~255
 * @return Actul WoM thresholds, unit : g   re_value = (level * 3.9)/1000 g
 */
float setWakeOnMotionThresholdForAccel(uint8_t level);

/**
 * @brief Read interrupt status register, and clear INT pin's interrupt signal. 
 * @return Interrupt status register value.
 * @n  INT_STATUS register:addr:0x3A,acess:rw
 * @n  ------------------------------------------------------------------------------------
 * @n  |     b7    |    b6     |    b5     |      b4        | b3 | b2 | b1 |      b0      |
 * @n  ------------------------------------------------------------------------------------
 * @n  |             WOM_XYZ_INT           | FIFO_OFLOW_INT |     rsv      | DATA_RDY_INT |
 * @n  ------------------------------------------------------------------------------------
 * @n  DATA_RDY_INT  : This bit automatically sets to 1 when a Data Ready interrupt is generated. The bit clears to 0 after the register has been read.
 * @n  rsv           : reserve
 * @n  FIFO_OFLOW_INT: This bit automatically sets to 1 when a FIFO buffer overflow has been generated. The bit clears to 0 after the register has been read.
 * @n  WOM_XYZ_INT   : These bits automatically set to a non-zero number when the X-axis,Y-axis or Z-axis of accelerometer which trigger WOM(wake on motion) 
 * @n                  interrupt.Cleared on Read.
 */
uint8_t readINTStatus();

/**
 * @brief Get Sensor's accel, gyro and temperature data.
 * @param accel: sIcg20660SensorData_t structure pointer which points to accel or NULL.
 * @param gyro: sIcg20660SensorData_t structure pointer which points to gyro or NULL.
 * @param t:  A float pointer which points to temperature or NULL.
 */
void getSensorData(sIcg20660SensorData_t *accel, sIcg20660SensorData_t *gyro, float *t);

/**
 * @brief Get X axis acceleration, unit g.
 * @return  X axis acceleration.
 */
float getAccelDataX();

/**
 * @brief Get Y axis acceleration, unit g.
 * @return  Y axis acceleration.
 */
float getAccelDataY();

/**
 * @brief Get Z axis acceleration, unit g.
 * @return  Z axis acceleration.
 */
float getAccelDataZ();

/**
 * @brief Get temperature data, uint: ℃.
 * @return  Temperature data.
 */
float getTemperatureC();
  
/**
 * @brief Get X-axis gyroscope speed, unit dps.
 * @return  X-axis gyroscope speed.
 */
float getGyroDataX();

/**
 * @brief Get Y-axis gyroscope speed, unit dps.
 * @return  Y-axis gyroscope speed.
 */
float getGyroDataY();

/**
 * @brief Get Z-axis gyroscope speed, unit dps.
 * @return  Z-axis gyroscope speed.
 */
float getGyroDataZ();

/**
 * @brief Get 14 bytes raw data, including accel, gyro and temperature.
 * @param data:  buffer for storing 14 bytes of raw data.
 * @n     The first byte of data :  Acceleration X-axis high byte data.
 * @n     The second byte of data:  Acceleration X-axis low byte data.
 * @n     The third byte of data :  Acceleration Y-axis high byte data.
 * @n     The 4th byte of data   :  Acceleration Y-axis low byte data.
 * @n     The 5th byte of data   :  Acceleration Z-axis high byte data.
 * @n     The 6th byte of data   :  Acceleration Z-axis low byte data.
 * @n     The 7th byte of data   :  Temperature high byte data.
 * @n     The 8th byte of data   :  Temperature low byte data.
 * @n     The 9th byte of data   :  Gyro X-axis high byte data.
 * @n     The 10th byte of data  :  Gyro X-axis low byte data.
 * @n     The 11th byte of data  :  Gyro Y-axis high byte data.
 * @n     The 12th byte of data  :  Gyro Y-axis low byte data.
 * @n     The 13th byte of data  :  Gyro Z-axis high byte data.
 * @n     The 14th byte of data  :  Gyro Z-axis low byte data.
 * @n Note: You can use RAW_DATA_LENGTH to creat data Arrya, and you can use  
 * @n RAW_DATA_AX_H_INDEX, RAW_DATA_AX_L_INDEX, RAW_DATA_AY_H_INDEX, RAW_DATA_AY_L_INDEX, RAW_DATA_AZ_H_INDEX, RAW_DATA_AZ_L_INDEX,
 * @n RAW_DATA_T_H_INDEX, RAW_DATA_T_L_INDEX,RAW_DATA_GX_H_INDEX, RAW_DATA_GX_L_INDEX, 
 * @n RAW_DATA_GY_H_INDEX, RAW_DATA_GY_L_INDEX, RAW_DATA_GZ_H_INDEX, RAW_DATA_GZ_L_INDEX or 0~13 to index data array.
 * @param len: The length of data array.
 */
void getRawData(uint8_t *data, uint8_t len = 0);

Communication Protocol Description

Connections for different communication methods:

  • I2C: 0x69(Default)/ 0x68

I2C连线图EN

  • SPI

SPI连线

  • Demo Interrupt Pin Mapping
Mainboard Default Pin
Micro:bit P9
ESP32 D9
ESP8266 D5
Raspberry Pi BCM27

Connect the interrupt pin only if the interrupt function is required.

Was this article helpful?

TOP