upm  0.5.1
Sensor/Actuator repository for libmraa (v0.9.1)
 All Data Structures Files Functions Variables Enumerations Enumerator Macros Groups Pages
Public Types | Public Member Functions | Protected Attributes
H3LIS331DL Class Reference

API for the H3LIS331DL-based Grove 3-Axis Digital Accelerometer (400g) More...

Detailed Description

This is a high-performance, high-range accelerometer for extreme applications.

h3lis331dl.jpg
// Instantiate an H3LIS331DL on I2C bus 0
upm::H3LIS331DL *accel = new upm::H3LIS331DL(H3LIS331DL_I2C_BUS,
H3LIS331DL_DEFAULT_I2C_ADDR);
// Initialize the device with default values
accel->init();
while (shouldRun)
{
int x, y, z;
float ax, ay, az;
accel->update();
accel->getRawXYZ(&x, &y, &z);
accel->getAcceleration(&ax, &ay, &az);
cout << "Raw: X = " << x << " Y = " << y << " Z = " << z << endl;
cout << "Acceleration: AX = " << ax << " AY = " << ay << " AZ = " << az
<< endl;
cout << endl;
usleep(500000);
}

Public Types

enum  H3LIS331DL_REG_T {
  REG_WHOAMI = 0x0f, REG_REG1 = 0x20, REG_REG2 = 0x21, REG_REG3 = 0x22,
  REG_REG4 = 0x23, REG_REG5 = 0x24, REG_HP_FILTER_RESET = 0x25, REG_REFERENCE = 0x26,
  REG_STATUS = 0x27, REG_OUT_X_L = 0x28, REG_OUT_X_H = 0x29, REG_OUT_Y_L = 0x2a,
  REG_OUT_Y_H = 0x2b, REG_OUT_Z_L = 0x2c, REG_OUT_Z_H = 0x2d, REG_INT1_CFG = 0x30,
  REG_INT1_SRC = 0x31, REG_INT1_THS = 0x32, REG_INT1_DUR = 0x33, REG_INT2_CFG = 0x34,
  REG_INT2_SRC = 0x35, REG_INT2_THS = 0x36, REG_INT2_DUR = 0x37
}
 
enum  REG1_BITS_T {
  REG1_XEN = 0x01, REG1_YEN = 0x02, REG1_ZEN = 0x04, REG1_DR0 = 0x08,
  REG1_DR1 = 0x10, REG1_DR_SHIFT = 3, REG1_PM0 = 0x20, REG1_PM1 = 0x40,
  REG1_PM2 = 0x80, REG1_PM_SHIFT = 5
}
 
enum  DR_BITS_T { DR_50_37 = 0x0, DR_100_74 = 0x1, DR_400_292 = 0x2, DR_1000_780 = 0x3 }
 
enum  PM_BITS_T {
  PM_POWERDWN = 0x0, PM_NORMAL = 0x1, PM_LP05 = 0x2, PM_LP1 = 0x3,
  PM_LP2 = 0x4, PM_LP5 = 0x5, PM_LP10 = 0x6
}
 
enum  REG2_BITS_T {
  REG2_HPCF0 = 0x01, REG2_HPCF1 = 0x02, REG2_HPCF_SHIFT = 0, REG2_HPEN1 = 0x04,
  REG2_HPEN2 = 0x08, REG2_FDS = 0x10, REG2_HPM0 = 0x20, REG2_HPM1 = 0x40,
  REG2_HPM_SHIFT = 5, REG2_BOOT = 0x80
}
 
enum  HPCF_BITS_T { HPCF_8 = 0x0, HPCF_16 = 0x1, HPCF_32 = 0x2, HPCF_64 = 0x3 }
 
enum  HPM_BITS_T { HPM_NORMAL0 = 0x0, HPM_REF = 0x1, HPM_NORMAL1 = 0x2 }
 
enum  REG3_BITS_T {
  REG3_I1_CFG0 = 0x01, REG3_I1_CFG1 = 0x02, REG3_I1_CFG_SHIFT = 0, REG3_LIR1 = 0x04,
  REG3_I2_CFG0 = 0x08, REG3_I2_CFG1 = 0x10, REG3_I2_CFG_SHIFT = 3, REG3_LIR2 = 0x20,
  REG3_PP_OD = 0x40, REG3_IHL = 0x80
}
 
