Simple test¶
Ensure your device works with this simple test.
import time
from machine import Pin, I2C
from micropython_bma220 import bma220
i2c = I2C(1, sda=Pin(2), scl=Pin(3)) # Correct I2C pins for RP2040
bma = bma220.BMA220(i2c)
while True:
accx, accy, accz = bma.acceleration
print(f"x:{accx:.2f}m/s², y:{accy:.2f}m/s², z:{accz:.2f}m/s²")
time.sleep(0.5)
Acc range settings¶
Example showing the Acc range setting
import time
from machine import Pin, I2C
from micropython_bma220 import bma220
i2c = I2C(1, sda=Pin(2), scl=Pin(3)) # Correct I2C pins for RP2040
bma = bma220.BMA220(i2c)
bma.acc_range = bma220.ACC_RANGE_16
while True:
for acc_range in bma220.acc_range_values:
print("Current Acc range setting: ", bma.acc_range)
for _ in range(10):
accx, accy, accz = bma.acceleration
print(f"x:{accx:.2f}m/s², y:{accy:.2f}m/s², z:{accz:.2f}m/s²")
time.sleep(0.5)
bma.acc_range = acc_range
Sleep duration settings¶
Example showing the Sleep duration setting
import time
from machine import Pin, I2C
from micropython_bma220 import bma220
i2c = I2C(1, sda=Pin(2), scl=Pin(3)) # Correct I2C pins for RP2040
bma = bma220.BMA220(i2c)
bma.sleep_duration = bma220.SLEEP_10MS
while True:
for sleep_duration in bma220.sleep_duration_values:
print("Current Sleep duration setting: ", bma.sleep_duration)
for _ in range(10):
accx, accy, accz = bma.acceleration
print(f"x:{accx:.2f}m/s², y:{accy:.2f}m/s², z:{accz:.2f}m/s²")
time.sleep(0.5)
bma.sleep_duration = sleep_duration
Filter bandwidth settings¶
Example showing the Filter bandwidth setting
import time
from machine import Pin, I2C
from micropython_bma220 import bma220
i2c = I2C(1, sda=Pin(2), scl=Pin(3)) # Correct I2C pins for RP2040
bma = bma220.BMA220(i2c)
bma.filter_bandwidth = bma220.ACCEL_500HZ
while True:
for filter_bandwidth in bma220.filter_bandwidth_values:
print("Current Filter bandwidth setting: ", bma.filter_bandwidth)
for _ in range(10):
accx, accy, accz = bma.acceleration
print(f"x:{accx:.2f}m/s², y:{accy:.2f}m/s², z:{accz:.2f}m/s²")
time.sleep(0.5)
bma.filter_bandwidth = filter_bandwidth
Latched mode settings¶
Example showing the Latched mode setting
import time
from machine import Pin, I2C
from micropython_bma220 import bma220
i2c = I2C(1, sda=Pin(2), scl=Pin(3)) # Correct I2C pins for RP2040
bma = bma220.BMA220(i2c)
bma.latched_mode = bma220.LATCH_FOR_2S
while True:
for latched_mode in bma220.latched_mode_values:
print("Current Latched mode setting: ", bma.latched_mode)
for _ in range(10):
accx, accy, accz = bma.acceleration
print(f"x:{accx:.2f}m/s², y:{accy:.2f}m/s², z:{accz:.2f}m/s²")
time.sleep(0.5)
bma.latched_mode = latched_mode
Slope Test¶
Example for the Slope mode
import time
from machine import Pin, I2C
from micropython_bma220 import bma220_slope
from micropython_bma220 import bma220_const as bma220
i2c = I2C(1, sda=Pin(2), scl=Pin(3)) # Correct I2C pins for RP2040
bma = bma220_slope.BMA220_SLOPE(i2c)
bma.latched_mode = bma220.LATCH_FOR_2S
bma.slope_x_enabled = bma220_slope.SLOPE_X_ENABLED
while True:
print("Slope Interrupt Triggered:", bma.slope_interrupt)
time.sleep(0.5)
Slope sign settings¶
Example showing the Slope sign setting
import time
from machine import Pin, I2C
from micropython_bma220 import bma220_slope
from micropython_bma220 import bma220_const as bma220
i2c = I2C(1, sda=Pin(2), scl=Pin(3)) # Correct I2C pins for RP2040
bma = bma220_slope.BMA220_SLOPE(i2c)
bma.latched_mode = bma220.LATCH_FOR_1S
bma.slope_x_enabled = bma220_slope.SLOPE_X_ENABLED
bma.slope_y_enabled = bma220_slope.SLOPE_Y_ENABLED
bma.slope_z_enabled = bma220_slope.SLOPE_Z_ENABLED
bma.slope_sign = bma220_slope.SLOPE_SIGN_NEGATIVE
bma.slope_threshold = 8
bma.slope_sign = bma220_slope.SLOPE_SIGN_NEGATIVE
while True:
for slope_sign in bma220_slope.slope_sign_values:
print("Current Slope sign setting: ", bma.slope_sign)
for _ in range(10):
print("Slope Interrupt Triggered:", bma.slope_interrupt)
infox, infoy, infoz = bma.slope_interrupt_info
print(f"Slope x:{infox}, y:{infoy}, z:{infoz}")
time.sleep(0.5)
bma.slope_sign = slope_sign
Double Tap Example¶
Example showing the Double Tap Mode
import time
from machine import Pin, I2C
from micropython_bma220 import bma220_tap_sensing
from micropython_bma220 import bma220_const as bma220
i2c = I2C(1, sda=Pin(2), scl=Pin(3)) # Correct I2C pins for RP2040
bma = bma220_tap_sensing.BMA220_TAP(i2c)
bma.latched_mode = bma220.LATCH_FOR_1S
bma.tt_x_enabled = bma220_tap_sensing.TT_X_ENABLED
bma.tt_y_enabled = bma220_tap_sensing.TT_Y_ENABLED
bma.tt_z_enabled = bma220_tap_sensing.TT_Z_ENABLED
bma.tt_duration = bma220_tap_sensing.TIME_500MS
while True:
print("Double Tap Interrupt Triggered:", bma.tt_interrupt)
time.sleep(0.5)
Orientation Mode Example¶
Example showing the Orientation Mode
import time
from machine import Pin, I2C
from micropython_bma220 import bma220_orientation
from micropython_bma220 import bma220_const as bma220
i2c = I2C(1, sda=Pin(2), scl=Pin(3)) # Correct I2C pins for RP2040
bma = bma220_orientation.BMA220_ORIENTATION(i2c)
bma.latched_mode = bma220.LATCH_FOR_1S
bma.orientation_blocking = bma220_orientation.MODE1
while True:
for orientation_blocking in (1, 2, 3):
print("Current Orientation blocking setting: ", bma.orientation_blocking)
for _ in range(50):
print("Orientation Interrupt Triggered:", bma.orientation_interrupt)
time.sleep(0.1)
bma.orientation_blocking = orientation_blocking
Low G Mode Example¶
Example showing the Log g Mode
import time
from machine import Pin, I2C
from micropython_bma220 import bma220_lowg_detection
from micropython_bma220 import bma220_const as bma220
i2c = I2C(1, sda=Pin(2), scl=Pin(3)) # Correct I2C pins for RP2040
bma = bma220_lowg_detection.BMA220_LOWG_DETECTION(i2c)
bma.latched_mode = bma220.LATCH_FOR_1S
while True:
print("Low G Interrupt Triggered:", bma.lowg_interrupt)
time.sleep(0.5)