Shop OBEX P1 Docs P2 Docs Learn Events
BS2 to RS-232-to-RS-485 Converter to Pelco D PTZ Camera? — Parallax Forums

BS2 to RS-232-to-RS-485 Converter to Pelco D PTZ Camera?

FalconFalcon Posts: 191
edited 2012-09-11 16:28 in BASIC Stamp
I've poured over the forums but did not find a whole lot of information regarding control of a Pelco protocol PTZ camera other than using SSR's. So I plan to give it a try sometime later this year.

The Pelco D protocol uses the RS-485 format. I've not heard that the BS2 can output RS-485 format so I plan to use an RS-232 to RS-485 converter, and drive the PTZ camera from that converter. Correct me if I'm wrong.

The data I've found so far shows the Pelco D protocol using the following parameters:

Baud: 4800
Parity: none
Start Bit: 1
Data Bits: 8
Stop Bits: 1

The Table 5.106 (page 418) of the BSM describes how to develop a Baudmode. Using the above info, I have 188 after Step 2. However, I'm not sure how to factor in the above info to answer Steps 3 (True or Inverted) or Step 4 (Driven or Open).

The Note under Table 5.107 includes the following, "If the dedicated serial port (Tpin=16) is used, the data is inverted." If I decide to use I/O pins other than Pin 16 I suppose the answer to Step 3 is True=0.

I've read pages 424 - 427 but I did not resolve Step 4.

What would be the correct Baud mode for the above parameters? What circuit factors would affect this in regard to the RS-485?

falcon

