pyupm_lis3dh module

class pyupm_lis3dh.LIS3DH(bus=0, addr=24, cs=-1)[source]

Bases: object

API for the LIS3DH 3-axis Accelerometer.

ID: lis3dh

Name: Digital 3-axis Accelerometer

Category: accelerometer

Manufacturer: stmicro

Connection: i2c spi gpio

Link:http://www.st.com/en/mems-and-sensors/lis3dh.html The LIS3DH is an ultra-low-power high performance three-axis linear accelerometer belonging to the “nano” family which leverages on the robust and mature manufacturing processes already used for the production of micromachined accelerometers.

The LIS3DH has user-selectable full scales of 2g/4g/8g/16g and is capable of measuring accelerations with output data rates from 1 Hz to 5300 Hz.

Not all functionality of this chip has been implemented in this driver, however all the pieces are present to add any desired functionality. This driver supports both I2C (default) and SPI operation.

C++ includes: lis3dh.hpp

enableADC(adc_enable)[source]

void enableADC(bool adc_enable)

Enable or disable built-in Analog-to-Digital Converter (ADC).

adc_enable: true to enable ADC, false to disable

std::runtime_error: on failure

enableAxes(x_axis_enable, y_axis_enable, z_axis_enable)[source]

void enableAxes(bool x_axis_enable, bool y_axis_enable, bool z_axis_enable)

Enable or disable specific axes. init() enables all three by default.

x_axis_enable: true to enable X axis, false to disable

y_axis_enable: true to enable Y axis, false to disable

z_axis_enable: true to enable Z axis, false to disable

std::runtime_error: on failure

enableBDUMode(bdu_enable)[source]

void enableBDUMode(bool bdu_enable)

Enable or disable Block Data Update (BDU) mode.

bdu_enable: true to enable BDU mode, false to disable

std::runtime_error: on failure

enableHPFiltering(filter)[source]

void enableHPFiltering(bool filter)

Enable high pass filtering of the accelerometer axis data. init() disables this by default. See the datasheet for details.

filter: true to enable filtering, false to disable

std::runtime_error: on failure

enableHRMode(hr_enable)[source]

void enableHRMode(bool hr_enable)

Enable or disable High Resolution (HR) mode. Checks if mutually exclusive Low Power (LP) mode is enabled and bails out if yes.

hr_enable: true to enable HR mode, false to disable

std::runtime_error: on failure

enableInterruptLatching(int1_latch, int2_latch)[source]

void enableInterruptLatching(bool int1_latch, bool int2_latch)

Enable or disable interrupt latching for INT1 and INT2. See the datasheet for details.

int1_latch: true to enable latching for INT1, false to disable

int2_latch: true to enable latching for INT2, false to disable

std::runtime_error: on failure

enableLPMode(lp_enable)[source]

void enableLPMode(bool lp_enable)

Enable or disable Low Power (LP) mode. Checks if mutually exclusive High Resolution (HR) mode is enabled and bails out if yes.

lp_enable: true to enable LP mode, false to disable

std::runtime_error: on failure

enableNormalMode()[source]

void enableNormalMode()

Enable Normal mode by explicitly disabling LP and HR ones. Note that there’s no “disable” part as it’s generally unknown, which mode we were in previously. To get out of Normal mode, just enable HR or LP one.

std::runtime_error: on failure

enableTemperature(temperature_enable)[source]

void enableTemperature(bool temperature_enable)

Enable or disable built-in temperature sensor. It depends on ADC being enabled, so we enable it unconditionally. See datasheet for details.

temperature_enable: true to enable temp sensor, false to disable

std::runtime_error: on failure

getAccelerometer(*args)[source]

std::vector< float > getAccelerometer()

Return accelerometer data in gravities in the form of a floating point vector. update() must have been called prior to calling this method.

A floating point vector containing x, y and z in that order

getChipID()[source]

uint8_t getChipID()

Return the chip ID

The chip ID

getStatus()[source]

uint8_t getStatus()

Return the contents of the status register

A bitmask of values from LIS3DH_STATUS_REG_BITS_T

getStatusAux()[source]

uint8_t getStatusAux()

Return the contents of the status aux register

A bitmask of values from LIS3DH_STATUS_REG_AUX_BITS_T

getTemperature(fahrenheit=False)[source]

float getTemperature(bool fahrenheit=false)

Return the current measured temperature. Note, this is not ambient temperature. update() must have been called prior to calling this method.

fahrenheit: true to return data in Fahrenheit, false for Celicus. Celsius is the default.

The temperature in degrees Celsius or Fahrenheit

init(odr=5, fs=0, high_res=True)[source]

void init(LIS3DH_ODR_T odr=LIS3DH_ODR_100HZ, LIS3DH_FS_T fs=LIS3DH_FS_2G, bool high_res=true)

Initialize the device and start operation. This function is called from the constructor so will not typically need to be called by a user unless the device is reset.

odr: One of the LIS3DH_ODR_T values. The default is LIS3DH_ODR_100HZ

fs: One of the LIS3DH_FS_T values. The default is LIS3DH_FS_2G

high_res: true to enable high resolution mode, false to disable. The default is true.

std::runtime_error: on failure

installISR(intr, gpio, level, isr, arg)[source]

void installISR(LIS3DH_INTERRUPT_PINS_T intr, int gpio, mraa::Edge level, void(*isr)(void *), void *arg)

Install an interrupt handler

intr: One of the LIS3DH_INTERRUPT_PINS_T values specifying which interrupt pin you are installing

gpio: GPIO pin to use as interrupt pin

level: The interrupt trigger level (one of mraa::Edge values). Make sure that you have configured the interrupt pin properly for whatever level you choose.

isr: The interrupt handler, accepting a void * argument

arg: The argument to pass the the interrupt handler

std::runtime_error: on failure

readReg(reg)[source]

uint8_t readReg(uint8_t reg)

Read a register

reg: The register to read

The value of the register

readRegs(reg, buffer, len)[source]

int readRegs(uint8_t reg, uint8_t *buffer, int len)

Read contiguous registers into a buffer

reg: The register to start the read from

buffer: The buffer to store the results

len: The number of registers to read

The number of bytes read

std::runtime_error: on failure

setFullScale(fs)[source]

void setFullScale(LIS3DH_FS_T fs)

Set the full scale (FS) of the device. This device supports a full scale of 2, 4, 8 and 16G.

fs: One of the LIS3DH_FS_T values

std::runtime_error: on failure

setInt1Config(cfg)[source]

void setInt1Config(uint8_t cfg)

Set interrupt 1 configuration. See the datasheet for details.

cfg: A bitmask of values from LIS3DH_CTRL_REG3_BITS_T

std::runtime_error: on failure

setInt2Config(cfg)[source]

void setInt2Config(uint8_t cfg)

Set interrupt 2 configuration. See the datasheet for details.

cfg: A bitmask of values from LIS3DH_CTRL_REG6_BITS_T

std::runtime_error: on failure

setInterruptActiveHigh(high)[source]

void setInterruptActiveHigh(bool high)

Indicate whether INT1 and INT2 interrupts should be active high (default) or active low. See the datasheet for details.

high: true for active high, false for active low

std::runtime_error: on failure

setODR(odr)[source]

void setODR(LIS3DH_ODR_T odr)

Set the output data rate (ODR) of the device

odr: One of the LIS3DH_ODR_T values

std::runtime_error: on failure

uninstallISR(intr)[source]

void uninstallISR(LIS3DH_INTERRUPT_PINS_T intr)

Uninstall a previously installed interrupt handler

intr: One of the LIS3DH_INTERRUPT_PINS_T values, specifying which interrupt pin you are removing

update()[source]

void update()

Update the internal stored values from sensor data

std::runtime_error: on failure

writeReg(reg, val)[source]

void writeReg(uint8_t reg, uint8_t val)

Write to a register

reg: The register to write to

val: The value to write

std::runtime_error: on failure

class pyupm_lis3dh.SwigPyIterator(*args, **kwargs)[source]

Bases: object

advance(n)[source]
copy()[source]
decr(n=1)[source]
distance(x)[source]
equal(x)[source]
incr(n=1)[source]
next()[source]
previous()[source]
value()[source]
class pyupm_lis3dh.byteVector(*args)[source]

Bases: object

append(x)[source]
assign(n, x)[source]
back()[source]
begin()[source]
capacity()[source]
clear()[source]
empty()[source]
end()[source]
erase(*args)[source]
front()[source]
get_allocator()[source]
insert(*args)[source]
iterator()[source]
pop()[source]
pop_back()[source]
push_back(x)[source]
rbegin()[source]
rend()[source]
reserve(n)[source]
resize(*args)[source]
size()[source]
swap(v)[source]
class pyupm_lis3dh.doubleVector(*args)[source]

Bases: object

append(x)[source]
assign(n, x)[source]
back()[source]
begin()[source]
capacity()[source]
clear()[source]
empty()[source]
end()[source]
erase(*args)[source]
front()[source]
get_allocator()[source]
insert(*args)[source]
iterator()[source]
pop()[source]
pop_back()[source]
push_back(x)[source]
rbegin()[source]
rend()[source]
reserve(n)[source]
resize(*args)[source]
size()[source]
swap(v)[source]
class pyupm_lis3dh.floatVector(*args)[source]

Bases: object

append(x)[source]
assign(n, x)[source]
back()[source]
begin()[source]
capacity()[source]
clear()[source]
empty()[source]
end()[source]
erase(*args)[source]
front()[source]
get_allocator()[source]
insert(*args)[source]
iterator()[source]
pop()[source]
pop_back()[source]
push_back(x)[source]
rbegin()[source]
rend()[source]
reserve(n)[source]
resize(*args)[source]
size()[source]
swap(v)[source]
class pyupm_lis3dh.int16Vector(*args)[source]

Bases: object

append(x)[source]
assign(n, x)[source]
back()[source]
begin()[source]
capacity()[source]
clear()[source]
empty()[source]
end()[source]
erase(*args)[source]
front()[source]
get_allocator()[source]
insert(*args)[source]
iterator()[source]
pop()[source]
pop_back()[source]
push_back(x)[source]
rbegin()[source]
rend()[source]
reserve(n)[source]
resize(*args)[source]
size()[source]
swap(v)[source]
class pyupm_lis3dh.intVector(*args)[source]

Bases: object

append(x)[source]
assign(n, x)[source]
back()[source]
begin()[source]
capacity()[source]
clear()[source]
empty()[source]
end()[source]
erase(*args)[source]
front()[source]
get_allocator()[source]
insert(*args)[source]
iterator()[source]
pop()[source]
pop_back()[source]
push_back(x)[source]
rbegin()[source]
rend()[source]
reserve(n)[source]
resize(*args)[source]
size()[source]
swap(v)[source]