5
\$\begingroup\$

I have bought a pair of simple 315MHz TX/RX modules. I want to use these to connect a battery powered ATTiny85 to an Arduino base station. The ATTiny needs to regularly wake up and send a sensor reading to the base station.

In theory I should be able to simply write data to the TX and read it from the RX module. However, how do I ensure that I write/read at the correct rate? What code do I need to use to transmit at a particular speed (bytes/second)? What is the best way of doing error correction/detection?

Since I want the transmitter to be battery powered could I use a transistor to turn off VCC to the TX module when idle. What will the RX module receive when the TX module is powered down?

\$\endgroup\$
10
\$\begingroup\$

Those modules basically make the receiver pin wiggle in response to how you drive the transmitter pin. They know nothing about what you think wiggling the pin means, and don't contain a UART. More details weren't immediately obvious without digging. That's your job, so I didn't bother to go further. You should provide a link to the datasheet, not the product splash page.

These modules work on AM modulation. The short writeup says ASK, but it's probably just on/off keying of the transmitter (which is technically a subset of ASK). The problem with this scheme is that the receiver can't inherently know the level for when the transmitter is on. It therefore most likely looks at recent received signal strengths and picks a value in the middle to decide between on and off. This is called data slicing.

If you are not regularly transmitting ons and offs, the receiver looses track of what levels on and off are, and can no longer data slice correctly. This is usually dealt with in two ways. First, a preamble is sent. This contains a bunch of ons and offs in rapid succession so that the receiver can settle on a good data slicer threshold. It is expected that some or all of these bits are not correctly interpreted by the receiver, so are therefore not really "received". The second strategy is to send data so that there is always a recent on and off for the receiver to refer to. Some receivers, particularly cheap ones that do the data slicing in analog, just slice about the low pass filtered average received signal strength. For such receivers, you not only need to vary between on and off frequently, but the average needs to be close to 1/2 on.

This is why manchester encoding is so popular for such RF links. I won't go into manchester encoding here since this is well known and you will have no problem finding lots of information on it out there. One nice feature of manchester code is that it averages to 1/2 on over each bit. A bit is divided into two halves. On-off may mean 1 and off-on 0. Manchester is probably the best easiest to do encoding scheme.

You can use a UART, but you have to be careful and you will give up some bandwidth (battery power). Look at what a UART will transmit. If you send the characters immediately following each other, then each one will take 10 bit times. There will be a start bit, 8 data bits, and a stop bit. The start and stop bit are always opposite polarity. You can arrange to use codes in the remaining 8 bits that have a equal number of 0s and 1s to keep the data slicer threshold in the middle. This means you only get to send 4 bits of information in each UART character. You'll also have to think about the preamble carefully.

In general, you should assume any one RF transmission has a significant chance of bit errors. This means some kind of checksum is a good idea. You can send data in packets, and include something like a 16 or 20 bit CRC checksum with each packet. If the packet is not received intact, then it is discarded like it never happened.

The system also has to deal with the random noise received when the transmitter is powered down. In that case the receiver threshold will drop and it will start data slicing whatever random noise it picks up. With a properly designed preamble and checksum, you can make the chance of random noise looking like valid data vanishingly small.

