Basic Stamp, Linux Shell, Serial communications, Help
Hi all,
I'm trying to get my Linux shell (Ubuntu 12.04.1) to communicate with my Basic Stamp (BS2) by simply writing to /dev/ttyS0 (with something like CAT). At the moment I've managed to get my Stamp to respond to data sent through the terminal, but it doesn't respond the way I think it should. Here is my Basic Stamp code:
' {$STAMP BS2}
' {$PBASIC 2.5}
sData VAR Byte
SERIN 16, 84, [DEC sData]
i VAR Byte
FOR i = 1 TO sData
HIGH 1 ' I have an LED connected to pin 1
PAUSE 250
LOW 1
PAUSE 250
NEXT
The trouble is that the number of blinks of the LED are unpredictable. I type in "1" (using the command "cat > /dev/ttyS0" and then typing the number), it blinks twice. I type in "1" again, it blinks nine times, now eight, two again, but never one. I have the port set to the same baud rate as my Stamp, and I've set no parity and 8-bit on the port as well; or, at least I think I have. I used the command "stty -F /dev/ttyS0 -parenb cs8", and I set the baud rate with setserial.
I don't understand the problem. I tried converting from ASCII the hard way (input-48) but that didn't work, I tried using DEBUGIN instead of SERIN and that didn't work. However, everything does work correctly when I use the Debug window on the Basic Stamp Editor.
Thanks,
SB316
I'm trying to get my Linux shell (Ubuntu 12.04.1) to communicate with my Basic Stamp (BS2) by simply writing to /dev/ttyS0 (with something like CAT). At the moment I've managed to get my Stamp to respond to data sent through the terminal, but it doesn't respond the way I think it should. Here is my Basic Stamp code:
' {$STAMP BS2}
' {$PBASIC 2.5}
sData VAR Byte
SERIN 16, 84, [DEC sData]
i VAR Byte
FOR i = 1 TO sData
HIGH 1 ' I have an LED connected to pin 1
PAUSE 250
LOW 1
PAUSE 250
NEXT
The trouble is that the number of blinks of the LED are unpredictable. I type in "1" (using the command "cat > /dev/ttyS0" and then typing the number), it blinks twice. I type in "1" again, it blinks nine times, now eight, two again, but never one. I have the port set to the same baud rate as my Stamp, and I've set no parity and 8-bit on the port as well; or, at least I think I have. I used the command "stty -F /dev/ttyS0 -parenb cs8", and I set the baud rate with setserial.
I don't understand the problem. I tried converting from ASCII the hard way (input-48) but that didn't work, I tried using DEBUGIN instead of SERIN and that didn't work. However, everything does work correctly when I use the Debug window on the Basic Stamp Editor.
Thanks,
SB316
Comments
hth.