LIS3DH

Hex.pmLicense: Apache-2.0

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

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"}
  ]
end

Documentation 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.