adafruit_adxl34x

A driver for the ADXL34x 3-axis accelerometer family

  • Author(s): Bryan Siepert

Based on drivers by K. Townsend and Tony DiCola

Implementation Notes

Hardware:

Software and Dependencies:

class adafruit_adxl34x.ADXL343(i2c: I2C, address: int = 83)

Stub class for the ADXL343 3-axis accelerometer

class adafruit_adxl34x.ADXL345(i2c: I2C, address: int = 83)

Driver for the ADXL345 3 axis accelerometer

Parameters:
  • i2c (I2C) – The I2C bus the ADXL345 is connected to.

  • address (int) – The I2C device address for the sensor. Default is 0x53.

Quickstart: Importing and using the device

Here is an example of using the ADXL345 class. First you will need to import the libraries to use the sensor

import board
import adafruit_adxl34x

Once this is done you can define your board.I2C object and define your sensor object

i2c = board.I2C()  # uses board.SCL and board.SDA
accelerometer = adafruit_adxl34x.ADXL343(i2c)

Now you have access to the acceleration attribute

acceleration = accelerometer.acceleration
property acceleration: Tuple[int, int, int]

The x, y, z acceleration values returned in a 3-tuple in \(m / s ^ 2\)

property data_rate: int

The data rate of the sensor.

disable_freefall_detection() None

Disable freefall detection

disable_motion_detection() None

Disable motion detection

disable_tap_detection() None

Disable tap detection

enable_freefall_detection(*, threshold: int = 10, time: int = 25) None

Freefall detection parameters:

Parameters:
  • threshold (int) – The value that acceleration on all axes must be under to register as dropped. The scale factor is 62.5 mg/LSB.

  • time (int) – The amount of time that acceleration on all axes must be less than threshold to register as dropped. The scale factor is 5 ms/LSB. Values between 100 ms and 350 ms (20 to 70) are recommended.

If you wish to set them yourself rather than using the defaults, you must use keyword arguments:

accelerometer.enable_freefall_detection(time=30)
enable_motion_detection(*, threshold: int = 18)

The activity detection parameters.

Parameters:

threshold (int) – The value that acceleration on any axis must exceed to register as active. The scale factor is 62.5 mg/LSB.

If you wish to set them yourself rather than using the defaults, you must use keyword arguments:

accelerometer.enable_motion_detection(threshold=20)
enable_tap_detection(*, tap_count: int = 1, threshold: int = 20, duration: int = 50, latency: int = 20, window: int = 255)

The tap detection parameters.

Parameters:
  • tap_count (int) – 1 to detect only single taps, and 2 to detect only double taps.

  • threshold (int) – A threshold for the tap detection. The scale factor is 62.5 mg/LSB The higher the value the less sensitive the detection.

  • duration (int) – This caps the duration of the impulse above threshold. Anything above duration won’t register as a tap. The scale factor is 625 µs/LSB

  • latency (int) – (double tap only) The length of time after the initial impulse falls below threshold to start the window looking for a second impulse. The scale factor is 1.25 ms/LSB.

  • window (int) – (double tap only) The length of the window in which to look for a second tap. The scale factor is 1.25 ms/LSB

If you wish to set them yourself rather than using the defaults, you must use keyword arguments:

accelerometer.enable_tap_detection(duration=30, threshold=25)
property events: Dict[str, bool]

events will return a dictionary with a key for each event type that has been enabled. The possible keys are:

Key

Description

tap

True if a tap was detected recently. Whether it’s looking for a single or double tap is determined by the tap param of enable_tap_detection

motion

True if the sensor has seen acceleration above the threshold set with enable_motion_detection.

freefall

True if the sensor was in freefall. Parameters are set when enabled with enable_freefall_detection

property offset: Tuple[int, int, int]

The x, y, z offsets as a tuple of raw count values.

See offset_calibration example for usage.

property range: int

The measurement range of the sensor.

property raw_x: int

The raw x value.

property raw_y: int

The raw y value.

property raw_z: int

The raw z value.

class adafruit_adxl34x.DataRate

An enum-like class representing the possible data rates.

Possible values are:

  • DataRate.RATE_3200_HZ

  • DataRate.RATE_1600_HZ

  • DataRate.RATE_800_HZ

  • DataRate.RATE_400_HZ

  • DataRate.RATE_200_HZ

  • DataRate.RATE_100_HZ

  • DataRate.RATE_50_HZ

  • DataRate.RATE_25_HZ

  • DataRate.RATE_12_5_HZ

  • DataRate.RATE_6_25HZ

  • DataRate.RATE_3_13_HZ

  • DataRate.RATE_1_56_HZ

  • DataRate.RATE_0_78_HZ

  • DataRate.RATE_0_39_HZ

  • DataRate.RATE_0_20_HZ

  • DataRate.RATE_0_10_HZ

class adafruit_adxl34x.Range

An enum-like class representing the possible measurement ranges in +/- G.

Possible values are:

  • Range.RANGE_16_G

  • Range.RANGE_8_G

  • Range.RANGE_4_G

  • Range.RANGE_2_G