Shop OBEX P1 Docs P2 Docs Learn Events
BS2 Linux serial commands or shell script for sending and receiving serial ? — Parallax Forums

BS2 Linux serial commands or shell script for sending and receiving serial ?

nick03nick03 Posts: 4
edited 2011-11-27 09:20 in General Discussion
Hi, this is my first thread/question....

I have a Basic Stamp 2 and need it to communicate with my Linux server (Debian 6.0.3).
I am trying to use serial to communicate between them (Serin & Serout),
but I am having troubles with the Linux part. I have read about using: echo Value > ttyS1
and it has not worked for me, so i need help to make a shell script to send a Word value
and receive a value.

Thanks in advance.

Comments

  • FranklinFranklin Posts: 4,747
    edited 2011-11-25 22:23
    Have you been able to open a serial terminal and communicate with the stamp? how do you have the stamp connected to the computer? You should be able to write a program that sends serial bits to the computer and see tham arrive.
  • nick03nick03 Posts: 4
    edited 2011-11-25 23:16
    I use my Windows computer for flashing the code to the Basic Stamp. To interface my Linux server I use the pins 15 & 14 for tx & rx from BS2 to serial on back of server. I have not used a serial terminal before. I know anough if I need to use C for a program, but would prefer some type of script for easy editing/modifing. So any sugestions? Thanks.

    I'm currently am using 5 parallel ports with only outputs for my project of controlling all of the lights in my room (a big bundle of wire) and am seeking more i/o's for adding possibility to control a rc car and 3 tv's (as in remote control functions). I just can't get the serial from the server to the Basic Stamp, but am able to use serial for connecting to a XBee to link to other XBee's for control in other areas wirelessly.
  • Kevin WoodKevin Wood Posts: 1,266
    edited 2011-11-26 13:13
    Hello Nick, welcome to the forums.

    I suggest taking a look at Python, which offers you an interactive shell as well as traditional scripting. You can develop your script on Windows, then make the necessary changes to port it to Linux (ie, different serial port names).

    Python may not be installed by default on Debian, but it will be in the repo. You'll want to look for a recent 2.x version (2.6 or 2.7), and you'll need to download and install the PySerial module. You'll also need Python on Windows. There are a few different releases, but I suggest ActivePython by ActiveState. It comes with a built-in IDE, but I suggest Komodo Edit or Notepad++ as better choices.
  • nick03nick03 Posts: 4
    edited 2011-11-26 13:20
    Thanks for the welcome, so from what I understand python is code to use. Is it hard to learn?
    Do you have any recommendations on a way to learn it like a book or something?
  • Kevin WoodKevin Wood Posts: 1,266
    edited 2011-11-26 14:50
    Well, Python is just one of many options, but a good one anyways. It's not that difficult to learn.

    As for learning material... if you don't have much programming experience, try this course from MIT. It uses Python to teach the principles of computer science. If you already feel comfortable with basic programming concepts, you can try Learn Python the Hard Way, which is more of a tutorial. There's also the official online documentation.
  • FranklinFranklin Posts: 4,747
    edited 2011-11-26 14:52
    I use the pins 15 & 14 for tx & rx from BS2 to serial on back of server
    how are you connecting these? The stamp is not RS232 compatable so you need a chip or device to do level shifting between the stamp and most computer serial ports.
  • nick03nick03 Posts: 4
    edited 2011-11-26 15:05
    I did not know it wasn't compatible (how stupid of me). So what would be the best way to have a shell script communicate with the Basic Stamp 2?

    I would hate to go back to using parallel ports for my project.
  • FranklinFranklin Posts: 4,747
    edited 2011-11-26 22:06
    Actually I may be wrong but I would check out the help files you can get online to see if certain pins on the stamp will work directly with the computer.
    It looks like you need to use pins 1 and 2 for serial http://www.parallax.com/Portals/0/Downloads/docs/prod/schem/BS2revJSchematic.pdf
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2011-11-27 09:20
    Yes. SOUT to DB9 Pin 2 and SIN to DB9 Pin 3 will work directly with the RS232 port on your computer and check the BasicStamp Manual for the default Baud rate and default protocol. Don't forget a share ground via DB9 Pin 5. No level shifters required over short distance cables.

    Before you get into shell scripts in Python, BASH, or whatever; you may just want to get your serial port up and running in a Terminal window.

    The truth is that the BasicStamps don't require much, but it helps to start out by having the BasicStamp send a prompt character and going on from there or using DEBUG to send a stream of output to your computer as a test.

    Take a look at this site for set up. Use Google searches for "Linux HOWTO ?????" for specific topics.

    http://linux.koolsolutions.com/2008/04/10/how-to-test-serial-ports-under-debian-linux/

    Install 'minicom' and learn how to use it. If you need to use a USB to Serial adapter, that still will accept use of 'minicom'.

    In many cases, your shell script can evoke 'minicom' and then redirect standard output, standard input, and standard error as required.

    http://www.cyberciti.biz/tips/connect-soekris-single-board-computer-using-minicom.html

    http://linux.about.com/od/commands/l/blcmdl1_minicom.htm

    http://linux.die.net/man/1/runscript
Sign In or Register to comment.