Adafruit LSM6DS Sensors Library
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Friends | List of all members
Adafruit_LSM6DS Class Reference

Class that stores state and functions for interacting with the LSM6DS I2C Accel/Gyro. More...

#include <Adafruit_LSM6DS.h>

Inheritance diagram for Adafruit_LSM6DS:
Adafruit_LSM6DS3 Adafruit_LSM6DS33 Adafruit_LSM6DSOX Adafruit_ISM330DHCX Adafruit_LSM6DSO32

Public Member Functions

 Adafruit_LSM6DS ()
 Instantiates a new LSM6DS class.
 
 ~Adafruit_LSM6DS ()
 Cleans up the LSM6DS.
 
bool begin_I2C (uint8_t i2c_addr=LSM6DS_I2CADDR_DEFAULT, TwoWire *wire=&Wire, int32_t sensorID=0)
 Sets up the hardware and initializes I2C. More...
 
bool begin_SPI (uint8_t cs_pin, SPIClass *theSPI=&SPI, int32_t sensorID=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 sensorID=0)
 Sets up the hardware and initializes software SPI. 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...
 
lsm6ds_data_rate_t getAccelDataRate (void)
 Gets the accelerometer data rate. More...
 
void setAccelDataRate (lsm6ds_data_rate_t data_rate)
 Sets the accelerometer data rate. More...
 
lsm6ds_accel_range_t getAccelRange (void)
 Gets the accelerometer measurement range. More...
 
void setAccelRange (lsm6ds_accel_range_t new_range)
 Sets the accelerometer measurement range. More...
 
lsm6ds_data_rate_t getGyroDataRate (void)
 Gets the gyro data rate. More...
 
void setGyroDataRate (lsm6ds_data_rate_t data_rate)
 Sets the gyro data rate. More...
 
lsm6ds_gyro_range_t getGyroRange (void)
 Gets the gyro range. More...
 
void setGyroRange (lsm6ds_gyro_range_t new_range)
 Sets the gyro range. More...
 
void reset (void)
 Resets the sensor to its power-on state, clearing all registers and memory.
 
void configIntOutputs (bool active_low, bool open_drain)
 Sets the INT1 and INT2 pin activation mode. More...
 
void configInt1 (bool drdy_temp, bool drdy_g, bool drdy_xl, bool step_detect=false, bool wakeup=false)
 Enables and disables the data ready interrupt on INT 1. More...
 
void configInt2 (bool drdy_temp, bool drdy_g, bool drdy_xl)
 Enables and disables the data ready interrupt on INT 2. More...
 
void highPassFilter (bool enabled, lsm6ds_hp_filter_t filter)
 Enables the high pass filter and/or slope filter. More...
 
void enableWakeup (bool enable, uint8_t duration, uint8_t thresh)
 Enables and disables the wakeup function. More...
 
bool awake (void)
 Checks interrupt register to see if we have a wake signal. More...
 
void enablePedometer (bool enable)
 Enables and disables the pedometer function. More...
 
void resetPedometer (void)
 Reset the pedometer count.
 
uint16_t readPedometer (void)
 Read the 16-bit pedometer count. More...
 
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...
 

Public Attributes

int16_t rawAccX
 Last reading's raw accelerometer X axis.
 
int16_t rawAccY
 Last reading's raw accelerometer Y axis.
 
int16_t rawAccZ
 Last reading's raw accelerometer Z axis.
 
int16_t rawTemp
 Last reading's raw temperature reading.
 
int16_t rawGyroX
 Last reading's raw gyro X axis.
 
int16_t rawGyroY
 Last reading's raw gyro Y axis.
 
int16_t rawGyroZ
 Last reading's raw gyro Z axis.
 

Protected Member Functions

uint8_t chipID ()
 Read chip identification register. More...
 
virtual void _read (void)
 Updates the measurement data for all sensors simultaneously.
 
virtual bool _init (int32_t sensor_id)
 Unique subclass initializer post i2c/spi init. 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.
 
uint16_t _sensorid_accel
 ID number for accelerometer.
 
uint16_t _sensorid_gyro
 ID number for gyro.
 
uint16_t _sensorid_temp
 ID number for temperature.
 
Adafruit_I2CDevice * i2c_dev = NULL
 Pointer to I2C bus interface.
 
Adafruit_SPIDevice * spi_dev = NULL
 Pointer to SPI bus interface.
 
Adafruit_LSM6DS_Temptemp_sensor = NULL
 Temp sensor data object.
 
Adafruit_LSM6DS_Accelerometeraccel_sensor
 Accelerometer data object. More...
 
Adafruit_LSM6DS_Gyrogyro_sensor = NULL
 Gyro data object.
 

Friends

class Adafruit_LSM6DS_Temp
 
class Adafruit_LSM6DS_Accelerometer
 
class Adafruit_LSM6DS_Gyro
 

Detailed Description

Class that stores state and functions for interacting with the LSM6DS I2C Accel/Gyro.

Member Function Documentation

◆ begin_I2C()

