Shop OBEX P1 Docs P2 Docs Learn Events
Wireless controls — Parallax Forums

Wireless controls

limliklimlik Posts: 23
edited 2009-11-02 03:59 in BASIC Stamp
What would be the most efficient way to transmit data through serial out put. I am sending data through the serial out and serial in command. I need to send 3 numbers. The issue is that the receiving end needs to be able to know which number is which and not accept any interference, maybe through a handshake type thing with each of the 3 outputs. All of this needs to flow through one connection. Any ideas?

Comments

  • Casey GrossCasey Gross Posts: 14
    edited 2009-10-31 22:01
    can you provide an example RX and TX code? i can edit the code for you.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-31 22:21
    How about using a unique punctuation character for each number? You could use an upper case letter to identify each number and end the number with a comma like:

    A5,B234,C0,

    Other characters would be ignored at the receiving end, so you could add returns or other identification information.

    For error checking, the receiving end could echo back the received value after the comma was received (with the unique prefix). The transmitting end would retransmit a value incorrectly received until it was received correctly.
  • limliklimlik Posts: 23
    edited 2009-10-31 22:38
    I forgot to add in a few details. The communication is one way, and #1 and #2 control a boe-bot type bot's steering and #3 controls whether a servo is turned or not

    Post Edited (limlik) : 10/31/2009 10:43:21 PM GMT
  • limliklimlik Posts: 23
    edited 2009-11-01 02:41
    I guess mostly what I am asking is, Is there a way to send any array over serout and use it after serin?
  • Mike GreenMike Green Posts: 23,101
    edited 2009-11-01 03:04
    Sure. Read the chapters in the Stamp Syntax and Reference Manual on SEROUT and SERIN. They have examples for sending byte arrays (strings). Also look at the section on aliases since the STR formatter in both SEROUT and SERIN deals with byte arrays, but you can redefine an array of words as an array of bytes and use the alternate name for the STR formatter. The same information should be in the help files of the Stamp Editor.
  • limliklimlik Posts: 23
    edited 2009-11-01 19:22
    I am feeling particularly slow today... Can you give me a short example of SEROUT: sending an array with 650, 850, 1 and SERIN recieving and splitting.

    Post Edited (limlik) : 11/1/2009 7:34:21 PM GMT
  • Mike GreenMike Green Posts: 23,101
    edited 2009-11-01 21:07
    Here's an example using an array of 3 bytes

    SEROUT <pin>,<Baud>,[noparse][[/noparse]STR arrayName\3]

    If they're all 16-bit words, you would need to send them one byte at a time like:

    SEROUT <pin>,<Baud>,[noparse][[/noparse]STR arrayName.lowByte\6]

    The corresponding SERIN would look much the same.
  • limliklimlik Posts: 23
    edited 2009-11-01 21:50
    Would this method be able to send the data efficiently enough to control the servos in a quick and responsive way? If not what would be a good way to send each number and have the receiving end know which is which using serial commands?

    Post Edited (limlik) : 11/1/2009 10:06:06 PM GMT
  • FranklinFranklin Posts: 4,747
    edited 2009-11-01 22:01
    limlik said...
    Would this method be able to send the data efficiently enough to control the servos in a quick and responsive way?
    Define quick and responsive. You can test this by connecting your two devices with wires while testing.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • Mike GreenMike Green Posts: 23,101
    edited 2009-11-01 22:02
    The answer is "probably". The issue is that the Stamp can only do one thing at a time. It can receive serial information or it can generate a servo control pulse, but not both. Fortunately, servos only need a control pulse about 50 times a second. If your sending Stamp or PC can send the needed information in a few milliseconds, the receiving Stamp can still produce a control pulse within the 20ms or so needed. If the sender bogs down and misses an opportunity to send, the receiver will miss producing a servo control pulse and the servo will begin to stutter.

    If you write your code so the sender sends a packet of information (one set of values) every 10-15ms and the data gets sent at 9600 Baud (about one byte every ms), then the receiver should be able to put out a servo control pulse and be ready for the next set of information once every 20ms or so.
  • limliklimlik Posts: 23
    edited 2009-11-01 22:23
    The project I am working on is a contest bot. I am trying to build a controller for it to be light weight (Weight factors into scoring heavily). The wireless I am using is now looking like it may be way to slow for this project. It works at a max of 4800 bps. http://www.sparkfun.com/commerce/product_info.php?products_id=8947 I had these on hand so I figured I would use them, I had forgotten the low baud rate on them. I will upgrade to a set of http://www.sparkfun.com/commerce/product_info.php?products_id=691

    Post Edited (limlik) : 11/1/2009 10:32:15 PM GMT
  • Mike GreenMike Green Posts: 23,101
    edited 2009-11-01 22:31
    4800 Baud would be marginal. A ServoPAL would be helpful since that would take over the job of issuing servo control pulses every 20ms and the Stamp could be concerned just with receiving new data from the wireless link and massaging it to generate a new control pulse when something changes. Look at the ServoPAL documentation.
  • limliklimlik Posts: 23
    edited 2009-11-01 22:44
    Thanks for all of your help [noparse]:)[/noparse] . I think I will order these new pieces asap. I'll try not to bug yall with my ridiculous questions unless I am stuck.
  • limliklimlik Posts: 23
    edited 2009-11-02 02:41
    Ah one more question for now. Might be obvious but does the BS2 support Serial Peripheral Interface commands?
  • Mike GreenMike Green Posts: 23,101
    edited 2009-11-02 03:01
    Yes. The SHIFTOUT and SHIFTIN statements handle the clock and data lines. Chip select is handled by the LOW and HIGH statements.
  • limliklimlik Posts: 23
    edited 2009-11-02 03:59
    Thanks again [noparse]:)[/noparse]
Sign In or Register to comment.