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.
- Host: GitHub
- URL: https://github.com/zookzook/rfm12
- Owner: zookzook
- Created: 2013-02-08T16:54:09.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2013-02-08T17:43:10.000Z (over 12 years ago)
- Last Synced: 2025-01-28T03:42:37.419Z (4 months ago)
- Language: C++
- Size: 125 KB
- Stars: 3
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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 formatThe 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 looprf12mListen()
. 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 callingrfm12_canSend()
.
If it returns true then you have to send your package withrfm12_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 callingrf12mListen()
we turn on the reveiver, if it is possible. CallidReceived()
to check if the RFM12 did receive a message. The message will be written the bufferrf12Buffer
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 callingdidProcess()
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.