Shop OBEX P1 Docs P2 Docs Learn Events
Serin only get "o" : Noob code problem — Parallax Forums

Serin only get "o" : Noob code problem

OrangeOrange Posts: 14
edited 2007-11-02 02:27 in BASIC Stamp
Guys I am using basic stamp 2px with board of education. I am very new to basic stamp so please bear with me.

I have a sensor which output RS232 8bit, No parity, 1 stop bit (check it using hyperterminal). I am not sure whether it is inverted or true.

The output rate is about 5Hz with the following string (from hyperterminal)
"0.3178, -0.2921, -0,9034, 101,12, 106.50"

I use a 22kOhm resistor on the serial input DB pin 3 to P0 and stick the pin 5 to VSS. There is no serial output from the basic stamp as I do not have a MAX232A TTL RS232 converter yet.

With this code:
' {$STAMP BS2px}
' {$PBASIC 2.5}
serdata VAR Byte
SERIN 0, 18447, [noparse][[/noparse] serdata]
DEBUG serdata

From the debug terminal I got:
ÿ



With this code
' {$STAMP BS2px}
' {$PBASIC 2.5}
serdata VAR Byte
SERIN 0, 18447, [noparse][[/noparse] serdata]
DEBUG DEC serdata

From the debug terminal I got:
255



with this code:
' {$STAMP BS2px}
' {$PBASIC 2.5}

serStr VAR Byte(10) ' make 10-byte array
serStr(9) = 0 ' put 0 in last byte of array
SERIN 0, 18447, [noparse][[/noparse] STR serStr\9] ' stop at "*" or nine bytes
DEBUG STR serStr ' display

From the debug terminal i got
ÿÿÿÿÿÿÿÿÿ




' {$STAMP BS2px}
' {$PBASIC 2.5}

serdata VAR Byte
SERIN 0, 2063, [noparse][[/noparse] serdata]
DEBUG DEC serdata

From the debug terminal I got
o


So, guys I am not sure where is wrong with my code.

Thanks.

Comments

  • ZootZoot Posts: 2,227
    edited 2007-10-22 20:57
    Try like this:

    ' {$STAMP BS2px}
    ' {$PBASIC 2.5}
    serdata VAR Byte
    again:
       SERIN 0, 18447, [noparse][[/noparse] serdata]
      DEBUG serdata
      GOTO again
    
    



    Going by your post, you are getting ascii text, so you need "debug" it that way -- if you wanted to use the vals as numbers, you would need to capture the string (delimited by spaces?), then parse each character to get your number (plus account for decimals). But first check that you are getting the data in to begin with.

    See SERIN in the Stamp Manual -- if the string you posted is accurate, you could serin till you reach ", " (comma+space) then presume characters up to that point were the "number". It'll still be a stream of text characters, however, not a "number".

    Lastly, your code shows baud rate of 1200? Make sure that matches the baud rate specified by your sensor's manufacturer.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-10-23 17:19
    It seems you have multiple threads for the same issue. Do not cross post. Please keep your follow ups in the original thread instead of starting a new one each time.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • OrangeOrange Posts: 14
    edited 2007-11-02 02:27
    Thanks guys!

    I will be more observant of the rules.
Sign In or Register to comment.