Shop OBEX P1 Docs P2 Docs Learn Events
Program Hangs using SEROUT — Parallax Forums

Program Hangs using SEROUT

chiqueschiques Posts: 21
edited 2012-12-29 19:11 in BASIC Stamp
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

Comments

  • SapphireSapphire Posts: 496
    edited 2012-12-27 19:27
    Try removing the \FC from your SEROUT command. That is Flow Control, and if your Flow Control pin is not in the correct state, SEROUT will wait forever.
  • chiqueschiques Posts: 21
    edited 2012-12-27 21:54
    Sapphire wrote: »
    Try removing the \FC from your SEROUT command. That is Flow Control, and if your Flow Control pin is not in the correct state, SEROUT will wait forever.

    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.
  • NWCCTVNWCCTV Posts: 3,629
    edited 2012-12-29 18:46
    I am no expert but maybe check your Baud rate. It has been my experience in the past that when I get "garbled" or inconsistent numbers from com ports it usually ends up being a baud setting.
  • chiqueschiques Posts: 21
    edited 2012-12-29 19:11
    Hey NWCCTV,
    That makes alot of sense. I'll try changing that around.
Sign In or Register to comment.