Shop OBEX P1 Docs P2 Docs Learn Events
RS232/ DB9 and Serial — Parallax Forums

RS232/ DB9 and Serial

Johnny5Johnny5 Posts: 10
edited 2009-08-06 23:43 in BASIC Stamp
Hi folks. I am just trying to send a message to my computer and back. Can someone tell me what I am doing wrong with the connection of the wires?

' {$STAMP BS2}
' {$PBASIC 2.5}
' {$PORT COM5}
test:
·SEROUT 1, 16780, 1000, [noparse][[/noparse]"Slowly"]
·GOTO test




The following is my C#.Net code:

sp.Open();

sp.ReadTimeout = 500;

sp.BaudRate =9600

sp.PortName="COM4";

this.lblSerIn.Text = sp.ReadLine();

sp.Close();

800 x 600 - 119K

Comments

  • Johnny5Johnny5 Posts: 10
    edited 2009-08-04 05:16
    Or point me to how to connect a RS232 to the Basic Stamp board
  • Mike GreenMike Green Posts: 23,101
    edited 2009-08-04 05:30
    The ' {$PORT COM5} line specifies the serial port to be used by the Stamp Editor for programming the Stamp. It has nothing to do with what the program does while executing.

    The easiest way to communicate with a PC RS232 port is to use the same serial port used for programming. The DEBUG and DEBUGIN statements do this. You can also use the SEROUT and SERIN statements with pin # 16. Read the chapters in the Basic Stamp Syntax and Reference Manual for more information. The same information is in the help files of the Stamp Editor. The same chapters in the manual show how to connect Stamp I/O pins to most RS232 ports. The signal levels involved (+5V / 0V) may work with most RS232 ports, but not all. For those, you'll have to use something like a MAX232 to convert the signal levels back and forth.
  • Johnny5Johnny5 Posts: 10
    edited 2009-08-04 05:50
    Thanks Mike. I will read more tomorrow during lunch at work.
  • Johnny5Johnny5 Posts: 10
    edited 2009-08-04 14:29
    I have the USB version of the education board. If I were to use the SEROUT and SERIN statements with pin # 16, would it work like this at 9600 baud rate? -->


    test:
    SEROUT 16, 16780, [noparse][[/noparse]"Slowly"]
    GOTO test


    Or am I totally off?
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2009-08-04 18:19
    Hi Johnny5, that's right with the exception that the baud rate for a BS2 at 9600 is 16468 eg:··· SEROUT 16,16468,[noparse][[/noparse]"Slowly"]

    To begin I would probably work with a baud of 4800 until you have things working right. Read the help files in the Pbasic IDE for more information.

    The following link refers to Visual Basic but the principal is the same for C# , of particular interest is the use of a "header" and newline character to "frame" your data.

    http://forums.parallax.com/showthread.php?p=671804

    Using the programming port (P16) is ideal , one thing might throw you at first is the fact that every character the PC ( C#) transmits is echoed back to the PC. If you don't take care of the echo it will mix with the next transmission.

    Jeff T.
  • Johnny5Johnny5 Posts: 10
    edited 2009-08-04 18:22
    Thank you very much. I will try it out tonight when I get home.
  • wingerwinger Posts: 3
    edited 2009-08-06 18:55
    With that in mind about SERIN and SEROUT, can the EEPROM read data stored in a database or file and accept it as data stored in its table?
  • Johnny5Johnny5 Posts: 10
    edited 2009-08-06 19:00
    I was able to get it running. I had to close out of the Basic Stamp Editor.
    I will post a solution and code up soon.
  • Johnny5Johnny5 Posts: 10
    edited 2009-08-06 19:03
    winger said...
    With that in mind about SERIN and SEROUT, can the EEPROM read data stored in a database or file and accept it as data stored in its table?
    That is my intention of the application. It will transmit values and signals to the computer and the computer is going to determine what to do based on what's stored in the computer's database.
  • wingerwinger Posts: 3
    edited 2009-08-06 19:20
    So Johnny5, can the database save information that the EEPROM can read? And how do you define to the program the location of the database file on the computer? That is where I am having trouble.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-08-06 19:39
    winger,
    "can the database save information that the EEPROM can read?" No, not quite

    The EEPROM in the Stamp is used for two things ... 1) to store the program to be executed; 2) to store data with the WRITE statement that can be accessed with the READ statement. You can include data with your program using the DATA statement. This is the same as data written with the WRITE statement, just initialized when your program is downloaded to the Stamp.

    If there's a database on your PC that you want to access from a Stamp, you have to write a program for the Stamp and a program for the PC to do this. The PC program waits for a request from the Stamp made up of serial data sent over a COM port. It decodes the request to determine what data needs to be accessed, accesses the data, and sends it to the Stamp in whatever format you need. The Stamp program does the opposite. It sends a request to the PC using a serial port with the data in whatever format you decide, then waits for a response from the PC. It decodes the data and makes use of it for whatever purpose you need.

    Have a look at the PC program StampPlotPro at www.selmaware.com (and also from Parallax).
  • wingerwinger Posts: 3
    edited 2009-08-06 20:12
    Thank You Mr. Mike Green!!! That information helps greatly. Will post an update on what I find
  • dev/nulldev/null Posts: 381
    edited 2009-08-06 23:43
    You will probably have problems with this.lblSerIn.Text = sp.ReadLine();.

    The serial control is event-driven, and you should read data when the DataReceived() event is triggered on the control.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Don't worry. Be happy
Sign In or Register to comment.