This is a Manchester encoding RF library which works on Arduino and ATTiny.
Library supports:
workspace_root/libraries/Manchester
#include <Manchester.h>
For sending data
void setup() { man.setupTransmit(TX_PIN, MAN_1200); }
For receiving data
void setup() { man.setupReceive(RX_PIN, MAN_1200); man.beginReceive(); }
For sending data
void loop() { man.transmit(transmit_data); }
For receiving data
void loop() { if (man.receiveComplete()) { uint16_t m = man.getMessage(); man.beginReceive(); //start listening for next message right after you retrieve the message //do something with your message here } }
This is broadly the same as on Arduino with one extra step. You need to download the ATtiny hardware files (a list of alternative ATtiny implementations is listed on this site which is where I got the files in tiny.zip). These should be unzipped into the following location.
workspace_root/hardware/tiny
As of now (June 2013) most of tiny cores does not support micro delay at 1Mhz and for that reason if you want to TRANSMIT (receive is OK) from your 1Mhz ATtiny85/84 you need to call this method before you call transmit setup:
man.workAround1MhzTinyCore(); //add this in order for transmitter to work with 1Mhz Attiny85/84 man.setupTransmit(TX_PIN, MAN_1200);
The library has been tested with common 315Mhz and 433Mhz transmitters using ASK OOK. Tips to improve your transmit distance: Attaching an antenna will greatly improve transmit distance (from few cm to few m) for 315Mhz use 23.81 cm straight wire, for 433Mhz use 17.28cm straight wire as antenna. If possible keep the wire straight, away from ground wire, and away from the rest of the circuit and battery pack. Transmitter can use anything from 3.3V to 12V. Increasing voltage will increase transmit distance. If you are using voltage regulator, attach transmitter directly to the battery. Receiver needs 5V, it doesn't work on 3.3V
Speed: I was able to achieve 9600 bauds between two 16Mhz Arduinos, or 2400 bauds between two 1Mhz ATTiny85, you can try different speeds to see which works the best for you.
Full duplex: for bidirectional communication use both 315Mhz and 433Mhz transmitters. This way they can transmit at the same time without interfering with each other. If you have just one type, wait for receiver to finish receiving before transmitting.
I used this library in a series of blog posts where I put together a battery powered temperature sensor: