First off, your serial input/output code won't work as it's set up. I use that particular pair of transmitter/receivers a lot, I know a bit about them. All you'll get at the output is a bunch of noise.
Do a search on "manchester encoding" for use with this type of Tx/Rx pair.
Basically what has to happen is this:
You have to 'train' the receiver to 'know' what the difference between a '1' and a '0' is.
You do this by sending a 'preamble' of 0's and 1's, a few milliseconds of each. This charges up a capacitor to 1/2 the voltage needed to detect if the input is actually a '1' or a '0'. This is actually what's called a 'data slicer'.
After the preamble is sent, you can start sending data.
The problem is, if the data you send has too many '1's or '0's, the capacitor in the 'data slicer' will either charge up all the way to the '1' trip-point or the '0' trip-point and pretty soon all your data is either '1's or '0's.
The trick is to try and send an equal number of '1's and '0's. The closer you are to an equal number of each, the better the quality of the data sent.
So, what you do is, you break apart your input byte into individual '1's and '0's, a binary '0' becomes a '01' and a binary '1' becomes a '10'. This has a side effect of doubling the amount of data you have to send, no biggie. If you only need 4 codes (actually this single byte method works up to 16 individual codes), you can just use a look up table.
For instance:
To send a binary 0000, send 01010101, ($55)
To send a binary 1010, send 10011001, ($99)
Relatively easily done. You can do it in a loop, parsing every bit out at both the Tx and Rx end, or just use bytes that have an equal number of '1's and '0's, but no more than 2 '1's or '0's in a row.
0 = 0000 = 0101 0101
1 = 0001 = 0101 0110
2 = 0010 = 0101 1001
3 = 0011 = 0101 1010
4 = 0100 = 0110 0101
5 = 0101 = 0110 0110
6 = 0110 = 0110 1001
7 = 0111 = 0110 1010
...and so on...
BTW = a good preamble sequence is a bunch of $55 and $AA back to back for about 5ms with the TWS-434/RWS-434 pair.
Have fun...break something...or make it work...
JDG
Bookmarks