LIS3DH
Elixir driver for the STMicroelectronics LIS3DH 3-axis MEMS accelerometer, connected over I²C.
Built on Wafer, so it's independent of any
particular I²C backend — use circuits_i2c
on a Nerves target, circuits_ft232h
when developing on a laptop, or any other Wafer.I2C implementation.
I'm prototyping against Adafruit's breakout.
Features
- Configurable operating mode (low-power 8-bit, normal 10-bit, high-resolution 12-bit), output data rate, ±2/4/8/16 g range, per-axis enables, and block-data-update.
- Acceleration reads scaled to m/s² for the active mode and range.
-
High-pass filter configuration and
REFERENCEregister access. -
FIFO sampler (
LIS3DH.Sampler) with bypass, stream, stream-to-FIFO, and FIFO modes. - Inertial interrupts: free-fall, motion / wake-up, 4D and 6D orientation, and activity (sleep-to-wake).
- Single- and double-click / tap detection.
- Self-test toggle (per ST application note AN3308).
- Auxiliary ADC (3 channels) and the embedded temperature sensor.
-
Routable interrupt pins (
INT1,INT2) with polarity and latching controls.
Usage
iex> {:ok, conn} = Wafer.Driver.Circuits.I2C.acquire(bus_name: "i2c-1", address: 0x18)
iex> {:ok, acc} = LIS3DH.acquire(conn: conn)
iex> {:ok, acc} = LIS3DH.configure_accelerometer(acc, mode: :normal, odr: 100, range: 2)
iex> LIS3DH.read_accelerometer(acc)
{:ok, %{x: 0.157, y: -0.118, z: 9.083}}acquire/1 verifies the device's WHO_AM_I by default; pass
verify_who_am_i: false to skip it, or reboot: true to refresh the trim
registers from non-volatile memory before reading.
The 7-bit I²C address is 0x18 when the SA0 pin is tied to GND, or 0x19
when tied to VDD.
See the moduledoc and LIS3DH.Sampler, LIS3DH.Interrupts, and LIS3DH.Click
for the full API.
Installation
The lis3dh package is available on Hex and
can be installed by adding it to your dependencies in mix.exs:
def deps do
[
{:lis3dh, "~> 0.1.0"}
]
endDocumentation for the latest release is on HexDocs.
GitHub mirror
This repository is mirrored on GitHub from its primary location on my Forgejo instance. Feel free to raise issues and open PRs on either.
License
This software is licensed under the terms of the Apache 2.0 license.