Serin only get "o" : Noob code problem
Orange
Posts: 14
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.
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
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 Savage
Parallax Tech Support
I will be more observant of the rules.