Program Hangs using SEROUT
chiques
Posts: 21
My intent is to capture the numeric value from my distance sensor and send it via the SEROUT command. Currently I'm using two sample programs and combining them to verify I have the correct syntax. The problem is when I comment out the SEROUT command my program hangs. Any suggestions why I get stuck here?
P.S. I understand I don't have the Ping variable in the SEROUT argument, my intent is to get this program to run and I'll slowly add the appropriate variables.
Thanks for any help.
CODE:
' {$STAMP BS2}
' {$PBASIC 2.5}
'
[ Constants ]
#SELECT $STAMP
#CASE BS2, BS2E
Trigger CON 5 ' trigger pulse = 10 uS
Scale CON $200 ' raw x 2.00 = uS
T1200 CON 813
T2400 CON 396
T9600 CON 84
T19K2 CON 32
T38K4 CON 6
#CASE BS2SX, BS2P, BS2PX
Trigger CON 13
Scale CON $0CD ' raw x 0.80 = uS
#CASE BS2PE
Trigger CON 5
Scale CON $1E1 ' raw x 1.88 = uS
#ENDSELECT
RawToIn CON 889 ' 1 / 73.746 (with **)
RawToCm CON 2257 ' 1 / 29.034 (with **)
IsHigh CON 1 ' for PULSOUT
IsLow CON 0
Baud CON T38K4 + Inverted
Inverted CON $4000
Open CON $8000
'
[ I/O Definitions ]
Ping PIN 15
SO PIN 1 ' serial output
FC PIN 0 ' flow control pin
'
[ Variables ]
rawDist VAR Word ' raw measurement
inches VAR Word
cm VAR Word
'
[ Initialization ]
Reset:
DEBUG CLS, ' setup report screen
"Parallax Ping Sonar ", CR,
"=====================", CR,
CR,
"Time (uS)..... ", CR,
"Inches........ ", CR,
"Centimeters... "
'
[ Program Code ]
Main:
DO
GOSUB Get_Sonar ' get sensor value
inches = rawDist ** RawToIn ' convert to inches
cm = rawDist ** RawToCm ' convert to centimeters
DEBUG CRSRXY, 15, 3, ' update report screen
DEC rawDist, CLREOL,
CRSRXY, 15, 4,
DEC inches, CLREOL,
CRSRXY, 15, 5,
DEC cm, CLREOL
SEROUT SO\FC, Baud, ["Hello!", CR] ' send the greeting
PAUSE 1000
LOOP ' repeat forever
END
Get_Sonar:
Ping = IsLow ' make trigger 0-1-0
PULSOUT Ping, Trigger ' activate sensor
PULSIN Ping, IsHigh, rawDist ' measure echo pulse
rawDist = rawDist */ Scale ' convert to uS
rawDist = rawDist / 2 ' remove return trip
RETURN
P.S. I understand I don't have the Ping variable in the SEROUT argument, my intent is to get this program to run and I'll slowly add the appropriate variables.
Thanks for any help.
CODE:
' {$STAMP BS2}
' {$PBASIC 2.5}
'
[ Constants ]
#SELECT $STAMP
#CASE BS2, BS2E
Trigger CON 5 ' trigger pulse = 10 uS
Scale CON $200 ' raw x 2.00 = uS
T1200 CON 813
T2400 CON 396
T9600 CON 84
T19K2 CON 32
T38K4 CON 6
#CASE BS2SX, BS2P, BS2PX
Trigger CON 13
Scale CON $0CD ' raw x 0.80 = uS
#CASE BS2PE
Trigger CON 5
Scale CON $1E1 ' raw x 1.88 = uS
#ENDSELECT
RawToIn CON 889 ' 1 / 73.746 (with **)
RawToCm CON 2257 ' 1 / 29.034 (with **)
IsHigh CON 1 ' for PULSOUT
IsLow CON 0
Baud CON T38K4 + Inverted
Inverted CON $4000
Open CON $8000
'
[ I/O Definitions ]
Ping PIN 15
SO PIN 1 ' serial output
FC PIN 0 ' flow control pin
'
[ Variables ]
rawDist VAR Word ' raw measurement
inches VAR Word
cm VAR Word
'
[ Initialization ]
Reset:
DEBUG CLS, ' setup report screen
"Parallax Ping Sonar ", CR,
"=====================", CR,
CR,
"Time (uS)..... ", CR,
"Inches........ ", CR,
"Centimeters... "
'
[ Program Code ]
Main:
DO
GOSUB Get_Sonar ' get sensor value
inches = rawDist ** RawToIn ' convert to inches
cm = rawDist ** RawToCm ' convert to centimeters
DEBUG CRSRXY, 15, 3, ' update report screen
DEC rawDist, CLREOL,
CRSRXY, 15, 4,
DEC inches, CLREOL,
CRSRXY, 15, 5,
DEC cm, CLREOL
SEROUT SO\FC, Baud, ["Hello!", CR] ' send the greeting
PAUSE 1000
LOOP ' repeat forever
END
Get_Sonar:
Ping = IsLow ' make trigger 0-1-0
PULSOUT Ping, Trigger ' activate sensor
PULSIN Ping, IsHigh, rawDist ' measure echo pulse
rawDist = rawDist */ Scale ' convert to uS
rawDist = rawDist / 2 ' remove return trip
RETURN
Comments
I tried that and it seems to loop. Now the problem is the data I'm reading from my other Mcu (Arduino Mega 2560) has no meaning with respect to the original 'DEC 10' for example. This should give something that represents decimal 10 but instead I am reading some trivial numbers.
The BASIC stamp manual is very complicated when explaining the SEROUT command so I'll need to keep experimenting with this. Thanks for the coding help though.
That makes alot of sense. I'll try changing that around.