View Full Version : Wireless controls

11-01-2009, 03:57 AM
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?

Casey Gross
11-01-2009, 04:01 AM
can you provide an example RX and TX code? i can edit the code for you.

Mike Green
11-01-2009, 04:21 AM
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:


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.

11-01-2009, 04:38 AM
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

11-01-2009, 09:41 AM
I guess mostly what I am asking is, Is there a way to send any array over serout and use it after serin?

Mike Green
11-01-2009, 10:04 AM
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.

11-02-2009, 02:22 AM
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 Green
11-02-2009, 04:07 AM
Here's an example using an array of 3 bytes

SEROUT <pin>,<Baud>,[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>,[STR arrayName.lowByte\6]

The corresponding SERIN would look much the same.

11-02-2009, 04:50 AM
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

11-02-2009, 05:01 AM
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 Green
11-02-2009, 05:02 AM
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.

11-02-2009, 05:23 AM
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 Green
11-02-2009, 05:31 AM
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.

11-02-2009, 05:44 AM
Thanks for all of your help :) . I think I will order these new pieces asap. I'll try not to bug yall with my ridiculous questions unless I am stuck.

11-02-2009, 09:41 AM
Ah one more question for now. Might be obvious but does the BS2 support Serial Peripheral Interface commands?

Mike Green
11-02-2009, 10:01 AM
Yes. The SHIFTOUT and SHIFTIN statements handle the clock and data lines. Chip select is handled by the LOW and HIGH statements.

11-02-2009, 10:59 AM
Thanks again :)