KX132

kx132

CircuitPython Driver for the Kionix KX132 Accelerometer

  • Author(s): Jose D. Montoya

class kx132.KX132(i2c_bus: busio.I2C, address: int = 0x1F)[source]

Driver for the KX132 Sensor connected over I2C.

Parameters:
i2c_bus : I2C

The I2C bus the KX132 is connected to.

address : int

The I2C device address. Defaults to 0x1F

Raises:

RuntimeError – if the sensor is not found

Quickstart: Importing and using the device

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

import board
import kx132

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
kx = kx132.KX132(i2c)

Now you have access to the attributes

accx, accy, accz = kx.acceleration
property acc_range : str

Acceleration range of the accelerometer outputs per Table. This range is also called a full-scale range of the accelerometer.

Mode

Value

kx132.ACC_RANGE_2

0b00

kx132.ACC_RANGE_4

0b01

kx132.ACC_RANGE_8

0b10

kx132.ACC_RANGE_16

0b11

property acceleration : tuple[float, float, float]

Acceleration When accelerometer is enabled the 16-bits of valid acceleration data for each axis is routed to acceleration. The data is updated every user-defined ODR period at the rate set by OSA<3:0> bits in ODCNTL register. :return: acceleration

property adp_enabled : str

Sensor adp_enabled

Mode

Value

kx132.ADP_DISABLED

0b0

kx132.ADP_ENABLED

0b1

property advanced_data_path : tuple[float, float, float]

This will nor return any information unless the adp_enabled is set. Data is updated at the rate set by OADP<3:0> bits in ADP_CNTL1 register. However, if data is routed via RMS block first (ADP_RMS_OSEL bit is set to 1 in ADP_CNTL2 register), the rate is also scaled down by RMS_AVC<2:0> bits in ADP_CNTL1 register. Values will remain the same until sensor is reset

property free_fall_enabled : str

Sensor free_fall_enabled

Mode

Value

kx132.FF_DISABLED

0b0

kx132.FF_ENABLED

0b1

property free_fall_threshold : int

Free Fall Threshold. This value is compared to the top 8 bits of the accelerometer 8g output (independent of the actual g-range setting of the device).

interrupt_release()[source]

Clear the interrupt register

property output_data_rate : int

There are 16 different configuration for the Output Data Rate. These rate are divided in two groups. 1. Low Power and High Performance Output Data Rates <= 400 Hz 2. High Performance Output Data Rates only >= 800 Hz

Please verify the data sheet for corresponding values The default ODR is 50Hz (0b110|6).

property performance_mode : str

Sensor performance_mode

Mode

Value

kx132.LOW_POWER_MODE

0b0

kx132.HIGH_PERFORMANCE_MODE

0b1

property previous_tilt_position

Previous Sensor tilt position. Data that is updated at the user-defined ODR frequency determined by OTP<1:0> in CNTL3. Data is protected during register read

soft_reset()[source]

The Software Reset bit initiates software reset, which performs the RAM reboot routine. This bit will remain 1 until the RAM reboot routine is finished.

property tap_doubletap_enable : str

Sensor tap_doubletap_enable

Mode

Value

kx132.TDTE_DISABLED

0b0

kx132.TDTE_ENABLED

0b1

property tap_doubletap_report

Tap/Double Tap report. Data is updated at the ODR settings determined by OTDT<2:0> in CNTL3. These bits are cleared when interrupt_release function is called.

property tilt_position

Current Sensor tilt position. Data that is updated at the user-defined ODR frequency determined by OTP<1:0> in CNTL3. Data is protected during register read

property tilt_position_enable : str

Sensor tilt_position_enable

Mode

Value

kx132.TILT_DISABLED

0b0

kx132.TILT_ENABLED

0b1