MicroPython ADXL343 Driver

adxl343

MicroPython Driver for the Analog Devices ADXL343 Accelerometer

  • Author(s): Jose D. Montoya

class micropython_adxl343.adxl343.ADXL343(i2c, address: int = 0x53)[source]

Driver for the ADXL343 Sensor connected over I2C.

Parameters:
i2c : I2C

The I2C bus the ADXL343 is connected to.

address : int

The I2C device address. Defaults to 0x53

Raises:

RuntimeError – if the sensor is not found

Quickstart: Importing and using the device

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

from machine import Pin, I2C
from micropython_adxl343 import adxl343

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

i2c = I2C(1, sda=Pin(2), scl=Pin(3))
adxl = adxl343.ADXL343(i2c)

Now you have access to the attributes

accx, accy, accz = adx.acceleration
property acceleration : tuple[float, float, float]

Acceleration Data in \(m / s ^ 2\)

property acceleration_range : str

Sensor acceleration_range

Mode

Value

adxl343.RANGE_2

0b00

adxl343.RANGE_4

0b01

adxl343.RANGE_8

0b10

adxl343.RANGE_16

0b11

property activity_detected : bool

Returns if an activity was detected :return: bool

property activity_mode : str

Sensor activity_mode

Mode

Value

adxl343.ACTIVITY_DISABLED

0b0

adxl343.ACTIVITY_ENABLED

0b1

property activity_threshold : float

Activity threshold in \(m / s ^ 2\) :return:

property double_tap_activated : bool

Returns if a double tap event was detected :return: bool

property double_tap_mode : str

Sensor double_tap_mode Every mechanical system has somewhat different single tap/double tap responses based on the mechanical characteristics of the system. Therefore, some experimentation is required. In general, a good starting point is to set the tap_duration to a value greater 10 ms, the tap_latent to a value greater than 20 ms, the tap_window to a value greater than 80 ms, and the tap_threshold to a value greater than 3 g. Setting a very low values may result in an unpredictable response due to the accelerometer picking up echoes of the tap inputs.

Mode

Value

adxl343.DT_DISABLED

0b0

adxl343.DT_ENABLED

0b1

property measurement_mode : str

Sensor measurement_mode. Selecting 0 or False places the part into standby mode, and a setting of 1 or True places the part into measurement mode. The ADXL343 powers up in standby mode with minimum power consumption.

Mode

Value

adxl343.STANDBY

0b0

adxl343.READY

0b1

property resolution_mode : str

Sensor resolution_mode. When resolution_mode is set to True, the device is in full resolution mode, where the output resolution increases with the g range set by the range bits to maintain a 4 mg/LSB scale factor. When is set to False, the device is in 10-bit mode, and the range bits determine the maximum g acceleration_range and scale factor.

Mode

Value

adxl343.LOW_RES

0b0

adxl343.HIGH_RES

0b1

property single_tap_activated : bool

Returns if a single tap event was detected :return: bool

property single_tap_mode : str

Sensor single_tap_mode

Mode

Value

adxl343.ST_DISABLED

0b0

adxl343.ST_ENABLED

0b1

property tap_duration : float

Tap threshold in us. Maximum time that an event must be above the tap_threshold to qualify as a tap event. The scale factor is 625 μs/LSB. A value of 0 disables the single tap/ double tap functions

property tap_latent : float

Wait time from the detection of a tap event to the start of the time window during which a possible second tap event can be detected. The scale factor is 1.25 ms/LSB. A value of 0 disables the double tap function.

property tap_threshold : float

Tap threshold in \(m / s ^ 2\) :return:

property tap_window : float

Time after the expiration of the latency time during which a second valid tap can begin. The scale factor is 1.25 ms/LSB. A value of 0 disables the double tap function