Simple test
Ensure your device works with this simple test.
examples/bma400_simpletest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 | # SPDX-FileCopyrightText: Copyright (c) 2023 Jose D. Montoya
#
# SPDX-License-Identifier: MIT
import time
import board
import bma400
i2c = board.I2C() # uses board.SCL and board.SDA
bma = bma400.BMA400(i2c)
while True:
accx, accy, accz = bma.acceleration
print("x:{:.2f}G y:{:.2f}G z:{:.2f}G".format(accx, accy, accz))
time.sleep(0.5)
|
Power mode settings
Example showing the Power mode setting
examples/bma400_power_mode.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 | # SPDX-FileCopyrightText: Copyright (c) 2023 Jose D. Montoya
#
# SPDX-License-Identifier: MIT
import time
import board
import bma400
i2c = board.I2C()
bma = bma400.BMA400(i2c)
bma.power_mode = bma400.LOW_POWER_MODE
while True:
for power_mode in bma400.power_mode_values:
print("Current Power mode setting: ", bma.power_mode)
for _ in range(10):
accx, accy, accz = bma.acceleration
print("x:{:.2f}Gs, y:{:.2f}Gs, z:{:.2f}Gs".format(accx, accy, accz))
time.sleep(0.5)
bma.power_mode = power_mode
|
Output data rate settings
Example showing the Output data rate setting
examples/bma400_output_data_rate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 | # SPDX-FileCopyrightText: Copyright (c) 2023 Jose D. Montoya
#
# SPDX-License-Identifier: MIT
import time
import board
import bma400
i2c = board.I2C()
bma = bma400.BMA400(i2c)
bma.output_data_rate = bma400.ACCEL_50HZ
while True:
for output_data_rate in bma400.output_data_rate_values:
print("Current Output data rate setting: ", bma.output_data_rate)
for _ in range(10):
accx, accy, accz = bma.acceleration
print("x:{:.2f}Gs, y:{:.2f}Gs, z:{:.2f}Gs".format(accx, accy, accz))
time.sleep(0.5)
bma.output_data_rate = output_data_rate
|
Oversampling rate settings
Example showing the Oversampling rate setting
examples/bma400_oversampling_rate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 | # SPDX-FileCopyrightText: Copyright (c) 2023 Jose D. Montoya
#
# SPDX-License-Identifier: MIT
import time
import board
import bma400
i2c = board.I2C()
bma = bma400.BMA400(i2c)
bma.oversampling_rate = bma400.OVERSAMPLING_2
while True:
for oversampling_rate in bma400.oversampling_rate_values:
print("Current Oversampling rate setting: ", bma.oversampling_rate)
for _ in range(10):
accx, accy, accz = bma.acceleration
print("x:{:.2f}Gs, y:{:.2f}Gs, z:{:.2f}Gs".format(accx, accy, accz))
time.sleep(0.5)
bma.oversampling_rate = oversampling_rate
|
Acc range settings
Example showing the Acc range setting
examples/bma400_acc_range.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 | # SPDX-FileCopyrightText: Copyright (c) 2023 Jose D. Montoya
#
# SPDX-License-Identifier: MIT
import time
import board
import bma400
i2c = board.I2C()
bma = bma400.BMA400(i2c)
bma.acc_range = bma400.ACC_RANGE_16
while True:
for acc_range in bma400.acc_range_values:
print("Current Acc range setting: ", bma.acc_range)
for _ in range(10):
accx, accy, accz = bma.acceleration
print("x:{:.2f}Gs, y:{:.2f}Gs, z:{:.2f}Gs".format(accx, accy, accz))
time.sleep(0.5)
bma.acc_range = acc_range
|
Source data registers settings
Example showing the Source data registers setting
examples/bma400_source_data_registers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 | # SPDX-FileCopyrightText: Copyright (c) 2023 Jose D. Montoya
#
# SPDX-License-Identifier: MIT
import time
import board
import bma400
i2c = board.I2C()
bma = bma400.BMA400(i2c)
bma.source_data_registers = bma400.ACC_FILT_LP
while True:
for source_data_registers in bma400.source_data_registers_values:
print("Current Source data registers setting: ", bma.source_data_registers)
for _ in range(10):
accx, accy, accz = bma.acceleration
print("x:{:.2f}Gs, y:{:.2f}Gs, z:{:.2f}Gs".format(accx, accy, accz))
time.sleep(0.5)
bma.source_data_registers = source_data_registers
|
Filter bandwidth settings
Example showing the Filter bandwidth setting
examples/bma400_filter_bandwidth.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 | # SPDX-FileCopyrightText: Copyright (c) 2023 Jose D. Montoya
#
# SPDX-License-Identifier: MIT
import time
import board
import bma400
i2c = board.I2C()
bma = bma400.BMA400(i2c)
bma.filter_bandwidth = bma400.ACC_FILT_BW0
while True:
for filter_bandwidth in bma400.filter_bandwidth_values:
print("Current Filter bandwidth setting: ", bma.filter_bandwidth)
for _ in range(10):
accx, accy, accz = bma.acceleration
print("x:{:.2f}Gs, y:{:.2f}Gs, z:{:.2f}Gs".format(accx, accy, accz))
time.sleep(0.5)
bma.filter_bandwidth = filter_bandwidth
|