===== RFM12B library | LowPowerLab ===== [[https://lowpowerlab.com/2012/12/28/rfm12b-arduino-library/|Originalartikel]] [[https://www.qgelm.de/wb2html/wb158.html|Backup]]
I’ve been using the RF12 library from Jeelabs for some time for my Moteino testing. This worked just fine and it was a great starting point. However some things were really confusing and I spent a lot of time redoing the same thing over and over again (eg. copy paste from known working code) just because there was a lot of code-overhead to do simple things like sending, receiving, and ACK management, and of course I couldn’t remember any of the functions or macros. Right from start, the need emerged to tweak it into a more flexible and more configurable library, so I kept hacking and modding it until it dawned on me… a new library had to be born. So I decided to completely rewrite it, and wrap the useful functionality in a dedicated C++ class. I modified some of the core features of the Jeelabs version, like adding another header byte to allow 7-bit source and destination addresses (Jeelabs only supports either source or destination in an attempt to save 1 byte), and allow low level configuration of the radio. This yielded a clean and easy to use, yet powerful library (at least it made my life easy). Here’s a summary:
I did some basic testing of the most common features. I’m posting this in hope that others will find it useful, start using it and provide some feedback. This code is also part of an effort to promote the Moteino wireless arduino clone and make it an ubiquitous platform for building very low cost internet of things.
Here is the packet structure for those interested:
The CTL bit in the first header byte is set to 1 when the received packet represents an ACK. The ACK bit in the second header byte is set to 1 when a sender is requesting an ACK to the current packet. NOTE: these bits are mutually exclusive (only either one can be set at one time), and an ACK packet can contain as much data as a normal packet – this would be useful in instances where the sent data is sent back with an ACK to be verified (even though the CRC check of each message will be an almost 100% guarantee of data integrity).
Here are diagrams for connecting the RFM12B transceiver radio to 3.3V or 5V Arduino clones nased on ATMega168/328:
