LIS3DH Propeller C library
v1.0.0
Propeller C Library for the Parallax LIS3DH 3 Axis Accelerometer with ADC module
|
Functions | |
lis3dh_t * | lis3dh_init (int pinSCK, int pinSDI, int pinCS) |
Initialize the sensor with typical configuration for reading axis and adc. Uses 3-Wire SPI mode. More... | |
lis3dh_t * | lis3dh_init4wire (int pinSCK, int pinSDI, int pinSDO, int pinCS) |
Initialize the sensor with typical configuration for reading axis and adc. Uses 4-Wire SPI mode. More... | |
void | lis3dh_shutdown (lis3dh_t *device) |
Shutdown the sensor, set configuration defaults with sensor disabled and clear buffers. More... | |
int | lis3dh_getWhoAmI (lis3dh_t *device) |
Reads the sensor identification register (WhoAmI). More... | |
void | lis3dh_setResolution (lis3dh_t *device, int bits) |
Sets the bit resolution for the sensor readings. 8-bit, 10-bit or 12-bit. More... | |
int | lis3dh_getResolution (lis3dh_t *device) |
Reads the bit resolution setting from the sensor. 8-bit, 10-bit or 12-bit. More... | |
void | lis3dh_setRange (lis3dh_t *device, int range) |
Sets the g measurement range to +/- 2, +/-4, +/- 8, +- 16 g. More... | |
int | lis3dh_getRange (lis3dh_t *device) |
Reads the g measurement range; one of +/- 2, +/-4, +/- 8, +- 16 g. More... | |
void | lis3dh_setSPImode (lis3dh_t *device, int mode) |
Sets the SPI mode to either 3-wire or 4-wire. More... | |
int | lis3dh_getSPImode (lis3dh_t *device) |
Read the SPI mode currently configured in the LIS3DH module; either 3-wire or 4-wire. More... | |
void | lis3dh_setBDUmode (lis3dh_t *device, int mode) |
Sets the sensor BDU (Block Data Update) mode. More... | |
void | lis3dh_setADCmode (lis3dh_t *device, int adcEnable, int tempEnable) |
Sets ADC mode for the Parallax LIS3DH 3-Axis Accelerometer Module. More... | |
void | lis3dh_adc (lis3dh_t *device, int *ad1, int *ad2, int *ad3) |
Gets raw adc measurements from all three ADC channels. More... | |
int | lis3dh_getADC (lis3dh_t *device, int channel) |
Gets raw adc measurement from a single ADC channel. More... | |
void | lis3dh_adc_mV (lis3dh_t *device, int *ad1, int *ad2, int *ad3) |
Gets mV adc measurements from all three ADC channels. More... | |
int | lis3dh_getADC_mV (lis3dh_t *device, int channel) |
Gets mV adc measurement from a single ADC channel. More... | |
void | lis3dh_adcCal_mV (lis3dh_t *device, int mV_L, int mV_H, int value_L, int value_H) |
Sets the adc calibration values for adc mV reading on AD1. More... | |
void | lis3dh_tempCal_C (lis3dh_t *device, int actualTempC) |
Sets the actual temperature to provide a reference for the relative temperature sensor. More... | |
void | lis3dh_tempCal_F (lis3dh_t *device, int actualTempF) |
Sets the actual temperature to provide a reference for the relative temperature sensor. More... | |
int | lis3dh_tempRaw (lis3dh_t *device) |
Reads the raw relative temperature value from the sensor. More... | |
int | lis3dh_temp_C (lis3dh_t *device) |
Reads the calibrated (referenced) temperature value from the sensor. More... | |
int | lis3dh_temp_F (lis3dh_t *device) |
Reads the calibrated (referenced) temperature value from the sensor. More... | |
int | lis3dh_accel (lis3dh_t *device, int *x, int *y, int *z) |
Gets raw accelerometer measurements from all three axis (x, y, z). More... | |
int | lis3dh_getAccel (lis3dh_t *device, int axis) |
Gets raw accelerometer measurements for a single axis (x, y, or z). More... | |
int | lis3dh_accel_mg (lis3dh_t *device, int *xmg, int *ymg, int *zmg) |
Gets mg (milli-g's) accelerometer measurements from all three axis (x, y, z). More... | |
int | lis3dh_getAccel_mg (lis3dh_t *device, int axis) |
Gets mg (milli-g's) accelerometer measurements from a single axis (x, y, or z). More... | |
int | lis3dh_tilt (lis3dh_t *device, int *ax, int *ay, int *az, int *motion) |
Gets tilt angle measurements for each axis, and magnitude of motion. More... | |
int | lis3dh_tiltConfig (lis3dh_t *device, int avg_factor) |
Optional configuration for tilt sensor. More... | |
void | lis3dh_writeByte (lis3dh_t *device, unsigned char address, unsigned char value) |
write a byte value to an LIS3DH register More... | |
unsigned char | lis3dh_readByte (lis3dh_t *device, unsigned char address) |
Read a value from an LIS3DH register. More... | |
int lis3dh_accel | ( | lis3dh_t * | device, |
int * | x, | ||
int * | y, | ||
int * | z | ||
) |
Gets raw accelerometer measurements from all three axis (x, y, z).
Resolution is user-configured in the sensor to 8, 10 or 12 bit. (Refer to setResolution and getResolution functions). Range is user-configured in the sensor as +/- 2, +/-4, +/- 8, +- 16 g. (Refer to setRange and getRange functions).
device | Pointer to the sensor device structure |
*x | Variable to store x axis reading into, scaled by resolution and range. |
*y | Variable to store x axis reading into, scaled by resolution and range. |
*z | Variable to store x axis reading into, scaled by resolution and range. |
int lis3dh_accel_mg | ( | lis3dh_t * | device, |
int * | xmg, | ||
int * | ymg, | ||
int * | zmg | ||
) |
Gets mg (milli-g's) accelerometer measurements from all three axis (x, y, z).
Resolution is user-configured in the sensor to 8, 10 or 12 bit. (Refer to setResolution and getResolution functions). Range is user-configured in the sensor as +/- 2, +/-4, +/- 8, +- 16 g. (Refer to setRange and getRange functions).
device | Pointer to the sensor device structure |
*xmg | Variable to store x axis reading into, scaled by resolution and range, converted to milli-g's. |
*ymg | Variable to store x axis reading into, scaled by resolution and range, converted to milli-g's. |
*zmg | Variable to store x axis reading into, scaled by resolution and range, converted to milli-g's. |
void lis3dh_adc | ( | lis3dh_t * | device, |
int * | ad1, | ||
int * | ad2, | ||
int * | ad3 | ||
) |
Gets raw adc measurements from all three ADC channels.
ADC resolution is user-configured in the sensor to 8 or 10 bit. (Refer to setResolution and getResolution functions).
device | Pointer to the sensor device structure |
*ad1 | Variable to store ADC channel 1 reading into, scaled to ADC resolution. |
*ad2 | Variable to store ADC channel 2 reading into, scaled to ADC resolution. |
*ad3 | Variable to store ADC channel 3 reading into, scaled to ADC resolution. |
void lis3dh_adc_mV | ( | lis3dh_t * | device, |
int * | ad1, | ||
int * | ad2, | ||
int * | ad3 | ||
) |
Gets mV adc measurements from all three ADC channels.
ADC resolution is user-configured in the sensor to 8 or 10 bit. (Refer to setResolution and getResolution functions).
device | Pointer to the sensor device structure |
*ad1 | Variable to store ADC channel 1 reading into, scaled to ADC resolution. |
*ad2 | Variable to store ADC channel 2 reading into, scaled to ADC resolution. |
*ad3 | Variable to store ADC channel 3 reading into, scaled to ADC resolution. |
void lis3dh_adcCal_mV | ( | lis3dh_t * | device, |
int | mV_L, | ||
int | mV_H, | ||
int | value_L, | ||
int | value_H | ||
) |
Sets the adc calibration values for adc mV reading on AD1.
The internal adc has an initial tolerance of +-400mV, and may require calibration before use.
device | Pointer to the sensor device structure |
mV_L | Value for ADC mV calibration - voltage at which lower calibration reading taken, in millivolts |
mV_H | Value for ADC mV calibration - voltage at which upper calibration reading taken, in millivolts |
value_L | Value for ADC mV calibration - value measured at lower calibration voltage, in millivolts |
value_H | Value for ADC mV calibration - value measured at upper calibration voltage, in millivolts |
int lis3dh_getAccel | ( | lis3dh_t * | device, |
int | axis | ||
) |
Gets raw accelerometer measurements for a single axis (x, y, or z).
Resolution is user-configured in the sensor to 8, 10 or 12 bit. (Refer to setResolution and getResolution functions). Range is user-configured in the sensor as +/- 2, +/-4, +/- 8, +- 16 g. (Refer to setRange and getRange functions).
device | Pointer to the sensor device structure |
axis | Value of the axis to read from. Must be 1, 2 or 3 (representing x, y or z). |
int lis3dh_getAccel_mg | ( | lis3dh_t * | device, |
int | axis | ||
) |
Gets mg (milli-g's) accelerometer measurements from a single axis (x, y, or z).
Resolution is user-configured in the sensor to 8, 10 or 12 bit. (Refer to setResolution and getResolution functions). Range is user-configured in the sensor as +/- 2, +/-4, +/- 8, +- 16 g. (Refer to setRange and getRange functions).
device | Pointer to the sensor device structure |
axis | Value of the axis to read from. Must be 1, 2 or 3 (representing x, y or z). |
int lis3dh_getADC | ( | lis3dh_t * | device, |
int | channel | ||
) |
Gets raw adc measurement from a single ADC channel.
ADC resolution is user-configured in the sensor to 8 or 10 bit. (Refer to setResolution and getResolution functions).
device | Pointer to the sensor device structure |
channel | Value of the ADC channel to read from. Must be 1, 2 or 3. |
int lis3dh_getADC_mV | ( | lis3dh_t * | device, |
int | channel | ||
) |
Gets mV adc measurement from a single ADC channel.
ADC resolution is user-configured in the sensor to 8 or 10 bit. (Refer to setResolution and getResolution functions).
device | Pointer to the sensor device structure |
channel | Value of the ADC channel to read from. Must be 1, 2 or 3. |
int lis3dh_getRange | ( | lis3dh_t * | device | ) |
Reads the g measurement range; one of +/- 2, +/-4, +/- 8, +- 16 g.
device | Pointer to the sensor device structure |
int lis3dh_getResolution | ( | lis3dh_t * | device | ) |
Reads the bit resolution setting from the sensor. 8-bit, 10-bit or 12-bit.
device | Pointer to the sensor device structure |
int lis3dh_getSPImode | ( | lis3dh_t * | device | ) |
Read the SPI mode currently configured in the LIS3DH module; either 3-wire or 4-wire.
device | Pointer to the sensor device structure |
int lis3dh_getWhoAmI | ( | lis3dh_t * | device | ) |
Reads the sensor identification register (WhoAmI).
device | Pointer to the sensor device structure |
lis3dh_t* lis3dh_init | ( | int | pinSCK, |
int | pinSDI, | ||
int | pinCS | ||
) |
Initialize the sensor with typical configuration for reading axis and adc. Uses 3-Wire SPI mode.
pinSCK | I/O pin connected to the SCK pin. |
pinSDI | I/O pin connected to the SDI pin. |
pinCS | I/O pin connected to the /CS pin. |
lis3dh_t* lis3dh_init4wire | ( | int | pinSCK, |
int | pinSDI, | ||
int | pinSDO, | ||
int | pinCS | ||
) |
Initialize the sensor with typical configuration for reading axis and adc. Uses 4-Wire SPI mode.
pinSCK | I/O pin connected to the SCK pin. |
pinSDI | I/O pin connected to the SDI pin. |
pinSDO | I/O pin connected to the SDO pin. |
pinCS | I/O pin connected to the /CS pin. |
unsigned char lis3dh_readByte | ( | lis3dh_t * | device, |
unsigned char | address | ||
) |
Read a value from an LIS3DH register.
device | Pointer to the sensor device structure |
address | LIS3DH register address. |
void lis3dh_setADCmode | ( | lis3dh_t * | device, |
int | adcEnable, | ||
int | tempEnable | ||
) |
Sets ADC mode for the Parallax LIS3DH 3-Axis Accelerometer Module.
device | Pointer to the sensor device structure |
adcEnable | 1 = ADC enabled, 0 = ADC disabled |
tempEnable | ADC channel 3 (AD3) source control. 1 = Internal temperature sensor, 0 = Input on AD3 pin |
void lis3dh_setBDUmode | ( | lis3dh_t * | device, |
int | mode | ||
) |
Sets the sensor BDU (Block Data Update) mode.
device | Pointer to the sensor device structure |
mode | expects a constant which represents the BDU mode (LIS3DH_BDUMODE_COMPLETE or LIS3DH_BDUMODE_CONTINUOUS) |
LIS3DH_BDUMODE_CONTINUOUS means data is ready to be read as each register is updated LIS3DH_BDUMODE_CONSISTENT means data is only ready to be read when both LSB and MSB registers are updated
void lis3dh_setRange | ( | lis3dh_t * | device, |
int | range | ||
) |
Sets the g measurement range to +/- 2, +/-4, +/- 8, +- 16 g.
This function makes the sensor apply scalars to the accelerometer readings. Higher range setting reduces sensitivy.
device | Pointer to the sensor device structure |
range | Value representing the GForce range (sensitivity). Must be 2, 4, 8 or 16 |
void lis3dh_setResolution | ( | lis3dh_t * | device, |
int | bits | ||
) |
Sets the bit resolution for the sensor readings. 8-bit, 10-bit or 12-bit.
Values returned when reading the accelerometer axis or adc will be sampled according to the resolution number of bits.
device | Pointer to the sensor device structure |
bits | Value to set the sensor resolution. Must be 8, 10 or 12. |
void lis3dh_setSPImode | ( | lis3dh_t * | device, |
int | mode | ||
) |
Sets the SPI mode to either 3-wire or 4-wire.
device | Pointer to the sensor device structure |
mode | Value representing SPI wire mode. Must be 3 or 4. |
void lis3dh_shutdown | ( | lis3dh_t * | device | ) |
Shutdown the sensor, set configuration defaults with sensor disabled and clear buffers.
device | Pointer to the sensor device structure |
int lis3dh_temp_C | ( | lis3dh_t * | device | ) |
Reads the calibrated (referenced) temperature value from the sensor.
The internal temperature sensor is a relative mode sensor, and requires calibration before use. In 8-bit mode, the raw value will change 1 digit / degree Celcius change.
device | Pointer to the sensor device structure |
int lis3dh_temp_F | ( | lis3dh_t * | device | ) |
Reads the calibrated (referenced) temperature value from the sensor.
The internal temperature sensor is a relative mode sensor, and requires calibration before use. In 8-bit mode, the raw value will change 1 digit / degree Celcius change.
device | Pointer to the sensor device structure |
void lis3dh_tempCal_C | ( | lis3dh_t * | device, |
int | actualTempC | ||
) |
Sets the actual temperature to provide a reference for the relative temperature sensor.
The internal temperature sensor is a relative mode sensor, and requires calibration before use.
device | Pointer to the sensor device structure |
actualTempC | Value of the temperature in degrees Celcius, where the sensor is being used. |
void lis3dh_tempCal_F | ( | lis3dh_t * | device, |
int | actualTempF | ||
) |
Sets the actual temperature to provide a reference for the relative temperature sensor.
The internal temperature sensor is a relative mode sensor, and requires calibration before use.
device | Pointer to the sensor device structure |
actualTempF | Value of the temperature in degrees Fahrenheit, where the sensor is being used. |
int lis3dh_tempRaw | ( | lis3dh_t * | device | ) |
Reads the raw relative temperature value from the sensor.
The internal temperature sensor is a relative mode sensor, and requires calibration before use. In 8-bit mode, the raw value will change 1 digit / degree Celcius change.
device | Pointer to the sensor device structure |
int lis3dh_tilt | ( | lis3dh_t * | device, |
int * | ax, | ||
int * | ay, | ||
int * | az, | ||
int * | motion | ||
) |
Gets tilt angle measurements for each axis, and magnitude of motion.
Angle to each axis in degrees, X relative to ground Y relative to ground Z relative to gravity. Motion is the sum of g-force on all axis relative to gravity at ground level (1G). 0 is motionless, larger positve or negative values represent more intense motion. The motion value could be used on it's own for projects requiring vibration sensing.
device | Pointer to the sensor device structure |
*ax | Variable to store angle of x axis relative to ground. |
*ay | Variable to store angle of y axis relative to ground. |
*az | Variable to store angle of z axis relative to gravity. |
*motion | Variable to store positive or negative value representing intensity of motion, with 0 being motionless at ground level. |
int lis3dh_tiltConfig | ( | lis3dh_t * | device, |
int | avg_factor | ||
) |
Optional configuration for tilt sensor.
Values stored in RAM. Reasonable defaults are set by the library.
device | Pointer to the sensor device structure |
avg_factor | Percentage of new data added to tilt readings low pass filter (moving average). Valid values are 0 to 100. (Setting 0 or 100 will disable the filter. For example, if avg_factor is 75, moving average calculation will include 75% new data and 25% existing data. Default value = 100 (moving average low pass filter disabled). |
void lis3dh_writeByte | ( | lis3dh_t * | device, |
unsigned char | address, | ||
unsigned char | value | ||
) |
write a byte value to an LIS3DH register
device | Pointer to the sensor device structure |
address | LIS3DH register address. |
value | Configuration value for the register. |