Simple test

Ensure your device works with this simple test.

examples/kx132_simpletest.py
import time
import board
import kx132

i2c = board.I2C()  # uses board.SCL and board.SDA
kx = kx132.KX132(i2c)

while True:
    accx, accy, accz = kx.acceleration
    print("x:{:.2f}g, y:{:.2f}g, z:{:.2f}g".format(accx, accy, accz))
    time.sleep(0.1)

Acc range settings

Example showing the Acc range setting

examples/kx132_acc_range.py
import time
import board
import kx132

i2c = board.I2C()  # uses board.SCL and board.SDA
kx = kx132.KX132(i2c)

kx.acc_range = kx132.ACC_RANGE_16

while True:
    for acc_range in kx132.acc_range_values:
        print("Current Acc range setting: ", kx.acc_range)
        for _ in range(10):
            accx, accy, accz = kx.acceleration
            print("x:{:.2f}m/s2, y:{:.2f}m/s2, z:{:.2f}m/s2".format(accx, accy, accz))
            time.sleep(0.5)
        kx.acc_range = acc_range

Tilt example

Example showing the Tilt setting

examples/kx132_tilt_example.py
import time
import board
import kx132

i2c = board.I2C()  # uses board.SCL and board.SDA
kx = kx132.KX132(i2c)

kx.tilt_position_enable = kx132.TILT_ENABLED

while True:
    print(f"Current position {kx.tilt_position}")
    time.sleep(0.3)

Previous Tilt position example

Example showing the Previous Tilt setting

examples/kx132_previous_tilt_position_example.py
import time
import board
import kx132

i2c = board.I2C()  # uses board.SCL and board.SDA
kx = kx132.KX132(i2c)

kx.tilt_position_enable = kx132.TILT_ENABLED

while True:
    print(f"Previous position {kx.previous_tilt_position}")
    print(f"Current position {kx.tilt_position}")
    time.sleep(0.3)

Tap Double Tap example

Tap Double Tap example

examples/kx132_tap_doubletap_example.py
import time
import board
import kx132

i2c = board.I2C()  # uses board.SCL and board.SDA
kx = kx132.KX132(i2c)

kx.tap_doubletap_enable = kx132.TDTE_ENABLED

while True:
    print(f"Status: {kx.tap_doubletap_report}")
    kx.interrupt_release()
    time.sleep(0.3)

Output Data rate setting

Example showing the Output Data Rate setting

examples/kx132_output_data_rate.py
import time
import board
import kx132

i2c = board.I2C()  # uses board.SCL and board.SDA
kx = kx132.KX132(i2c)

while True:
    kx.performance_mode = kx132.HIGH_PERFORMANCE_MODE
    kx.output_data_rate = 12  # 3200 Hz
    print("Current Performance Mode setting: ", kx.performance_mode)
    for _ in range(10):
        accx, accy, accz = kx.acceleration
        print("x:{:.2f}m/s2, y:{:.2f}m/s2, z:{:.2f}m/s2".format(accx, accy, accz))
        time.sleep(0.5)
    kx.performance_mode = kx132.LOW_POWER_MODE
    kx.output_data_rate = 3  # 6.25 Hz
    print("Current Performance Mode setting: ", kx.performance_mode)
    for _ in range(10):
        accx, accy, accz = kx.acceleration
        print("x:{:.2f}m/s2, y:{:.2f}m/s2, z:{:.2f}m/s2".format(accx, accy, accz))
        time.sleep(0.5)

Adp enabled settings

Example showing the Adp enabled setting

examples/kx132_adp_enabled.py
import time
import board
import kx132

i2c = board.I2C()  # uses board.SCL and board.SDA
kx = kx132.KX132(i2c)

while True:
    kx.adp_enabled = kx132.ADP_DISABLED
    print("Current ADP setting: ", kx.adp_enabled)
    for _ in range(10):
        adpx, adpy, adpz = kx.advanced_data_path
        print("x:{:.2f}g, y:{:.2f}g, z:{:.2f}g".format(adpx, adpy, adpz))
        time.sleep(0.5)
    kx.adp_enabled = kx132.ADP_ENABLED
    print("Current ADP setting: ", kx.adp_enabled)
    for _ in range(10):
        adpx, adpy, adpz = kx.advanced_data_path
        print("x:{:.2f}g, y:{:.2f}g, z:{:.2f}g".format(adpx, adpy, adpz))
        time.sleep(0.5)
    kx.soft_reset()