Newer
Older
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
import mpu6050
import time
# Create a new Mpu6050 object
mpu6050 = mpu6050.mpu6050(0x68)
# Define a function to read the sensor data
def read_sensor_data():
# Read the accelerometer values
accelerometer_data = mpu6050.get_accel_data()
# Read the gyroscope values
gyroscope_data = mpu6050.get_gyro_data()
# Read temp
temperature = mpu6050.get_temp()
return accelerometer_data, gyroscope_data, temperature
# Start a while loop to continuously read the sensor data
while True:
# Read the sensor data
accelerometer_data, gyroscope_data, temperature = read_sensor_data()
Ax = accelerometer_data['x']
Ay = accelerometer_data['y']
Az = accelerometer_data['z']
Gx = gyroscope_data['x']
Gy = gyroscope_data['y']
Gz = gyroscope_data['z']
# Print the results
print(f"Accelerometer (g): X={Ax:.8f}, Y={Ay:.8f}, Z={Az:.8f}")
print(f"Gyroscope (°/s): X={Gx:.8f}, Y={Gy:.8f}, Z={Gz:.8f}")
print("-" * 50)
# Print the sensor data
# print("Accelerometer data:", accelerometer_data)
# print("Gyroscope data:", gyroscope_data)
# print("--------------------")
#print("Temp:", temperature)
# Wait for 1 second
time.sleep(0.1)