Good question. The HM55B is discontinued in favor of a much better compass device, but Parallax usually keeps the webstore page available for reference. Attached is my copy of the HM55B documentation and sample programs.
Each one will have a wiring diagram and sample code for the bS2.· You will· need to adjust the codes to make them work together.
Dave
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Dave Andreae
Parallax Tech Support·
first attempt probably needs adjustment
' -----[ Title ]--------------------------------------------------------------
' Smart Sensors and Applications - Ping)))Dar.bs2
' Display radar style object distance measurements in the Debug Terminal.
' as the Boe-Bot sweeps the Ping))) Mounting Bracket servo from right
' (0-degrees) to left (180-degrees).
' {$STAMP BS2} ' Target device = BASIC Stamp 2
' {$PBASIC 2.5} ' Language = PBASIC 2.5
' -----[ I/O Definitions ]----------------------------------------------------
PingServo PIN 14 ' Servo that directs Ping)))
Ping PIN 15 ' Ping))) sensor signal pin
DinDout PIN 10 ' P6 transceives to/from Din/Dout
Clk PIN 8 ' P5 sends pulses to HM55B's Clk
En PIN 9 ' 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
a VAR Word ' x-axis data
b VAR Word ' y-axis data
status VAR Nib ' Status flags
degree VAR Word ' Store angle measurement
' -----[ Constants ]----------------------------------------------------------
LimitLeft CON 1250 ' Bracket 90-degrees LimitLeft
LimitRight CON 250 ' Bracket 90-degrees LimitRight
PingDirToAngle CON 8454 ' Servo pulse -> angle with **
CmConstant CON 2260 ' Echo time -> cm with **
SinCosTo256 CON 517 ' For */ -127..127 -> -256..256
Increment CON 15 ' Servo PULSOUT increment value
Negative CON 1 ' Negative sign
Positive CON 0 ' Positive sign
' -----[ Variables ]----------------------------------------------------------
pingDir VAR Word ' Pulse duration -> direction
time VAR Word ' Ping))) echo time
distance VAR Time ' Object distance
x VAR Word ' x Debug cursor coordinate
y VAR Word ' y Debug cursor coordinate
angle VAR Byte ' Angle from LimitRight in brads
counter VAR angle ' Loop counter
sweepInc VAR Nib ' Sweep increment
sweepDir VAR Bit ' Increment/decrement pingDir
xSign VAR Bit ' x variable sign
ySign VAR xSign ' Stores sign of y variable
nsign VAR Bit ' Numerator sign
dsign VAR Bit ' Denominator sign
' -----[ Initialization ]-----------------------------------------------------
pingDir = LimitRight ' Start servo at 0-degrees
FOR counter = 1 TO 40 ' Initialize servo position
PULSOUT PingServo, pingDir
PAUSE 20
NEXT
sweepInc = Increment ' Set the sweep increment
' -----[ Main Routine ]-------------------------------------------------------
DO
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
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
IF pingDir <= LimitRight THEN ' Refresh display if far right
DEBUG CLS, CRSRXY, 50, 25, "X"
ENDIF
GOSUB Sweep_Increment ' Move servo by sweepInc
' Calculate angle from far right in brads.
angle = pingDir - LimitRight ** PingDirToAngle
GOSUB Get_Ping_Cm ' Get cm measurement
distance = distance MAX 100 / 4 ' Scale for Debug Terminal
GOSUB Polar_To_Cartesian ' distnace @ angle -> (x, y)
x = x * 2 ' 2 spaces for every 1 CR
DEBUG CRSRXY, 50 + x, 25 - y, "*" ' Display (x, y) coordinate
LOOP
' -----[ Subroutine - Get_Ping_Cm ]-------------------------------------------
' Gets Ping))) rangefinder measurement and converts time to centimeters.
' Distance may be declared as time to save variable space.
Get_Ping_Cm:
PULSOUT Ping, 5
PULSIN Ping, 1, time
distance = time ** CmConstant
RETURN
' -----[ Subroutine - Polar_To_Cartesian ]------------------------------------
' Calculates x and y (Cartesian coordinates) given distance and angle
' (polar coordinates).
Polar_To_Cartesian:
' Calculate x coordinate.
x = COS angle ' Polar to Cartesian
xSign = x.BIT15 ' Store sign bit
x = ABS(x) */ SinCOsTo256 ' Polar to Cartesian continued
x = distance */ x
IF xSign = negative THEN x = -x ' Correct sign with sign bit
' Calculate y coordinate.
y = SIN angle ' Polar to Cartesian
ySign = y.BIT15 ' Store sign bit
y = ABS(y) */ SinCOsTo256 ' Polar to Cartesian continued
y = distance */ y
IF ySign = negative THEN y = -y ' Correct sign with sign bit
RETURN
' -----[ Subroutine - Sweep_Increment ]---------------------------------------
' Increment/decrement the position of the servo that directs the Ping)))
' rangefinder. When pingDir goes outside either LimitRight or LimitLeft,
' the sweep direction toggles.
Sweep_Increment:
' Change sweepDir for adding/subtracting increment if at rotation limit.
IF pingDir <= LimitRight THEN
sweepDir = Positive
ELSEIF pingDir >= LimitLeft THEN
sweepDir = Negative
ENDIF
' Add/subtract increment to/from pingDir.
IF sweepDir = negative THEN
pingDir = pingDir - sweepInc
ELSEIF sweepDir = Positive THEN
pingDir = pingDir + sweepInc
ENDIF
' Send positioning pulse to Ping))) Mounting Bracket servo.
PULSOUT PingServo, pingDir
RETURN
' -----[ Subroutines - get axis ]-----------------------------
Compass_Get_Axes: ' Compass module subroutine
HIGH En: LOW En ' Send reset command to HM55B
SHIFTOUT DinDout,clk,MSBFIRST,[Reset\4]
HIGH En: LOW En ' HM55B start measurement command
SHIFTOUT DinDout,clk,MSBFIRST,[Measure\4]
status = 0 ' Clear previous status flags
DO ' Status flag checking loop
HIGH En: LOW En ' Measurement status command
SHIFTOUT DinDout,clk,MSBFIRST,[Report\4]
SHIFTIN DinDout,clk,MSBPOST,[Status\4] ' Get Status
LOOP UNTIL status = Ready ' Exit loop when status is ready
SHIFTIN DinDout,clk,MSBPOST,[x\11,y\11] ' Get x & y axis values
HIGH En ' Disable module
IF (b.BIT10 = 1) THEN b = b | NegMask ' Store 11-bits as signed word
IF (a.BIT10 = 1) THEN a = a | NegMask ' Repeat for other axis
RETURN
Good question. The HM55B is discontinued in favor of a much better compass device, but Parallax usually keeps the webstore page available for reference. Attached is my copy of the HM55B documentation and sample programs.
Howdy- what is this new compass device? Currently when I go to compass sensors absolutely none show up- it is all GPS. Can you direct me to this new compass? Thanks
Howdy- what is this new compass device? Currently when I go to compass sensors absolutely none show up- it is all GPS. Can you direct me to this new compass? Thanks
Comments
http://www.parallax.com/Store/Sensors/CompassGPS/tabid/173/CategoryID/48/List/0/Level/a/ProductID/98/Default.aspx?SortField=ProductName%2cProductName
http://www.parallax.com/Store/Robots/RoboticAccessories/tabid/145/CategoryID/22/List/0/SortField/0/Level/a/ProductID/248/Default.aspx
Each one will have a wiring diagram and sample code for the bS2.· You will· need to adjust the codes to make them work together.
Dave
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Dave Andreae
Parallax Tech Support·
P.S.: I just remember that the use of compass is only for data-log.
Post Edited (MichelB) : 6/22/2009 4:22:46 PM GMT
Howdy- what is this new compass device? Currently when I go to compass sensors absolutely none show up- it is all GPS. Can you direct me to this new compass? Thanks