DShannon
03-09-2005, 11:17 AM
Just hooked up the Vector2x to my BS2. Code is below (circuit and code is same as http://www.robotics.com/arobot/vector.html)
Seems as though my headings are off by about 90 degrees.
The only thing I can think off is that I have YFlip grounded along with RES (as per the schemtatic at the above link (and attached).
Any ideas????
' {$STAMP BS2}
' {$PBASIC 2.5}
'------------------------------------------------
'compass signals.
slct CON 2 'select signal.
sdo CON 3 'serial data out.
sclk CON 4 'clock signal.
rst CON 5 'reset signal.
'Other.
heading VAR Word 'heading variable.
setup:
OUTPUT slct 'set pin direction.
OUTPUT sclk
OUTPUT rst
INPUT sdo
GOSUB compinit 'initialize the compass.
main:
GOSUB getcomp 'get the compass heading.
DEBUG DEC ? heading 'Display heading.
DEBUG CR
PAUSE 1000 'wait a sec.
GOTO main 'loop for ever.
'------------------------------------------------
'this routine initializes the Vector 2x compass.
'
compinit:
HIGH sclk
HIGH slct 'make sure this is high.
LOW rst 'lower reset pin.
PAUSE 15 'wait 15 ms.
HIGH rst 'raise reset pin.
PAUSE 200 'wait a bit.
RETURN 'done.
'------------------------------------------------
'This routine gets the heading from the Vector 2x
'compass and places it in the variable heading.
'
getcomp:
LOW slct 'start the Vector 2x.
PAUSE 200 'wait for heading.
heading = 0 'clear variable.
SHIFTIN sdo,sclk,MSBPRE,[heading\16]
'get the data from Vector 2x.
HIGH sclk 'reset pins.
HIGH slct
RETURN 'done.
Seems as though my headings are off by about 90 degrees.
The only thing I can think off is that I have YFlip grounded along with RES (as per the schemtatic at the above link (and attached).
Any ideas????
' {$STAMP BS2}
' {$PBASIC 2.5}
'------------------------------------------------
'compass signals.
slct CON 2 'select signal.
sdo CON 3 'serial data out.
sclk CON 4 'clock signal.
rst CON 5 'reset signal.
'Other.
heading VAR Word 'heading variable.
setup:
OUTPUT slct 'set pin direction.
OUTPUT sclk
OUTPUT rst
INPUT sdo
GOSUB compinit 'initialize the compass.
main:
GOSUB getcomp 'get the compass heading.
DEBUG DEC ? heading 'Display heading.
DEBUG CR
PAUSE 1000 'wait a sec.
GOTO main 'loop for ever.
'------------------------------------------------
'this routine initializes the Vector 2x compass.
'
compinit:
HIGH sclk
HIGH slct 'make sure this is high.
LOW rst 'lower reset pin.
PAUSE 15 'wait 15 ms.
HIGH rst 'raise reset pin.
PAUSE 200 'wait a bit.
RETURN 'done.
'------------------------------------------------
'This routine gets the heading from the Vector 2x
'compass and places it in the variable heading.
'
getcomp:
LOW slct 'start the Vector 2x.
PAUSE 200 'wait for heading.
heading = 0 'clear variable.
SHIFTIN sdo,sclk,MSBPRE,[heading\16]
'get the data from Vector 2x.
HIGH sclk 'reset pins.
HIGH slct
RETURN 'done.