Shop OBEX P1 Docs P2 Docs Learn Events
SEROUT command replaces a variable — Parallax Forums

SEROUT command replaces a variable

T3rr0rByte13T3rr0rByte13 Posts: 29
edited 2012-01-28 13:41 in BASIC Stamp
I am having an issue where the serout command replaces a variable i am using to store the value of IR detection. I am using a boebot with the easy bluetooth module.

the below is just a snippet of code from the program, all variables are declared.
do
freqout 2, 1, 38500
irDetectLeft = IN0

freqout 8, 1, 38500
irDetectRight = IN9

serout TX, baud, ["3"]
serout TX, baud, ["2"]
serout TX, baud, ["1"]
serout TX, baud, ["0"]

debug home, BIN1 irdetectleft, BIN1 irdetectright
loop

The problem is when the debug command shows up I see: 11 and 10 when both IR's are triggered.
However commenting out the serout commands, the debug command shows: 00 when both IR's are triggered

What am I missing??

Comments

  • walkin79walkin79 Posts: 29
    edited 2012-01-28 03:22
    sorry i dont know how to delet the message
  • walkin79walkin79 Posts: 29
    edited 2012-01-28 03:25
    same problem sorry
  • Mike GreenMike Green Posts: 23,101
    edited 2012-01-28 08:59
    The SEROUT command cannot replace a variable. There must be something else going on in your code that we can't see from the fragment you've posted. Sometimes the SEROUT statements add enough of a delay (about 1ms per character sent) that something time-dependent gets thrown off.

    walkin79,
    Use the Edit Post button at the bottom of your messages. You'll see a Delete button in the row of buttons at the bottom of the edit window.
  • T3rr0rByte13T3rr0rByte13 Posts: 29
    edited 2012-01-28 13:09
    okay I created a new file to simplify everything, this is the entire program. The code is below. Still the same issue.
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    FREQOUT 4, 2000, 3000
    RX PIN 2
    TX PIN 0
    Baud CON 84
    irDetectRight VAR Byte
    irDetectLeft VAR Byte
      DO
      FREQOUT 8, 1, 38500
      irDetectRight = IN9
      FREQOUT 2, 1, 38500
      irDetectLeft = IN0
      DEBUG HOME, BIN1 irDetectright, BIN1 irDetectleft
      SEROUT TX, Baud, ["3"]
      LOOP
      RETURN
    
  • Mike GreenMike Green Posts: 23,101
    edited 2012-01-28 13:31
    The problem is that you're using the same I/O pins for RX and TX as you're using for the left sided IR LED and detector. You're using pin #0 as an input for IR distance detection and as an output for the SEROUT. You're using pin #2 as an output for the IR LED and, presumably, you were going to use a SERIN on the same pin.

    The SEROUT sets pin #0 to output mode so the IN0 will return the state of the output register (OUTS) bit rather than the input status of the I/O pin. Putting an INPUT 0 statement after the DO will reset I/O pin #0 to input mode, but you really have to use a different I/O pin for RX and TX.
  • T3rr0rByte13T3rr0rByte13 Posts: 29
    edited 2012-01-28 13:41
    I changed the IR LED input to pin 3 and the IR detector to pin 1 and it works like a charm! Thanks Mike.
Sign In or Register to comment.