-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.py
44 lines (33 loc) · 1.26 KB
/
example.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
import json
from nicla_sense_me_i2c import NiclaSenseMe
import board
import busio
i2c = busio.I2C(board.SCL, board.SDA)
sensor = NiclaSenseMe(i2c)
# Calib obtained with sensor.get_calib() after calibration.
with open("calib.json") as calib_file:
calib = json.load(calib_file)
# Warm start with sensor already calibrated.
sensor.send_calib(**calib)
sensor.start()
while True:
# In degrees. [0, 360], [-180, 180], [-90, 90]
heading, pitch, roll = sensor.orientation()
print(f"{heading=:.2f}°\n{pitch=:.2f}°\n{roll=:.2f}°")
# In earth g.
acc_x, acc_y, acc_z = sensor.acceleration()
print(f"{acc_x=:.2f}g\n{acc_y=:.2f}g\n{acc_z=:.2f}g")
# In earth g.
lin_acc_x, lin_acc_y, lin_acc_z = sensor.linear_acceleration()
print(f"{lin_acc_x=:.2f}g\n{lin_acc_y=:.2f}g\n{lin_acc_z=:.2f}g")
# In degrees/second.
gyr_x, gyr_y, gyr_z = sensor.gyroscope()
print(f"{gyr_x=:.2f}deg/s\n{gyr_y=:.2f}deg/s\n{gyr_z=:.2f}deg/s")
# In µT.
mag_x, mag_y, mag_z = sensor.magnetometer()
print(f"{mag_x=:.2f}µT\n{mag_y=:.2f}µT\n{mag_z=:.2f}µT")
qx, qy, qz, qw = sensor.quaternion()
print(f"rotation=({qx:.4f}, {qy:.4f}, {qz:.4f}, {qw:.4f})")
# In degrees celsius.
temp = sensor.temperature()
print(f"{temp=:.2f}°C\n")