' MPU 6050 board - Inertial Measurements
' connect SCL to A5, SDA to A4, 3.3V and ground
#Region Project Attributes
#AutoFlushLogs: True
#StackBufferSize: 300
#End Region
Sub Process_Globals
Public Serial1 As Serial
Private wire As WireMaster
Private raf As RandomAccessFile
Private const MPU As Int = 0x68
Private AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ As Int
Private tmr As Timer
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
wire.Initialize
wire.WriteTo(MPU, Array As Byte(0x6b, 0))
tmr.Initialize("tmr_tick",700)
tmr.Enabled = True
End Sub
Sub tmr_tick
wire.WriteTo(MPU, Array As Byte(0x3b))
Dim b() As Byte = wire.RequestFrom(MPU, 14)
If b.Length = 14 Then
raf.Initialize(b,False)
AcX = raf.ReadInt16(raf.CurrentPosition)
AcY = raf.ReadInt16(raf.CurrentPosition)
AcZ = raf.ReadInt16(raf.CurrentPosition)
Dim temp As Double
Tmp = raf.ReadInt16(raf.CurrentPosition)
temp = Tmp /340.00+36.53
GyX = raf.ReadInt16(raf.CurrentPosition)
GyY = raf.ReadInt16(raf.CurrentPosition)
GyZ = raf.ReadInt16(raf.CurrentPosition)
Log("acx: ", AcX , ", acy: ", AcY ," ,acz: ", AcZ,", Tmp: ",NumberFormat(temp,1,1) , ", GyX: ", GyX , ", GyY: ", GyY ," ,GyZz: ", GyZ)
Else
Log("Missing data...")
End If
End Sub