Shop OBEX P1 Docs P2 Docs Learn Events
RS 232 Question for a newbe (BS2) — Parallax Forums

RS 232 Question for a newbe (BS2)

YORKIEYORKIE Posts: 6
edited 2011-05-08 06:26 in BASIC Stamp
Hi there,

I'm new to Parallax and the world of Basic Stamp.

I have completed many experiments, and I want to further one particular experiment for a future application.
The experiment was controlling the position of a servo with a potentiometer using an RC time circuit.

What I want to achieve is the same, but over a range of 50 meters/150ft.
I believe this can be achieved using two basic stamps, connected via RS232

One basic stamp being the input - Potentiometer/RC time circuit and the second module being the output - Servo connected.

Can anyone point me in the right direction as to what code I need on each of the modules?

This is my code so far:

' What's a Microcontroller - ControlServoWithPot.bs2
' Read potentiometer in RC-time circuit using RCTIME command.
' Scale time by 0.724 and offset by 500 for the servo.

' {$STAMP BS2}
' {$PBASIC 2.5}

PAUSE 1000
DEBUG "Program Running!"
time VAR Word

DO
HIGH 7
PAUSE 10
RCTIME 7, 1, time
time = time */ 185 ' Scale by 0.724 (X 256 for */).
time = time + 500 ' Offset by 500.
PULSOUT 14, time ' Send pulse to servo.
LOOP

Thanks in advance
=]

Comments

  • RiJoRiRiJoRi Posts: 157
    edited 2011-05-06 05:32
    Remember that the RS-232 standard defines the maximum length as 50 feet (~17 meters). While people have used greater lengths with CAT5 cable, AND low baud rates to extend the limit, it is in general not a good idea. See http://www.rs485.com/rs485spec.html for an overview of the standards.

    --Rich
  • YORKIEYORKIE Posts: 6
    edited 2011-05-06 06:35
    Thanks Rich, I didn't realize....

    Ok then, same question, but how to I go about using 485 for the comms.
    Would I set it up as 232, and use a 485 converter?

    Thanks
    Yorkie
  • stamptrolstamptrol Posts: 1,731
    edited 2011-05-06 07:14
    At low baud rates, say 1200 or 2400 and sending a few bytes with SEROUT, you won't have any trouble at 150 feet.

    '485 is a good thing to learn about. Use 75176 chips (or the more modern versions) at each end to create a half-duplex system that can be adapted to a wide range of communication tasks.

    Cheers,
  • Mike GreenMike Green Posts: 23,101
    edited 2011-05-06 07:18
    You're substituting one electrical standard (RS485) for another (RS232). The Stamps use logic levels (0V / 5V) for their serial data signals except for the programming / debug port which has some interface electronics in it that makes it compatible with RS232, but not strictly satisfying the RS232 requirements. To do that would require a converter like the MAX232. For RS485, instead of a MAX232, you'd use something like a MAX483E.

    True RS232 signal levels (not what's used for the programming / debug port) are used all the time over a 50 meter range. In a high electrical noise environment or where you want speeds greater than say 9600 Baud, you may want to use RS485.
  • YORKIEYORKIE Posts: 6
    edited 2011-05-06 07:28
    Thanks guys, some very useful information there.

    I would like to go ahead and use RS232 over the range, which is actually 40m. I believe I can achieve this with RS232.

    Any help on the code would greatly be appreciated.
    Best Regards
    Yorkie
  • stamptrolstamptrol Posts: 1,731
    edited 2011-05-06 09:31
    As Mike pointed out, don't confuse serial communication with the standards that describe it ( rs-232, rs-485, rs-422).

    You'll be able to use SERIAL communication by tieing two stamps together, but unless there's some over-riding technical need, you'll probably do it with the 5 volt levels of the stamp, not the "real" RS-232 levels of +/- 12 volts or +/- 15 volts.

    See the Help file under SERIN for a solid example of how to connect 2 stamps together.

    Cheers,
  • YORKIEYORKIE Posts: 6
    edited 2011-05-08 03:14
    Ok, here it is..

    If I use the stamps 5v SERIN/SEROUT for communication, what range would I be looking at.

    About the code, I can't get my head around the help file.
    Please, Please someone give me a wee hint.

    Thanks
  • stamptrolstamptrol Posts: 1,731
    edited 2011-05-08 04:19
    5v serin/serout will get you well beyond the range you described. Keep the speed down in the 1200 or 2400 baud range.

    The example in the SERIN helpfile is quite straight forward and has the connections and sample code. Its near the bottom of the Help article for SERIN.

    You've already got the servo code. Just add on the serial communication code.

    Cheers,
  • YORKIEYORKIE Posts: 6
    edited 2011-05-08 04:38
    Hi Tom,

    Sorry to be a pain, but which Help file are you referring to?

    Cheers mate
  • stamptrolstamptrol Posts: 1,731
    edited 2011-05-08 06:00
    Open the Stamp software as if you were going to write a program.

    Click on "Help", then "Index". Scroll down to SERIN.

    If you're on a Mac, I don't know where the file resides, but you can probably download it as a text file fromthe Parallax web site.
  • YORKIEYORKIE Posts: 6
    edited 2011-05-08 06:26
    Thanks Tom,

    Got it! I am running on a Mac, but recently installed Parallels which lets me run windows as a virtual machine.
    Just downloaded the Stamp Editor, and found the help section.

    I will read through, and try and grasp it.

    Many Thanks for your help.
    Nik
Sign In or Register to comment.