enum  I_CFG_BITS_T { I_SRC = 0x0, I_OR = 0x1, I_DR = 0x2, I_BOOTING = 0x3 }
 
enum  REG4_BITS_T {
  REG4_SIM = 0x01, REG4_FS0 = 0x10, REG4_FS1 = 0x20, REG4_FS_SHIFT = 4,
  REG4_BLE = 0x40, REG4_BDU = 0x80
}
 
enum  FS_BITS_T { FS_100 = 0x0, FS_200 = 0x1, FS_400 = 0x3 }
 
enum  REG5_BITS_T { REG5_TURNON0 = 0x01, REG5_TURNON1 = 0x02 }
 
enum  STATUS_BITS_T {
  STATUS_XDA = 0x01, STATUS_YDA = 0x02, STATUS_ZDA = 0x04, STATUS_ZYXDA = 0x08,
  STATUS_XOR = 0x10, STATUS_YOR = 0x20, STATUS_ZOR = 0x40, STATUS_ZYXOR = 0x80
}
 
enum  INT_CFG_BITS_T {
  INT_CFG_XLIE = 0x01, INT_CFG_XHIE = 0x02, INT_CFG_YLIE = 0x04, INT_CFG_YHIE = 0x08,
  INT_CFG_ZLIE = 0x10, INT_CFG_ZHIE = 0x20, INT_CFG_AOI = 0x80
}
 
enum  INT_SRC_BITS_T {
  INT_SRC_XL = 0x01, INT_SRC_XH = 0x02, INT_SRC_YL = 0x04, INT_SRC_YH = 0x08,
  INT_SRC_ZL = 0x10, INT_SRC_ZH = 0x20, INT_SRC_IA = 0x40
}
 

Public Member Functions

 H3LIS331DL (int bus, uint8_t address=H3LIS331DL_DEFAULT_I2C_ADDR)
 
 ~H3LIS331DL ()
 
bool init (DR_BITS_T odr=DR_50_37, PM_BITS_T pm=PM_NORMAL, FS_BITS_T fs=FS_100)
 
uint8_t getChipID ()
 
bool setDataRate (DR_BITS_T odr)
 
bool setPowerMode (PM_BITS_T pm)
 
bool enableAxis (uint8_t axisEnable)
 
bool setFullScale (FS_BITS_T fs)
 
bool setHPCF (HPCF_BITS_T val)
 
bool setHPM (HPM_BITS_T val)
 
bool boot ()
 
bool enableHPF1 (bool enable)
 
bool enableHPF2 (bool enable)
 
bool enableFDS (bool enable)
 
bool setInterruptActiveLow (bool enable)
 
bool setInterruptOpenDrain (bool enable)
 
bool setInterrupt1Latch (bool enable)
 
bool setInterrupt2Latch (bool enable)
 
bool setInterrupt1PadConfig (I_CFG_BITS_T val)
 
bool setInterrupt2PadConfig (I_CFG_BITS_T val)
 
bool enableBDU (bool enable)
 
bool enableBLE (bool enable)
 
bool enableSleepToWake (bool enable)
 
uint8_t getStatus ()
 
bool setInterrupt1Config (uint8_t val)
 
bool setInterrupt2Config (uint8_t val)
 
bool setInterrupt1Source (uint8_t val)
 
bool setInterrupt2Source (uint8_t val)
 
bool setInterrupt1Threshold (uint8_t val)
 
bool setInterrupt2Threshold (uint8_t val)
 
bool setInterrupt1Duration (uint8_t val)
 
bool setInterrupt2Duration (uint8_t val)
 
void update ()
 
void setAdjustmentOffsets (int adjX, int adjY, int adjZ)
 
void getAcceleration (float *aX, float *aY, float *aZ)
 
void getRawXYZ (int *x, int *y, int *z)
 
void getXYZ (int *x, int *y, int *z)
 
