Simple test¶
Ensure your device works with this simple test.
import time
from machine import Pin, I2C
from micropython_kx132 import kx132
i2c = I2C(1, sda=Pin(2), scl=Pin(3))
kx = kx132.KX132(i2c)
while True:
accx, accy, accz = kx.acceleration
print(f"x:{accx:.2f}g, y:{accy:.2f}g, z:{accz:.2f}g")
print()
time.sleep(0.1)
Acc range settings¶
Example showing the Acc range setting
import time
from machine import Pin, I2C
from micropython_kx132 import kx132
i2c = I2C(1, sda=Pin(2), scl=Pin(3))
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(f"x:{accx:.2f}g, y:{accy:.2f}g, z:{accz:.2f}g")
print()
time.sleep(0.5)
kx.acc_range = acc_range
Tilt example¶
Example showing the Tilt setting
import time
from machine import Pin, I2C
from micropython_kx132 import kx132
i2c = I2C(1, sda=Pin(2), scl=Pin(3))
kx = kx132.KX132(i2c)
kx.tilt_position_enable = kx132.TILT_ENABLED
while True:
print(f"Current position {kx.tilt_position}")
print()
time.sleep(0.3)
Previous Tilt position example¶
Example showing the Previous Tilt setting
import time
from machine import Pin, I2C
from micropython_kx132 import kx132
i2c = I2C(1, sda=Pin(2), scl=Pin(3))
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}")
print()
time.sleep(0.3)
Tap Double Tap example¶
Tap Double Tap example
import time
from machine import Pin, I2C
from micropython_kx132 import kx132
i2c = I2C(1, sda=Pin(2), scl=Pin(3))
kx = kx132.KX132(i2c)
kx.tap_doubletap_enable = kx132.TDTE_ENABLED
while True:
print(f"Status: {kx.tap_doubletap_report}")
print()
kx.interrupt_release()
time.sleep(0.3)
Output Data rate setting¶
Example showing the Output Data Rate setting
import time
from machine import Pin, I2C
from micropython_kx132 import kx132
i2c = I2C(1, sda=Pin(2), scl=Pin(3))
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(f"x:{accx:.2f}g, y:{accy:.2f}g, z:{accz:.2f}g")
print()
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(f"x:{accx:.2f}g, y:{accy:.2f}g, z:{accz:.2f}g")
print()
time.sleep(0.5)
Adp enabled settings¶
Example showing the Adp enabled setting
import time
from machine import Pin, I2C
from micropython_kx132 import kx132
i2c = I2C(1, sda=Pin(2), scl=Pin(3))
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(f"x:{adpx:.2f}g, y:{adpy:.2f}g, z:{adpz:.2f}g")
print()
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(f"x:{adpx:.2f}g, y:{adpy:.2f}g, z:{adpz:.2f}g")
print()
time.sleep(0.5)
kx.soft_reset()