-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbmi323_spi_read_write.py
68 lines (52 loc) · 2.47 KB
/
bmi323_spi_read_write.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import logging
import sys
import time
from pathlib import Path
from umrx_app_v3.shuttle_board.bmi323.bmi323_shuttle import BMI323Shuttle
def setup_logging(level: int = logging.DEBUG) -> logging.Logger:
logger = logging.getLogger()
logger.setLevel(level)
stdout_handler = logging.StreamHandler(sys.stdout)
log_format = "(%(asctime)s) [%(levelname)-8s] %(filename)s:%(lineno)d: %(message)s"
log_formatter = logging.Formatter(log_format)
stdout_handler.setFormatter(log_formatter)
file_handler = logging.FileHandler(f"{Path(__file__).parent / Path(__file__).stem}.log", mode="w")
file_handler.setFormatter(log_formatter)
logger.addHandler(stdout_handler)
logger.addHandler(file_handler)
return logger
if __name__ == "__main__":
logger = setup_logging()
# For using with Application board 3.0, replace the line below with:
# shuttle = BMI088Shuttle.on_hardware_v3_rev0()
shuttle = BMI323Shuttle.on_hardware_v3_rev1()
shuttle.initialize()
shuttle.check_connected_hw()
shuttle.configure_spi()
_ = shuttle.board.read_spi(shuttle.CS, 0, 1) # dummy read is required, do not delete
res = shuttle.board.read_spi(shuttle.CS, 0, 3)
logger.info(f"{res=}")
res = shuttle.board.read_spi(shuttle.CS, 0, 3)
logger.info(f"{res=}")
logger.info(f"chip_id=0x{shuttle.sensor.chip_id:04X}")
logger.info(f"err_reg=0x{shuttle.sensor.err_reg:04X}")
logger.info(f"err_reg=0x{shuttle.sensor.status:04X}")
a_x, a_y, a_z = shuttle.sensor.acc_data
logger.info(f"acceleration=({a_x=:04X}, {a_y=:04X}, {a_z=:04X})")
g_x, g_y, g_z = shuttle.sensor.gyr_data
logger.info(f"angular_velocity=({g_x=:04X}, {g_y=:04X}, {g_z=:04X})")
logger.info(f"sensor_time={shuttle.sensor.sensor_time:04X}")
logger.info(f"acc_conf=0x{shuttle.sensor.acc_conf:04X}")
logger.info(f"gyr_conf=0x{shuttle.sensor.gyr_conf:04X}")
# start accelerometer and gyro measurements
shuttle.sensor.acc_conf = 0x4027
shuttle.sensor.gyr_conf = 0x404B
logger.info(f"acc_conf=0x{shuttle.sensor.acc_conf:04X}")
logger.info(f"gyr_conf=0x{shuttle.sensor.gyr_conf:04X}")
logger.info(f"alt_acc_conf=0x{shuttle.sensor.alt_acc_conf:04X}")
logger.info(f"alt_gyr_conf=0x{shuttle.sensor.alt_gyr_conf:04X}")
time.sleep(0.1)
a_x, a_y, a_z = shuttle.sensor.acc_data
logger.info(f"acceleration=({a_x=}, {a_y=}, {a_z=})")
g_x, g_y, g_z = shuttle.sensor.gyr_data
logger.info(f"angular_velocity=({g_x=}, {g_y=}, {g_z=})")