mraa::I2c & i2cContext ()
 

Protected Attributes

int16_t m_rawX
 
int16_t m_rawY
 
int16_t m_rawZ
 
int16_t m_adjX
 
int16_t m_adjY
 
int16_t m_adjZ
 
mraa::I2c m_i2c
 

Member Enumeration Documentation

H3LIS331DL registers

REG1 bits

enum DR_BITS_T

REG1 DR (output rate) bits

enum PM_BITS_T

REG1 PM (power mode) bits

REG2 bits

REG2 HPCF (high-pass cutoff frequency) bits

enum HPM_BITS_T

REG2 HPM (high-pass filter mode) bits

REG3 bits

REG3 I1/I2 PAD control bits

REG4 bits

enum FS_BITS_T

REG4 FS (full scale) bits

REG5 TURNON (sleep to wake) bits

STATUS bits

INT1/INT2 CFG bits

INT1/INT2 SRC bits

Constructor & Destructor Documentation

H3LIS331DL ( int  bus,
uint8_t  address = H3LIS331DL_DEFAULT_I2C_ADDR 
)

H3LIS331DL constructor

Parameters
busI2C bus to use
addressAddress for this device

Here is the call graph for this function:

~H3LIS331DL ( )

H3LIS331DL destructor

Member Function Documentation

bool init ( DR_BITS_T  odr = DR_50_37,
PM_BITS_T  pm = PM_NORMAL,
FS_BITS_T  fs = FS_100 
)

Sets up initial values and starts operation

Parameters
odrData rate: one of the DR_BITS_T values
pmPower mode: one of the PM_BITS_T values
fsFullScale: one of the FS_BITS_T values
Returns
True if successful

Here is the call graph for this function:

uint8_t getChipID ( )

Reads and returns the chip ID (WHO_AM_I register)

Returns
True if successful
bool setDataRate ( DR_BITS_T  odr)

Sets the output data rate

Parameters
Oneof the DR_BITS_T values
Returns
True if successful

Here is the caller graph for this function:

bool setPowerMode ( PM_BITS_T  pm)

Sets the power mode

Parameters
Oneof the PM_BITS_T values
Returns
True if successful

Here is the caller graph for this function:

bool enableAxis ( uint8_t  axisEnable)

Enables one or more of the 3 axes. The argument is a bitmask composed of REG1_XEN, REG1_YEN, and/or REG1_ZEN corresponding to the axes you want enabled.

Parameters
axisEnableBitmask of axes to enable (REG1_XEN | REG1_YEN | REG1_ZEN)
Returns
True if successful

Here is the caller graph for this function:

bool setFullScale ( FS_BITS_T  fs)

Sets the scaling factor to 100g, 200g, or 400g

Parameters
fsOne of the FS_BITS_T values
Returns
True if successful

Here is the caller graph for this function:

bool setHPCF ( HPCF_BITS_T  val)

Sets a high-pass cutoff filter

Parameters
valOne of the HPCF_BITS_T values
Returns
True if successful
bool setHPM ( HPM_BITS_T  val)

Sets a high-pass filter mode

Parameters
valOne of the HPM_BITS_T values
Returns
True if successful
bool boot ( )

Boots the device. Booting the device causes internal flash calibration values to be reloaded into the visible registers in case they have been corrupted. This function returns when the booting is complete.

Returns
True if successful
bool enableHPF1 ( bool  enable)

Enables a high-pass filter for interrupt 1 source

Parameters
enableTrue to enable the filter, false otherwise
Returns
True if successful
bool enableHPF2 ( bool  enable)

Enables a high-pass filter for interrupt 2 source

Parameters
enableTrue to enable the filter, false otherwise
Returns
True if successful
bool enableFDS ( bool  enable)

Enables filtered data selection

Parameters
enableTrue to enable, false otherwise
Returns
True if successful
bool setInterruptActiveLow ( bool  enable)

Sets interrupts to be active low instead of high

Parameters
enableTrue to enable, false otherwise
Returns
True if successful
bool setInterruptOpenDrain ( bool  enable)

Sets an interrupt output mode to open drain rather than push/pull

