12
12
13
13
14
14
import utime
15
- from machine import SoftI2C , Pin
15
+ from machine import SoftI2C , Pin , RTC
16
16
import math
17
17
from mpu9250 import MPU9250
18
18
# from mpu6500 import MPU6500, SF_G, SF_DEG_S
@@ -71,6 +71,8 @@ def Kalman_filter(angle, gyroRate, accelAngle):
71
71
toRad = 2.0 * math .pi / 360
72
72
toDeg = 1 / toRad
73
73
74
+ rtc = RTC ()
75
+
74
76
i2c = SoftI2C (scl = Pin (22 ), sda = Pin (21 ))
75
77
print (f"I2C configuration: { str (i2c )} " )
76
78
@@ -94,6 +96,8 @@ def Kalman_filter(angle, gyroRate, accelAngle):
94
96
print ("MPU9250 id: " + hex (sensor .whoami ))
95
97
print ("\n Press `Ctrl+C` to stop\n " )
96
98
99
+ print ("datetime,roll,pitch,yaw" )
100
+
97
101
try :
98
102
while True :
99
103
ax , ay , az = sensor .acceleration
@@ -127,9 +131,12 @@ def Kalman_filter(angle, gyroRate, accelAngle):
127
131
yaw -= 2 * math .pi
128
132
yaw = yaw * toDeg
129
133
134
+ (year , month , day , wday , hrs , mins , secs , subsecs ) = rtc .datetime ()
135
+ print (f"{ year } -{ month } -{ day } { hrs } :{ mins } :{ secs } .{ subsecs } ," , end = "" )
136
+
130
137
# print(f"{roll:.1f},{pitch:.1f},{yaw:.1f},{temp:.1f}")
131
138
print (f"{ roll :.1f} ,{ pitch :.1f} ,{ yaw :.1f} " )
132
- utime .sleep_ms (20 ) # 50 Hz
139
+ utime .sleep_ms (1 ) # 50 Hz
133
140
134
141
except KeyboardInterrupt :
135
142
# This part runs when Ctrl+C is pressed
0 commit comments