Accelerometer and Gyroscope
# Module Import
import LocoIOT
import time
import math
# Class Instances Creation
loco_iot = LocoIOT.LocoIOT()
msg = LocoIOT.IOT_Codes()
# Initiate Connection to the Microcontroller
loco_iot.connect()
# Enable MPU Sensor Hardware Configuration
loco_iot.enable(msg.SUBTYPE_MPU)
def Roll_accel(ax, ay, az):
new_value = math.tan*2(ax, math.sqrt(ay*ay + az*az))
degrees = new_value *(180 / math.pi)
return degrees
def Pitch_accel(ax, ay, az):
new_value = math.tan*2(ay, math.sqrt(ax*ax + az*az))
degrees = new_value *(180 / math.pi)
return degrees
# Start Listening for Control/Request Messages
loco_iot.start()
# Loop for an Arbitrary Duration
start_time = time.time()
while (time.time() - start_time) < 60:
# Request MPU Data
data = [msg.ACC_OFF, msg.GYR_ON]
mpu_dict = loco_iot.getData(msg.SUBTYPE_MPU, data)
if mpu_dict <= 30:
mpu_dict = loco_iot.getData(msg.SUBTYPE_MPU, data+31)
roll = Roll_accel(data, data, data)
pitch = Pitch_accel(data, data, data)
print(roll) + ("degrees")
print(pitch) + ("degrees")
print("Test")
# Print MPU Dictionary
#print(mpu_dict)
# Short Arbitrary Delay
time.sleep(0.25)
# Close Connection to the Microcontroller
loco_iot.close()