Shop OBEX P1 Docs P2 Docs Learn Events
Basic Stamp, Linux Shell, Serial communications, Help — Parallax Forums

Basic Stamp, Linux Shell, Serial communications, Help

SB316SB316 Posts: 33
edited 2012-09-13 05:38 in BASIC Stamp
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

Comments

  • FranklinFranklin Posts: 4,747
    edited 2012-08-24 13:19
    You might try having the stamp send back what it thinks sData is (serout sData)
  • softconsoftcon Posts: 217
    edited 2012-09-13 05:38
    Just for testing purposes, until you know everything works, just use minicom to talk to the stamp. Once minicom produces proper results, then you can go back to talking via redirection via /dev/ttysx, though I think you should be using /dev/cuax instead, since those are the ones used by modems for bidirectional talking. I don't remember the reason for this, it's been some years since I had a working linux box, (I'm talking slackware 7.0 kind of years) so it could be recommendations have changed again, but regardless, try minicom to see if you get the results you expect, then if that works, go back to your redirection method, and see what happens, it may just be as simple as your cr is being interpreted to be a number, and confusing things.
    hth.
Sign In or Register to comment.