#picaxe 28X2
#no_table
#no_data
' BNO055 Test - V3
' -----------------
symbol BNO_YAW = w5 ' b10, b11
symbol BNO_ROLL = w6 ' b12, b13
symbol BNO_PITCH = w7 ' b14, b15
symbol CalState = b4
symbol P_sgn = b8
symbol R_sgn = b9
' Code starts here
sertxd(cr,lf,ppp_filename," Starting ...",cr,lf)
pause 1000
' Setup I2C
hi2cSetup i2cmaster, $50, i2cslow, i2cbyte
' Set BNO active
hi2cOut $3D, ($0C)
do
' Read chip ID
hi2cin $00,(b0)
' Quit if chip ID wrong
if b0 <> $A0 then : sertxd( "Bad comms !",cr,lf): reset : endif
' Read calibration state
hi2cin $35,(CalState)
' Read Euler angles
hi2cin $1A,(b10,b11) ' Yaw, 0 to +360
hi2cin $1C,(b12,b13) ' Roll, -90 to +90
hi2cin $1E,(b14,b15) ' Pitch, -180 to +180
' Scale Yaw to 360'
BNO_YAW = BNO_YAW / 16
' Convert pitch to +/- value
if BNO_PITCH > $8000 then
P_sgn = "-"
BNO_PITCH = 0 - BNO_PITCH
else
P_sgn = "+"
endif
' Scale Pitch to 180'
BNO_PITCH = BNO_PITCH / 16 ' ?? might need changing
' Convert roll to +/- value
if BNO_ROLL > $8000 then
R_sgn = "-"
BNO_ROLL = 0 - BNO_ROLL
else
R_sgn = "+"
endif
' Scale Roll to 90'
BNO_ROLL = BNO_ROLL / 16 ' ?? might need changing
' Show results
sertxd("Y=",#BNO_YAW,9,9,"P=",P_sgn,#BNO_PITCH,9,9,"R=",R_sgn,#BNO_ROLL,9,9)
' Show calibration state
if CalState = 255 then : sertxd( "Cal OK") : else : sertxd( "Cal poor") : endif
' New line
sertxd(cr,lf)
pause 200
loop
[\code]