An open API service indexing awesome lists of open source software.

https://github.com/zookzook/rfm12

An Arduino implementation for using the RFM12 transceiver from Hoperf.
https://github.com/zookzook/rfm12

Last synced: about 2 months ago
JSON representation

An Arduino implementation for using the RFM12 transceiver from Hoperf.

Awesome Lists containing this project

README

        

RFM12
=====

An Arduino implementation for using the RFM12 transceiver from Hoperf. This implementation uses
the same message format as the JeeNodes:

* header, which contains the node id
* length, the length of the message
* data, the data of the message
* crc, the crc in little-endian format

The code uses a finite state machine which organizes the operation mode of the RFM12. You can
receive, send messages or power down the RFM12. After initialization the fsm is idle. You can transmit
or receive a message. Therefore to change the operation mode the fsm must be idle. While sending you
are not able to receive a message. Since you have to wait for a message, you call in a loop
rf12mListen(). This switch on the receiver.

# Sending a message

First initialize the RFM12 data structure and the RFM12 itself. In europe use RF12_868MHZ. The
example use node id 2 and group 200. After that check if sending is possible by calling rfm12_canSend().
If it returns true then you have to send your package with rfm12_send().



#include "rfm12.h"

typedef struct {
uint16_t temp;
uint8_t counter;
} Payload;

Payload payload;

void setup() { rfm12_setup( 2, RF12_868MHZ, 200 ); }

void loop() {
if( rfm12_canSend() ) {
payload.temp= 20.10;
payload.counter= 1;
rfm12_send( &payload, sizeof payload );
}
...
}

# Receiving a message

To receive the message that we sent before. We initializes the RFM12 with node id 1 and group 200.
By calling rf12mListen() we turn on the reveiver, if it is possible. Call idReceived()
to check if the RFM12 did receive a message. The message will be written the buffer rf12Buffer which
is also used for sending. After receiving the message you should process the message in the buffer. While
processing the buffer won't be overwritten by the next message. By calling didProcess() the state
of the fsm (finite state machine) will be changed to be idle. Now you can receive the next message or
answer by sending a message.



#include "rf12m.h"

typedef struct {
uint16_t temp;
uint8_t counter;
} Payload;

void setup () { rf12m_init( 1, RF12_868MHZ, 200 ); }

void loop () {

rf12mListen();

if (didReceive() ) {
Payload* p= (Payload*)&rf12Buffer[ 2 ];
Serial.print( p->counter );
Serial.print( ". Temperature:" );
Serial.println( (float)p->temp / 100.0 );
didProcess();
}
}

# Just code

This is not a library. It is just some code that you can grab and modify it for your needs.
Out of the box it supports Attiny84 and ATMega328. For using other microcontroller just change the
pins and interrupt handlers. If you use ATMega328 you can use the debug mode #define RFM12_DEBUG 1 that puts some strings on the serial usb.