boolean Adafruit_LSM6DS::begin_I2C ( uint8_t  i2c_address = LSM6DS_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.

◆ begin_SPI() [1/2]

bool Adafruit_LSM6DS::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_idThe user-defined ID to differentiate different sensors
Returns
True if initialization was successful, otherwise false.

◆ begin_SPI() [2/2]

bool Adafruit_LSM6DS::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_idThe user-defined ID to differentiate different sensors
Returns
True if initialization was successful, otherwise false.

◆ getEvent()

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

◆ getAccelDataRate()

lsm6ds_data_rate_t Adafruit_LSM6DS::getAccelDataRate ( void  )

Gets the accelerometer data rate.

Returns
The the accelerometer data rate.

◆ setAccelDataRate()

void Adafruit_LSM6DS::setAccelDataRate ( lsm6ds_data_rate_t  data_rate)

Sets the accelerometer data rate.

Parameters
data_rateThe the accelerometer data rate. Must be a lsm6ds_data_rate_t.

◆ getAccelRange()

lsm6ds_accel_range_t Adafruit_LSM6DS::getAccelRange ( void  )

Gets the accelerometer measurement range.

Returns
The the accelerometer measurement range.

◆ setAccelRange()

void Adafruit_LSM6DS::setAccelRange ( lsm6ds_accel_range_t  new_range)

Sets the accelerometer measurement range.

Parameters
new_rangeThe lsm6ds_accel_range_t range to set.

◆ getGyroDataRate()

lsm6ds_data_rate_t Adafruit_LSM6DS::getGyroDataRate ( void  )

Gets the gyro data rate.

Returns
The the gyro data rate.

◆ setGyroDataRate()

void Adafruit_LSM6DS::setGyroDataRate ( lsm6ds_data_rate_t  data_rate)

Sets the gyro data rate.

Parameters
data_rateThe the gyro data rate. Must be a lsm6ds_data_rate_t.

◆ getGyroRange()

lsm6ds_gyro_range_t Adafruit_LSM6DS::getGyroRange ( void  )

Gets the gyro range.

Returns
The the gyro range.

◆ setGyroRange()

void Adafruit_LSM6DS::setGyroRange ( lsm6ds_gyro_range_t  new_range)

Sets the gyro range.

Parameters
new_rangeThe lsm6ds_gyro_range_t to set.

◆ configIntOutputs()

void Adafruit_LSM6DS::configIntOutputs ( bool  active_low,
bool  open_drain 
)

Sets the INT1 and INT2 pin activation mode.

Parameters
active_lowtrue to set the pins as active high, false to set the mode to active low
open_draintrue to set the pin mode as open-drain, false to set the mode to push-pull

◆ configInt1()

void Adafruit_LSM6DS::configInt1 ( bool  drdy_temp,
bool  drdy_g,
bool  drdy_xl,
bool  step_detect = false,
bool  wakeup = false 
)

Enables and disables the data ready interrupt on INT 1.

Parameters
drdy_temptrue to output the data ready temperature interrupt
drdy_gtrue to output the data ready gyro interrupt
drdy_xltrue to output the data ready accelerometer interrupt
step_detecttrue to output the step detection interrupt (default off)
wakeuptrue to output the wake up interrupt (default off)

◆ configInt2()

void Adafruit_LSM6DS::configInt2 ( bool  drdy_temp,
bool  drdy_g,
bool  drdy_xl 
)

Enables and disables the data ready interrupt on INT 2.

Parameters
drdy_temptrue to output the data ready temperature interrupt
drdy_gtrue to output the data ready gyro interrupt
drdy_xltrue to output the data ready accelerometer interrupt

◆ highPassFilter()

void Adafruit_LSM6DS::highPassFilter ( bool  filter_enabled,
lsm6ds_hp_filter_t  filter 
)

Enables the high pass filter and/or slope filter.

Parameters
filter_enabledWhether to enable the slope filter (see datasheet)
filterThe lsm6ds_hp_filter_t that sets the data rate divisor

◆ enableWakeup()

void Adafruit_LSM6DS::enableWakeup ( bool  enable,
uint8_t  duration = 0,
uint8_t  thresh = 20 
)

Enables and disables the wakeup function.

Parameters
enableTrue to turn on the wakeup function, false to turn off
durationHow many > threshold readings to generate a wakeup
threshThe threshold (sensitivity)

◆ awake()

bool Adafruit_LSM6DS::awake ( void  )

Checks interrupt register to see if we have a wake signal.

Returns
True if wake event bit is set in WAKEUP_SRC (cleared on read)

◆ enablePedometer()

void Adafruit_LSM6DS::enablePedometer ( bool  enable)

Enables and disables the pedometer function.

Parameters
enableTrue to turn on the pedometer function, false to turn off

◆ readPedometer()

uint16_t Adafruit_LSM6DS::readPedometer ( void  )

Read the 16-bit pedometer count.

Returns
The value from the step counter

◆ getTemperatureSensor()

Adafruit_Sensor * Adafruit_LSM6DS::getTemperatureSensor ( void  )

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

Returns
Adafruit_Sensor pointer to temperature sensor

◆ getAccelerometerSensor()

Adafruit_Sensor * Adafruit_LSM6DS::getAccelerometerSensor ( void  )

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

Returns
Adafruit_Sensor pointer to accelerometer sensor

◆ getGyroSensor()

Adafruit_Sensor * Adafruit_LSM6DS::getGyroSensor ( void  )

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

Returns
Adafruit_Sensor pointer to gyro sensor

◆ chipID()

uint8_t Adafruit_LSM6DS::chipID ( void  )
protected

Read chip identification register.

Returns
8 Bit value from WHOAMI register

◆ _init()

bool Adafruit_LSM6DS::_init ( int32_t  sensor_id)
protectedvirtual

Unique subclass initializer post i2c/spi init.

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

Friends And Related Function Documentation

◆ Adafruit_LSM6DS_Temp

friend class Adafruit_LSM6DS_Temp
friend

Gives access to private members to Temp data object

◆ Adafruit_LSM6DS_Accelerometer

friend class Adafruit_LSM6DS_Accelerometer
friend

Gives access to private members to Accelerometer data object

◆ Adafruit_LSM6DS_Gyro

friend class Adafruit_LSM6DS_Gyro
friend

Gives access to private members to Gyro data object

Member Data Documentation

◆ accel_sensor

Adafruit_LSM6DS_Accelerometer* Adafruit_LSM6DS::accel_sensor
protected
Initial value:
=
NULL

Accelerometer data object.


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