Skip to content

Commit 567b149

Browse files
Create Acceleration_Explorations.py
mightve made a few "woke up at 1am" mistakes
1 parent 6e978e0 commit 567b149

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from mpu6050 import MPU6050
2+
import time
3+
4+
mpu=MPU6050(14,13) #attach the IIC pin(sclpin,sdapin)
5+
mpu.MPU_Init() #initialize the MPU6050
6+
G = 9.8
7+
time.sleep_ms(1000)#waiting for MPU6050 to work steadily
8+
9+
try:
10+
while True:
11+
accel=mpu.MPU_Get_Accelerometer()#gain the values of Acceleration
12+
gyro=mpu.MPU_Get_Gyroscope() #gain the values of Gyroscope
13+
print("\na/g:\t")
14+
print(accel[0],"\t",accel[1],"\t",accel[2],"\t",
15+
gyro[0],"\t",gyro[1],"\t",gyro[2])
16+
print("a/g:\t")
17+
print(accel[0]/16384,"g",accel[1]/16384,"g",accel[2]/16384,"g",
18+
gyro[0]/131,"d/s",gyro[1]/131,"d/s",gyro[2]/131,"d/s")
19+
20+
tilt_angle = accel[1] + accel[2] # Combines X and Y values for tilt angle
21+
if accel[2] <= 15650: # Checks if the board is tilted based off of the current accel Z axis
22+
print("Tilted: Yes\t", end="")
23+
print("Angle: " + str(tilt_angle))
24+
else:
25+
print("Tilted: No")
26+
time.sleep_ms(1000)
27+
except:
28+
pass

0 commit comments

Comments
 (0)