Comments

  • stamptrolstamptrol Posts: 1,731
    edited 2012-05-09 05:01
    Using the Stamp with rs485 is not difficult. Your example is using 4800-8-N-1 see the table in the Stamp Helpfile under SEROUT or SERIN.

    You can use a commercial 232-485 converter on the programming port (pin 16) which has the required inversion circuitry to make life a little easier. As long as the converter has the on-board ability to provide the standard rs-232 voltage levels, it is largely a plug-and-play exercise. Having to flip pin 2-3 is usually the only necessary change with some converters. Many have a switch to allow this to be changed easily.

    An alternative is to use a 75176 chip (or one of the similar, more modern chips) which converts from the Stamp i/o pin TTL levels directly to rs-485.

    By using the 75176 chip, you'll gain a better understanding of serial communication in general which is always a good thing. Also the chip is very low cost compared to the commercial converter.

    Cheers,
  • FalconFalcon Posts: 191
    edited 2012-05-10 04:45
    Stamptrol,
    I appreciate your assistance.

    I ordered a couple cheap RS232 to RS485 converters. I will also throw a 75176 chip in my cart the next time I make a DigiKey order.

    Can you expand on the "flip 2-3- pin" part? Or point me to a thread or link to help explain it. I've not heard of that.

    I will ultimately use two XBee modules as follows: BS2 (or Prop)→XBee Ser 1(Out)→XBee Ser 1(In)→RS232 to RS485 converter→PTZ camera. Will this create any additional

    falcon
  • stamptrolstamptrol Posts: 1,731
    edited 2012-05-10 06:40
    Falcon,

    Its nothing to get too concerned about at this point.

    As you're aware, there is one pin designated Tx and one designated Rx on the serial connector. There are two general configuarations of that connector that manufacturers use: DTE (data terminal equipment) and DCE (data communucation equipment). In one, Tx is pin 2, Rx is pin 3; in the other, its reversed. Its quite common during set up of a serial link to have to flip or interchange pin 2 and 3 to get the Tx at one end to be connected to Rx on the other and vice versa.

    The ultimate serial guide is Jan Axelson's "Serial Port Complete".

    The XBee solution should work fine. But, get the system working via a wired connection first to minimize startup problems.

    Cheers,
  • FalconFalcon Posts: 191
    edited 2012-09-01 12:31
    Well, I wasn't able to get this to work so I worked on other projects for a while. I came back to it this morning...and got it to work. It turns out the SN75176 chip did not have the typical notch near pin 1, and I had it installed backwards.

    I was able to get Pan Right/Left and Tilt Up/Down working with the Parallax 5-Position switch, and two other SPST switches for the Zoom In/Out.

    The code is pretty simple but it is a building block. Changing the speed of movements requires changing one byte and updating the Check Sum byte. That will have to wait.
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    
    
    
    xm_rcv     CON 0                                   ' Pin 0 sets transmit (1) or receive (0).
    serIO      CON 1                                   ' Pin 1 is used for serial input/output.
    baud       CON 396                                 ' 8 bit No Parity True 2400-baud serial baudmode.
    
    ' WORD    1          2            3            4           5          6             7
    '       Sync      Address     Command 1   Command 2      Data 1     Data 2      Check Sum
    
    
    Camera_On:                                         ' Initialization
    HIGH xm_rcv
    PAUSE 10                                           ' Turn on 485 transmitter; wait briefly.
    SEROUT serIO,baud,[$FF,$02,$88,$00,$00,$00,$8A]    ' Id2
    PAUSE 10
    LOW xm_rcv                                         ' Switch to receive mode.
    DEBUG "Camera On", CR
    PAUSE 1000
    
    HIGH xm_rcv                                        'Stops any current movement
    PAUSE 1                                            ' Turn on 485 transmitter; wait briefly.
    SEROUT serIO,baud,[$FF,$02,$00,$00,$00,$20,$02]    ' Id
    LOW xm_rcv                                         ' Switch to receive mode.
    DEBUG "Stop", CR
    
    main:
    
      IF (IN3 = 0) THEN Pan_Left_Medium
      IF (IN4 = 0) THEN Tilt_Down_Medium
      IF (IN5 = 0) THEN Pan_Right_Medium
      IF (IN7 = 0) THEN Tilt_Up_Medium
      IF (IN10 = 0) THEN Zoom_In
      IF (IN11 = 0) THEN Zoom_Out
    GOTO Move_STOP
    
    
    Pan_Right_Medium:
    HIGH xm_rcv
    PAUSE 1                                            ' Turn on 485 transmitter; wait briefly.
    SEROUT serIO,baud,[$FF,$02,$00,$02,$00,$20,$24]    ' Id
    LOW xm_rcv                                         ' Switch to receive mode.
    DEBUG "Pan Right Medium", CR
    GOTO main
    
    
    Pan_Left_Medium:
    HIGH xm_rcv
    PAUSE 1                                            ' Turn on 485 transmitter; wait briefly.
    SEROUT serIO,baud,[$FF,$02,$00,$04,$00,$20,$26]    ' Id2
    LOW xm_rcv                                         ' Switch to receive mode.
    DEBUG "Pan Left Medium", CR
    GOTO main
    
    
    Tilt_Up_Medium:
    HIGH xm_rcv
    PAUSE 1                                            ' Turn on 485 transmitter; wait briefly.
    SEROUT serIO,baud,[$FF,$02,$00,$08,$00,$20,$2A]    ' Id2
    LOW xm_rcv                                         ' Switch to receive mode.
    DEBUG "Tilt Up", CR
    GOTO main
    
    
    
    Tilt_Down_Medium:
    HIGH xm_rcv
    PAUSE 1                                            ' Turn on 485 transmitter; wait briefly.
    SEROUT serIO,baud,[$FF,$02,$00,$10,$00,$20,$32]    ' Id
    LOW xm_rcv                                         ' Switch to receive mode.
    DEBUG "Tilt Down", CR
    GOTO main
    
    
    Zoom_In:
    HIGH xm_rcv
    PAUSE 1                                            ' Turn on 485 transmitter; wait briefly.
    SEROUT serIO,baud,[$FF,$02,$00,$20,$00,$20,$42]    ' Id
    LOW xm_rcv                                         ' Switch to receive mode.
    DEBUG "Zoom In", CR
    GOTO main
    
    
    Zoom_Out:
    HIGH xm_rcv
    PAUSE 1                                            ' Turn on 485 transmitter; wait briefly.
    SEROUT serIO,baud,[$FF,$02,$00,$40,$00,$20,$62]    ' Id2
    LOW xm_rcv                                         ' Switch to receive mode.
    DEBUG "Zoom Out", CR
    GOTO main
    
    
    Move_STOP:
    HIGH xm_rcv
    PAUSE 1                                            ' Turn on 485 transmitter; wait briefly.
    SEROUT serIO,baud,[$FF,$02,$00,$00,$00,$00,$02]    ' Id
    LOW xm_rcv                                         ' Switch to receive mode.
    DEBUG "Stop", CR
    GOTO main
    


    Here is the schematic
    Stamp to PTZ Camera via RS-485.bmp

    falcon
  • NWCCTVNWCCTV Posts: 3,629
    edited 2012-09-01 18:54
    Great job. I never thought about doing it this way. I acquired a bunch of Pelco Spectra II, Spectra III and Spectra minis from an area Casino that recently shut down. I also got the Coaxitron Matrix system for controlling the PTZ of the Pelco cameras without additional wires. The thing is huge and I really do not want to use it. This may be the way to go for a future idea I have. I was happy just to get the PTZ functions to work via just the serial port using RX/TX of the camera. No converter was needed. RS-485 is basically just two wires. I connected the RX/TX, added the Com port for PTZ in my software, (Video Insight) and it picked it up and ran perfectly. I am still trying to figure out why everyone says you need an RS-232 to RS-485 converter.
  • FalconFalcon Posts: 191
    edited 2012-09-10 17:16
    Now on to the next step...

    To recap, I have a project where I am using a BS2 to control a Pelco-D PTZ camera. The camera requires RS-485 input. I have this working using an SN75176 BUS Transceiver chip (Thankyou Stamptrol) with the help of a Parallax AppKit.

    Signal chain: The BS2 interfaces with the SN75176. The SN75176 converts the BS2 TTL-level output to RS-485. The RS-485 drives the Pelco_D Camera. This much works fine.

    I now want to use two XBee transceivers to make this wireless. Should the XBees be placed between the BS2 and the SN75176 (to transmit TTL-level), or between the SN75176 and the Camera (to transmit RS-485)?


    See this attachment: Stamp to PTZ Camera via RS-485.bmp

    Are there any specific XBee settings that need to be configured for either of these options? Or will the XBee just transmit whatever pulsetrain it receives?



    Any and all comments are welcome.

    falcon
  • SapphireSapphire Posts: 496
    edited 2012-09-10 18:56
    Falcon,

    The SN75176 will have to go after the Xbee receiver, to convert the single-ended output to a differential signal that the Pelco is expecting. RS485 is not protocol specific, it is merely an electrical specification for transmitting data over a twisted pair.

    BS2 ---> Xbee ~~~~ Xbee ---> SN75176 ===> Pelco
  • FalconFalcon Posts: 191
    edited 2012-09-11 04:47
    Sapphire,

    That makes sense.
    That being said, on th BS2, P0 is the Driver enable pin to the SN 75176 and P1 is the SEROUT data. I suppose I would then feed the P1 (SEROUT) to the XBee DIN pin? Would the BS2 P0 (Enable) then be connected to any Digital I/O pin on the XBee?

    I've been pouring over the XBee tutorial but do not see an example of a continuous stream of multiple BYTE data being sent between two XBee's.

    falcon
  • SapphireSapphire Posts: 496
    edited 2012-09-11 16:28
    Falcon,

    You'll have to hard wire the DE pin on the SN75176 to be in transmit mode so when data comes across the RF link, it goes out on the twisted-wire pair. I don't think you need to connect it through the Xbee, but since I've never done that I could be mistaken. The Parallax documentation says you can operate the Xbee as a simple point-to-point serial link, which seems to fit your application.
Sign In or Register to comment.