getting the HM55B compass module to work
Hi,
I have use a·BS to get data from other BS2s and use that BS2 to send·all the infomation·to my computer. relay1, relay2 and LED are the data i get from the other BS2s. However, I want to do a compass module in the BS itself so that I can send readings from the compass to my computer. However, without inserting the compass code, my vb program are able to display information from relay1, relay2 and LED. When I inserted the compass code, all readings are empty. I have try without using my vb program and uses the·debug command to check. It's the same too. How can I make my compass and the other readings work too ?
The code with the compass code
The code without the compass code
I have use a·BS to get data from other BS2s and use that BS2 to send·all the infomation·to my computer. relay1, relay2 and LED are the data i get from the other BS2s. However, I want to do a compass module in the BS itself so that I can send readings from the compass to my computer. However, without inserting the compass code, my vb program are able to display information from relay1, relay2 and LED. When I inserted the compass code, all readings are empty. I have try without using my vb program and uses the·debug command to check. It's the same too. How can I make my compass and the other readings work too ?
The code with the compass code
' {$STAMP BS2}
' {$PBASIC 2.5}
relay1 PIN 0
relay2 PIN 1
LED PIN 2
DinDout PIN 6 ' P6 transceives to/from Din/Dout
Clk PIN 5 ' P5 sends pulses to HM55B's Clk
En PIN 4 ' P4 controls HM55B's /EN(ABLE)
Reset CON %0000 ' Reset command for HM55B
Measure CON %1000 ' Start measurement command
Report CON %1100 ' Get status/axis values command
Ready CON %1100 ' 11 -> Done, 00 -> no errors
NegMask CON %1111100000000000 ' For 11-bit negative to 16-bits
x VAR Word ' x-axis data
y VAR Word ' y-axis data
status VAR Nib ' Status flags
angle VAR Word ' Store angle measurement
reading1 VAR Word
reading2 VAR Word
reading3 VAR Word
DO
IF relay1 = 1 THEN
reading1 = 1
ELSE
reading1 = 0
ENDIF
IF relay2 = 1 THEN
reading2 = 1
ELSE
reading2 = 0
ENDIF
IF LED = 1 THEN
IF LED = 1 THEN ' Motion Detected
reading3 = reading3 + 1 ' Update Trip Counter
DO : LOOP UNTIL LED = 0 ' Wait For PIR To Clear
ENDIF
ENDIF
'DEBUG HOME, "relay1"," = ", DEC1 reading1
'DEBUG CR, "relay2", " = ", DEC1 reading2
PAUSE 100
SEROUT 16,16468,[noparse][[/noparse]DEC1 reading1,DEC1 reading2,DEC1 reading3,DEC3 angle]
SEROUT 16,16468,[noparse][[/noparse]LF]
'DEBUG HOME, DEC1 reading1
'DEBUG CR, DEC1 reading2
'DEBUG CR, DEC1 reading3
'DEBUG CR, DEC angle
GOSUB Compass_Get_Axes ' Get x, and y values
angle = x ATN -y ' Convert x and y to brads
angle = angle */ 360 ' Convert brads to degrees
'SEROUT 16,16468,[noparse][[/noparse]DEC3 angle]
'SEROUT 16,16468,[noparse][[/noparse]LF]
'DEBUG HOME, "x-axis N(-S) = ",SDEC x, ' Display axes and degrees
'CLREOL, CR, "y-axis W(-E) = ",
'SDEC y, CLREOL, CR, CR, "angle = ",
'DEC angle, " degrees", CLREOL
PAUSE 150 ' Debug delay for slower PCs
LOOP
' -----[noparse][[/noparse] Subroutines ]--------------------------------------------------------
Compass_Get_Axes: ' Compass module subroutine
HIGH En: LOW En ' Send reset command to HM55B
SHIFTOUT DinDout,clk,MSBFIRST,[noparse][[/noparse]Reset\4]
HIGH En: LOW En ' HM55B start measurement command
SHIFTOUT DinDout,clk,MSBFIRST,[noparse][[/noparse]Measure\4]
status = 0 ' Clear previous status flags
DO ' Status flag checking loop
HIGH En: LOW En ' Measurement status command
SHIFTOUT DinDout,clk,MSBFIRST,[noparse][[/noparse]Report\4]
SHIFTIN DinDout,clk,MSBPOST,[noparse][[/noparse]Status\4] ' Get Status
LOOP UNTIL status = Ready ' Exit loop when status is ready
SHIFTIN DinDout,clk,MSBPOST,[noparse][[/noparse]x\11,y\11] ' Get x & y axis values
HIGH En ' Disable module
IF (y.BIT10 = 1) THEN y = y | NegMask ' Store 11-bits as signed word
IF (x.BIT10 = 1) THEN x = x | NegMask ' Repeat for other axis
RETURN
END
The code without the compass code
' {$STAMP BS2}
' {$PBASIC 2.5}
relay1 PIN 0
relay2 PIN 1
LED PIN 2
reading1 VAR Word
reading2 VAR Word
reading3 VAR Word
DO
IF relay1 = 1 THEN
reading1 = 1
ELSE
reading1 = 0
ENDIF
IF relay2 = 1 THEN
reading2 = 1
ELSE
reading2 = 0
ENDIF
IF LED = 1 THEN
IF LED = 1 THEN ' Motion Detected
reading3 = reading3 + 1 ' Update Trip Counter
DO : LOOP UNTIL LED = 0 ' Wait For PIR To Clear
ENDIF
ENDIF
PAUSE 100
SEROUT 16,16468,[noparse][[/noparse]DEC1 reading1,DEC1 reading2,DEC1 reading3]
SEROUT 16,16468,[noparse][[/noparse]LF]
'DEBUG HOME, DEC1 reading1
'DEBUG CR, DEC1 reading2
'DEBUG CR, DEC1 reading3
LOOP
END

Comments
Remember that your SEROUT statements in your program come before the GOSUB and the angle calculations, so the first angle sent to the PC will be garbage (probably zero).