Parameters
enableTrue to enable, false otherwise
Returns
True if successful
bool setInterrupt1Latch ( bool  enable)

Enables interrupt 1 latch

Parameters
enableTrue to enable, false otherwise
Returns
True if successful
bool setInterrupt2Latch ( bool  enable)

Enables interrupt 2 latch

Parameters
enableTrue to enable, false otherwise
Returns
True if successful
bool setInterrupt1PadConfig ( I_CFG_BITS_T  val)

Sets the interrupt 1 pad configuration

Parameters
valOne fo the I_CFG_BITS_T values
Returns
True if successful
bool setInterrupt2PadConfig ( I_CFG_BITS_T  val)

Sets the interrupt 2 pad configuration

Parameters
valOne fo the I_CFG_BITS_T values
Returns
True if successful
bool enableBDU ( bool  enable)

Enables block data update. When enabled, low/high output registers are not updated until both low and high values have been read.

Parameters
enableTrue to enable, false otherwise
Returns
True if successful
bool enableBLE ( bool  enable)

Enables big-endian output for 16b reads

Parameters
enableTrue to enable, false otherwise
Returns
True if successful
bool enableSleepToWake ( bool  enable)

Enables sleep-to-wake functionality

Parameters
enableTrue to enable, false otherwise
Returns
True if successful
uint8_t getStatus ( )

Returns the contents of the REG_STATUS register

Returns
Contents of the REG_STATUS register
bool setInterrupt1Config ( uint8_t  val)

Sets up the interrupt 1 config register

Parameters
valBitmask of desired INT_CFG_BITS_T bits
Returns
True if successful
bool setInterrupt2Config ( uint8_t  val)

Sets up the interrupt 2 config register

Parameters
valBitmask of desired INT_CFG_BITS_T bits
Returns
True if successful
bool setInterrupt1Source ( uint8_t  val)

Sets up the interrupt 1 source register

Parameters
valBitmask of desired INT_SRC_BITS_T bits
Returns
True if successful
bool setInterrupt2Source ( uint8_t  val)

Sets up the interrupt 2 source register

Parameters
valBitmask of desired INT_SRC_BITS_T bits
Returns
True if successful
bool setInterrupt1Threshold ( uint8_t  val)

Sets up the interrupt 1 threshold register

Parameters
valThreshhold to set
Returns
True if successful
bool setInterrupt2Threshold ( uint8_t  val)

Sets up the interrupt 2 threshold register

Parameters
valThreshhold to set
Returns
True if successful
bool setInterrupt1Duration ( uint8_t  val)

Sets up the interrupt 1 duration register

Parameters
valDuration to set
Returns
True if successful
bool setInterrupt2Duration ( uint8_t  val)

Sets up the interrupt 2 duration register

Parameters
valDuration to set
Returns
True if successful
void update ( void  )

Reads the sensor and stores current values internally

void setAdjustmentOffsets ( int  adjX,
int  adjY,
int  adjZ 
)

Sets adjustment offsets for each of the axes. This can be used for calibration. The values supplied here are subtracted from the axis data read from the device.

Parameters
adjXAmount by which to correct the X-axis measurement
adjYAmount by which to correct the Y-axis measurement
adjZAmount by which to correct the Z-axis measurement

Here is the caller graph for this function:

void getAcceleration ( float *  aX,
float *  aY,
float *  aZ 
)

Gets acceleration values for each of the axes

Parameters
aXReturned X-axis acceleration
aYReturned Y-axis acceleration
aZReturned Z-axis acceleration
void getRawXYZ ( int *  x,
int *  y,
int *  z 
)

Gets raw axis values

Parameters
xReturned raw X-axis value
yReturned raw Y-axis value
zReturned raw Z-axis value
void getXYZ ( int *  x,
int *  y,
int *  z 
)

Gets adjusted axis values

Parameters
xReturned X-axis value
yReturned Y-axis value
zReturned Z-axis value
mraa::I2c& i2cContext ( )
inline

Provides public access to the MRAA I2C context of the class for direct user access

Returns
Reference to the class I2C context

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