Silicon Labs / ICM20648

Dependents:   TBSense2_Sensor_Demo

Embed: (wiki syntax)

« Back to documentation index

ICM20648 Class Reference

ICM20648 Class Reference

ICM20648 class. More...

#include <ICM20648.h>

Public Member Functions

 ICM20648 (PinName mosi, PinName miso, PinName sclk, PinName cs, PinName irq=NC)
 Create an ICM20648 object connected to the specified SPI pins.
 ~ICM20648 (void)
 ICM20648 destructor.
bool open ()
 Probe for the ICM20648 and try to initialize the sensor.
bool measure ()
 Perform a measurement.
bool get_gyroscope (float *gyr_x, float *gyr_y, float *gyr_z)
 Do a measurement on the gyroscope.
bool get_accelerometer (float *acc_x, float *acc_y, float *acc_z)
 Do a measurement on the accelerometer.
bool get_temperature (float *temperature)
 Do a measurement of the temperature sensor.

Detailed Description

ICM20648 class.

Used for taking accelerometer and gyroscope measurements.

Example:

 #include "mbed.h"
 #include "ICM20648.h "

 //Create an ICM20648 object
 ICM20648 sensor(PC4, PC5);

 int main()
 {
     //Try to open the ICM20648
     if (sensor.open()) {
         printf("Device detected!\n");

         while (1) {
             float acc_x, acc_y, acc_z;
             float gyr_x, gyr_y, gyr_z;
             
             sensor.measure();

             sensor.get_accelerometer(&acc_x, &acc_y, &acc_z);
             sensor.get_gyroscope(&gyr_x, &gyr_y, &gyr_z);

             //Print the current accelerometer measurement
             printf("acc: %.3f  %.3f  %.3f\n", acc_x, acc_y, acc_z);
             //Print the current gyroscope measurement
             printf("gyr: %.3f  %.3f  %.3f\n", gyr_x, gyr_y, gyr_z);

             //Sleep for 0.5 seconds
             wait(0.5);
         }
     } else {
         error("Device not detected!\n");
     }
 }

Definition at line 69 of file ICM20648.h.


Constructor & Destructor Documentation

ICM20648 ( PinName  mosi,
PinName  miso,
PinName  sclk,
PinName  cs,
PinName  irq = NC 
)

Create an ICM20648 object connected to the specified SPI pins.

Parameters:
mosiThe SPI MOSI pin.
misoThe SPI MISO pin.
sclkThe SPI clock pin.
csThe SPI Chip Select pin.
irqThe ICM20648 irq pin.

Definition at line 279 of file ICM20648.cpp.

~ICM20648 ( void   )

ICM20648 destructor.

Definition at line 285 of file ICM20648.cpp.


Member Function Documentation

bool get_accelerometer ( float *  acc_x,
float *  acc_y,
float *  acc_z 
)

Do a measurement on the accelerometer.

Parameters:
[out]acc_xAccelerometer measurement on X axis
[out]acc_yAccelerometer measurement on Y axis
[out]acc_zAccelerometer measurement on Z axis
Returns:
true if measurement was successful

Definition at line 355 of file ICM20648.cpp.

bool get_gyroscope ( float *  gyr_x,
float *  gyr_y,
float *  gyr_z 
)

Do a measurement on the gyroscope.

Parameters:
[out]gyr_xGyroscope measurement on X axis
[out]gyr_yGyroscope measurement on Y axis
[out]gyr_zGyroscope measurement on Z axis
Returns:
true if measurement was successful

Definition at line 335 of file ICM20648.cpp.

bool get_temperature ( float *  temperature )

Do a measurement of the temperature sensor.

Parameters:
[out]temperatureMeasured temperature
Returns:
true if measurement was successful

Definition at line 367 of file ICM20648.cpp.

bool measure (  )

Perform a measurement.

Returns:
true if measurement was successful

Definition at line 322 of file ICM20648.cpp.

bool open (  )

Probe for the ICM20648 and try to initialize the sensor.

Returns:
'true' if the device exists on the bus, 'false' if the device doesn't exist on the bus.

Definition at line 289 of file ICM20648.cpp.