\$\endgroup\$
  • \$\begingroup\$ Thanks for the excellent answer. Are there any existing code samples which do all of this? It sounds like most/all of this is stuff which anyone who uses these modules will have to solve - surely I'm not the first. \$\endgroup\$ – mchr Dec 31 '11 at 18:45
  • 1
    \$\begingroup\$ I've done manchester encoding and decoding a number of times, but each had its own wrinkles and is therefore embedded in customer code I'm not going to give out. Look around. It's quite possible someone had done this and posted code. Keep in mind, however, that those that think this is a big enough deal to post code are not the ones whos code you want. Sometimes you find some good stuff out there though. Like I said, look around. \$\endgroup\$ – Olin Lathrop Dec 31 '11 at 21:12
  • \$\begingroup\$ I have generally found that when I find code like that, it has so many issues that takes so long to debug that I would have just been better off writing my own. \$\endgroup\$ – Kellenjb Jan 1 '12 at 18:56
  • \$\begingroup\$ @Kellenjb: I agree. I don't even look around for others' code. At best is doesn't suck, and that's rare, but integrating it into my project is difficult and error-prone if it wasn't written to my developement environment in the first place. I mention to look around only because it seems other people don't feel this way. \$\endgroup\$ – Olin Lathrop Jan 1 '12 at 19:15
  • \$\begingroup\$ @mchr I haven't personally used it yet so can't speak to the reliability, but I've seen the VirtualWire (note that's a PDF unfortunately) library mentioned a bit in discussions of this type of modules combined with Arduinos. It seems it was written specifically for them. \$\endgroup\$ – Jeremy M Jan 2 '12 at 2:59
2
\$\begingroup\$

I have ended up using a Manchester encoding library. The latest version of this library has now been published here: https://github.com/mchr3k/arduino-libs-manchester

Details about my use of this library can be seen here: http://mchr3k-arduino.blogspot.com/

\$\endgroup\$
1
\$\begingroup\$

This question is directly addressed by the Wicked Node / Wicked Receiver Shield products that I make (disclosure) at Wicked Device. Please check them out. They constitute a low cost one-way ASK radio link on 433MHz to get up to four analog sensor readings (per Wicked Node) wirelessly to your Arduino at prescribed intervals. I used an ATTiny24A rather than an ATTiny85 primarily for the extra Analog inputs. The software uses sleep modes extensively and the Wicked Node is designed to operate from a 9V battery for several months.

\$\endgroup\$
0
\$\begingroup\$

I'd recommend looking at VirtualWire library, which implements RF transmission for ISM range transmitter/receiver pairs with ASK output. See http://www.open.com.au/mikem/arduino/. I've successfully used it to collect data from wireless sensors spread around my house.

\$\endgroup\$
  • \$\begingroup\$ Unfortunately the VirtualWire library does not support the ATTiny85. \$\endgroup\$ – mchr Jan 9 '12 at 13:27
0
\$\begingroup\$

Depending on how much interoperability with existing devices you want, but if you want a lot, http://www.dealextreme.com/p/wireless-bluetooth-rs232-ttl-transceiver-module-80711 might be worth looking into. It's just a very cheap Bluetooth serial link and just about any computer with bluetooth could read it. Bluetooth also has excellent performance (relatively) even in environments with very noisy 2.4GHz comms.

\$\endgroup\$
  • \$\begingroup\$ Thanks for the link - that's a very cheap bluetooth module! \$\endgroup\$ – mchr Feb 1 '12 at 16:32
0
\$\begingroup\$

Take a look here:

https://www.sparkfun.com/datasheets/RF/KLP_Walkthrough.pdf

Most of the answers you are seeking at in the document.

\$\endgroup\$
  • \$\begingroup\$ Can you add a few more details from the link to your answer? Link-only answers are discouraged because they become useless if the link dies in the future. \$\endgroup\$ – PeterJ Nov 30 '14 at 8:03
0
\$\begingroup\$

Though the original poster already found a solution. I will just add some info for people who end up here. There are basically 2 established ways to send wireless data between arduino's/Attiny's: VirtualWire and Manchester. Both have libraries available. Virtualwire I understand only can send characters (though there is a work around), Manchester can send numbers. In using the manchester library, make sure you have the latest one. Both VirtualWire and manchester can be put in an Attiny. With regard to switching the Transmitter on or Off to save battery use, I suggest you put the Attiny to sleep and when it wakes up, have it switch on the powersupply of the transmitter through a transistor (attiny pin to base, make high etc). There is an example (probably more than one) in instructables: http://www.instructables.com/id/Attiny85-RF-Transmitter-to-Arduino-Uno-Receiver-Ma/?comments=all#CWNVMX4I6RT1A1N

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.