How to make RFM69 work on Photon? [SOLVED - new library RFM69-Particle]


#1

Hi,

I’m trying to get the RFM69 existing library to work with Photon. The same code works on an Arduino Pro Mini but on the Photon while it compiles without error, it never reports receiving any radio message.

First off, can someone please confirm the correct wiring diagram for connecting an RFM69W/CW/HCW device to a Photon? I’ve created my own mapping based on the Photon datasheet and listed it as such:

/*
Photon SPI mapping from https://docs.particle.io/reference/firmware/photon/#spi

    Photon      Arduino	    RFM69	
    GND         GND	    GND	    
    3V3         3.3V	    VCC	   
    A2          10	    NSS	    
    A3          13	    SCK	    
    A5          11	    MOSI	
    A4          12	    MISO	
    D2          2	    DI00	
                            ANA	    Antenna
    D9                      RST                        
*/

Here is the full RX Photon node code (the TX node runs on an Arduino):

 // This #include statement was automatically added by the Particle IDE.
#include "RFM69/RFM69.h"

// SEE ORIGINAL LICENSE AND AUTHOR INFORMATION AT END OF MAIN LOOP

//*********************************************************************************************
// *********** IMPORTANT SETTINGS - YOU MUST CHANGE/ONFIGURE TO FIT YOUR HARDWARE *************
//*********************************************************************************************
//below was tested both as int16_t and #define with no difference in making it work
int16_t NETWORKID = 100;  //the same on all nodes that talk to each other
int16_t NODEID = 1;  

//Match frequency to the hardware version of the radio on your Feather
//#define FREQUENCY     RF69_433MHZ
//#define FREQUENCY     RF69_868MHZ
#define FREQUENCY      RF69_915MHZ
#define ENCRYPTKEY     "sampleEncryptKey" //exactly the same 16 characters/bytes on all nodes!
#define IS_RFM69HCW    true // set to 'true' if you are using an RFM69HCW module

//*********************************************************************************************

#define RFM69_CS      A2 //tried A3 no difference //Arduino 10
#define RFM69_IRQ     2
#define RFM69_IRQN    0  // Pin 2 is IRQ 0!
#define RFM69_RST     9

int16_t packetnum = 0;  // packet counter, we increment per xmission

//RFM69 radio = RFM69(RFM69_CS, RFM69_IRQ, IS_RFM69HCW, RFM69_IRQN);
RFM69 radio; //tried above statement also no difference in making it work

//*********************************************************************************************
// ***********                          Wiring the RFM69 Radio                   *************
//*********************************************************************************************
/*
Photon SPI mapping from https://docs.particle.io/reference/firmware/photon/#spi 

    Photon      Arduino	    RFM69	Color
    GND         GND	        GND	    Black
    3V3         3.3V	    VCC	    Red
    A2          10	        NSS	    Yellow
    A3          13	        SCK	    Green
    A5          11	        MOSI	Blue
    A4          12	        MISO	Violet
    D2          2	        DI00	Gray
                            ANA	    Antenna
    D9                      RST                        
*/


void setup() 
{
    
    Serial.begin(115200); // Open serial monitor at 115200 baud to see ping results.
    
    pinMode(D7, OUTPUT);

    Particle.publish("Startup setup","Completed",360,PRIVATE);
  
  Serial.println("RFM69HCW Receiver");
  
// Initialize radio
  radio.initialize(FREQUENCY,NODEID,NETWORKID);
  if (IS_RFM69HCW) {
    radio.setHighPower();    // Only for RFM69HCW & HW!
  }
  
  radio.setPowerLevel(10); // power output ranges from 0 (5dBm) to 31 (20dBm)
    
  radio.encrypt(ENCRYPTKEY);
  
  Serial.print("\nListening at ");
  Serial.print(FREQUENCY==RF69_433MHZ ? 433 : FREQUENCY==RF69_868MHZ ? 868 : 915);
  Serial.println(" MHz");
}


//=========================MAIN LOOP===========================================
void loop() {

Serial.print(".");

  //check if something was received (could be an interrupt from the radio)
  if (radio.receiveDone())
  {
    //print message received to serial
    Serial.println(" "); //if received the ..... will new line
    Serial.print('[');Serial.print(radio.SENDERID);Serial.print("] ");
    Serial.print((char*)radio.DATA);
    Serial.print("   [RX_RSSI:");Serial.print(radio.RSSI);Serial.print("]");

    //check if received message contains Hello World
    if (strstr((char *)radio.DATA, "Hello World"))
    {
      //check if sender wanted an ACK
      if (radio.ACKRequested())
      {
        radio.sendACK();
        Serial.println(" - ACK sent");
      }
      else {Serial.println(" - No ACK sent");}
    }  
  }

  radio.receiveDone(); //put radio in RX mode
  
  delay(1000);


} //end loop
//END OF MAIN LOOP!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


/* RFM69 library and code by Felix Rusu - felix@lowpowerlab.com
// Get libraries at: https://github.com/LowPowerLab/
// Make sure you adjust the settings in the configuration section below !!!
// **********************************************************************************
// Copyright Felix Rusu, LowPowerLab.com
// Library and code by Felix Rusu - felix@lowpowerlab.com
// **********************************************************************************
// License
// **********************************************************************************
// This program is free software; you can redistribute it 
// and/or modify it under the terms of the GNU General    
// Public License as published by the Free Software       
// Foundation; either version 3 of the License, or        
// (at your option) any later version.                    
//                                                        
// This program is distributed in the hope that it will   
// be useful, but WITHOUT ANY WARRANTY; without even the  
// implied warranty of MERCHANTABILITY or FITNESS FOR A   
// PARTICULAR PURPOSE. See the GNU General Public        
// License for more details.                              
//                                                        
// You should have received a copy of the GNU General    
// Public License along with this program.
// If not, see <http://www.gnu.org/licenses></http:>.
//                                                        
// Licence can be viewed at                               
// http://www.gnu.org/licenses/gpl-3.0.txt
//
// Please maintain this license information along with authorship
// and copyright notices in any redistribution of this code
// **********************************************************************************/

Please help with promini/rfm69/photon gateway
Electron does not respond to Radiohead test sketch
#2

@bloukingfisher, the Photon has no D9 pin (connected to RST on RFM69). Is that a typo?

This portion of the code needs fixing:

#define RFM69_CS      A2 //tried A3 no difference //Arduino 10
#define RFM69_IRQ     2
#define RFM69_IRQN    0  // Pin 2 is IRQ 0!
#define RFM69_RST     9

You need to specify a valid pin for RFM69_RST like D6 for example. What is pin DI00 on the RFM69 module? Are you using IRQ or IRQN along with interrupts?


#3

Yes, that would be wrong. I’m not using the RST pin on the radio and I’m not using interrupts (but kept it in from the Arduino code).

So yes, RST if used can be connected to D6. I’m not really sure how any of the GPIO pins on the RF69 are used. In the Arduino the DI00 was connected to pin 2 which was defined as IRQ.


#4

@bloukingfisher, the way Arduino maps interrupts is different than the Photon. I’ll need to look at the library to see if it needs porting.


#5

Thanks @peekay123 for taking a look!

Reference to the Pin out use on arduino and this library/RFM69.

Revised code, connecting D6 to DI00 for IRQ potential use; D5 to RST for potential use. Initiating radio with custom pin outs (not receiving radio transmissions):

// This #include statement was automatically added by the Particle IDE.
#include "RFM69/RFM69.h"

// SEE ORIGINAL LICENSE AND AUTHOR INFORMATION AT END OF MAIN LOOP

//*********************************************************************************************
// *********** IMPORTANT SETTINGS - YOU MUST CHANGE/CONFIGURE TO FIT YOUR HARDWARE *************
//*********************************************************************************************
//below was tested both as int16_t and #define with no difference in making it work
int16_t NETWORKID = 100;  //the same on all nodes that talk to each other
int16_t NODEID = 1;  

//Match frequency to the hardware version of the radio on your Feather
//#define FREQUENCY     RF69_433MHZ
//#define FREQUENCY     RF69_868MHZ
#define FREQUENCY      RF69_915MHZ
#define ENCRYPTKEY     "sampleEncryptKey" //exactly the same 16 characters/bytes on all nodes!
#define IS_RFM69HCW    true // set to 'true' if you are using an RFM69HCW module

//*********************************************************************************************

#define RFM69_CS      A2 //tried A3 no difference //Arduino 10
#define RFM69_IRQ     D6
#define RFM69_IRQN    0  // Pin 2 is IRQ 0!
#define RFM69_RST     D5

int16_t packetnum = 0;  // packet counter, we increment per xmission

RFM69 radio = RFM69(RFM69_CS, RFM69_IRQ, IS_RFM69HCW, RFM69_IRQN);
//RFM69 radio; //tried above statement also no difference in making it work

//*********************************************************************************************
// ***********                          Wiring the RFM69 Radio                   *************
//*********************************************************************************************
/*
Photon SPI mapping from https://docs.particle.io/reference/firmware/photon/#spi 

    Photon      Arduino	    RFM69	Color
    GND         GND	        GND	    Black
    3V3         3.3V	    VCC	    Red
    A2          10	        NSS	    Yellow
    A3          13	        SCK	    Green
    A5          11	        MOSI	Blue
    A4          12	        MISO	Violet
    D6          2	        DI00	Gray
                            ANA	    Antenna
    D5                      RST                        
*/


void setup() 
{
    
    Serial.begin(115200); // Open serial monitor at 115200 baud to see ping results.
    
    pinMode(D7, OUTPUT);

    Particle.publish("Startup setup","Completed",360,PRIVATE);
  
  Serial.println("RFM69HCW Receiver");
  
// Initialize radio
  radio.initialize(FREQUENCY,NODEID,NETWORKID);
  if (IS_RFM69HCW) {
    radio.setHighPower();    // Only for RFM69HCW & HW!
  }
  
  radio.setPowerLevel(10); // power output ranges from 0 (5dBm) to 31 (20dBm)
    
  radio.encrypt(ENCRYPTKEY);
  
  Serial.print("\nListening at ");
  Serial.print(FREQUENCY==RF69_433MHZ ? 433 : FREQUENCY==RF69_868MHZ ? 868 : 915);
  Serial.println(" MHz");
}


//=========================MAIN LOOP===========================================
void loop() {

Serial.print(".");

  //check if something was received (could be an interrupt from the radio)
  if (radio.receiveDone())
  {
    //print message received to serial
    Serial.println(" "); //if received the ..... will new line
    Serial.print('[');Serial.print(radio.SENDERID);Serial.print("] ");
    Serial.print((char*)radio.DATA);
    Serial.print("   [RX_RSSI:");Serial.print(radio.RSSI);Serial.print("]");

    //check if received message contains Hello World
    if (strstr((char *)radio.DATA, "Hello World"))
    {
      //check if sender wanted an ACK
      if (radio.ACKRequested())
      {
        radio.sendACK();
        Serial.println(" - ACK sent");
      }
      else {Serial.println(" - No ACK sent");}
    }  
  }

  radio.receiveDone(); //put radio in RX mode
  
  delay(1000);


} //end loop
//END OF MAIN LOOP!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


/* RFM69 library and code by Felix Rusu - felix@lowpowerlab.com
// Get libraries at: https://github.com/LowPowerLab/
// Make sure you adjust the settings in the configuration section below !!!
// **********************************************************************************
// Copyright Felix Rusu, LowPowerLab.com
// Library and code by Felix Rusu - felix@lowpowerlab.com
// **********************************************************************************
// License
// **********************************************************************************
// This program is free software; you can redistribute it 
// and/or modify it under the terms of the GNU General    
// Public License as published by the Free Software       
// Foundation; either version 3 of the License, or        
// (at your option) any later version.                    
//                                                        
// This program is distributed in the hope that it will   
// be useful, but WITHOUT ANY WARRANTY; without even the  
// implied warranty of MERCHANTABILITY or FITNESS FOR A   
// PARTICULAR PURPOSE. See the GNU General Public        
// License for more details.                              
//                                                        
// You should have received a copy of the GNU General    
// Public License along with this program.
// If not, see <http://www.gnu.org/licenses></http:>.
//                                                        
// Licence can be viewed at                               
// http://www.gnu.org/licenses/gpl-3.0.txt
//
// Please maintain this license information along with authorship
// and copyright notices in any redistribution of this code
// **********************************************************************************/

#6

This would be super cool to know but it raises questions:

  1. Would the Spread Spectrum cause unwanted interference with the hosting signal (WIFI => Photon, 3G => Electron)?

  2. FCC? I was working a project using the LoRa Feathers before and got shot down about half way the project because they lacked FCC numbers. Adding this you would have to go through that whole process and I think it costs about $5K and some time to have a lab run the tests

Imagine the capabilities with that though, You could have a whole series of radios doing their jobs and reporting that back to the Electron or Photon as a gateway to the Particle Cloud! Watching this for progress…

Cheers,


#7

@callen No inteference so far in my testing. I have used an NRF24 2.4 Ghz module that appears that it may clash with the Photon wifi occasionally (Photon Wifi doesn’t degrade, but the packet reception on the RF degrades). There may be potential ways around it in software control, channel selection, etc but it does seem like potential problems.

It’s on my mind too. The hardware claims to be ETSI and FCC compliant…but doesn’t have any module numbers etc. like Particle does. My interpretation is that they are claiming that if you run lab tests it would pass, but they have not obtained modular approval themselves.

Unfortunately I’ve not been able to find a viable low cost module that has modular approval numbers. Would love to hear if or when you find anything!


#8

@peekay123 I’ve had success. The pin-outs were correct but I couldn’t get the library to work. I’ve made some modifications, incorporated additional library files and created an example app working with the Photon. Now it is working.

Stand by…I’m working on adding it to the Web IDE libraries


#9

@bloukingfisher, try reversing the order of the “version” and “license” lines in the spark.json file.


#10

All working great now. I’ve added my RFM69-Particle library in the community library on the Web IDE and includes working example apps (works with serial and dashboard if you’re not using serial).

I’ve heard from someone else that the RFM69 library did work for them. Maybe it just wasn’t compatible with the “H” higher power hardware versions which I was testing on. Anyway, RFM69-Particle should now work with all styles of the RFM69 hardware (make changes as required in the example code for your particular device/frequency/high power).


Mimic Control Gate Garage Door remote 433 mhz ( 50 meters range )
Please help with promini/rfm69/photon gateway
#11

@bloukingfisher Thanks for adding the library to the interface!

I have 2 different versions of the RFM69 modules and have gotten a good 1 mile range out of then in suburban areas using a simple wire antenna which I think is great.

I think these low cost 2 way radios allow for some really neat long range applications to be developed which helps overcome the short range of WiFi Hotspots.

Can you share the link to where you bought the RFM69 module from that is working for you? All mine are on boards with Atmel processors already on board.


#12

I got mine from the official US distributor for $4-$5 each (arrived shipped in about 1-2 days, neat!). I’ve not yet had time to do a longer range test but certainly works way beyond WiFi range which solved something for me.

I’m also just using a simple wire dipole antenna.

PS: The exact model I’m using is the RFM69HCW but requires some soldering as the pin sizes don’t match a normal breadboard. And I don’t use it at the high power 20 dBM setting as my battery cannot source enough current for that (130 mA!). Lower power setting of 10 works awesome and requires only ~30 mA.


#13

@bloukingfisher I was actually getting the 1-mile range on the RF96 modules, sorry. Got the 69 confused with the 96 :smile:

I don’t think the libraries are compatible.


#14

Outstanding work gentleman!!! Thanks a million for the library. Soon I will get to using it.


#15

Thanks guys. This library is working great when communicating between Photons. Has anyone tried setting up a Photon with the RFM69 as a receiver and an arduino pro mini with RFM69 as a transmitter? I am trying to have them both communicate with each other and unfortunately the Photon is not able to receive any messages from the Arduino pro mini. Below are my codes for each device. Has anybody had any success with getting the Photon and Arduino to communicate with each other?

Arduino Pro Mini Code

#include <RFM69.h>
#include <RFM69_ATC.h>
#include <RFM69registers.h>
#include <SPI.h>

int16_t NETWORKID = 0;
int16_t MYNODEID = 9;
int16_t TONODEID = 3;

//#define NETWORKID     0   // Must be the same for all nodes
//#define MYNODEID      1   // My node ID
//#define TONODEID      3   // Destination node ID
#define FREQUENCY     RF69_915MHZ
//#define USEACK        true // Request ACKs or not
#define LED           6 // LED positive pin
#define GND           8 // LED ground pin
#define BTN 7


RFM69 radio;

void setup()
{
  Serial.begin(9600);
  Serial.print("Node ");
  Serial.print(MYNODEID,DEC);
  Serial.println(" ready");  

  pinMode(BTN, INPUT); 
  pinMode(GND,OUTPUT);
  digitalWrite(GND,LOW);

  radio.initialize(FREQUENCY, MYNODEID, NETWORKID);
  radio.setHighPower(); // Always use this for RFM69HCW
}

void loop()
{
  if(digitalRead(BTN) == HIGH){
    
     Serial.print("begin - pushed");
     static int sendlength = 8;
     static char sendbuffer[] = "411";
  
     Serial.print("sending to node ");
     Serial.print(TONODEID, DEC);
     Serial.print(", message [");
      for (byte i = 0; i < sendlength; i++)
      Serial.print(sendbuffer[i]);
      Serial.println("]");
  
//      if (USEACK)
//        {
//          if (radio.sendWithRetry(TONODEID, sendbuffer, sendlength))
//            Serial.println("ACK received!");
//          else
//            Serial.println("no ACK received");
//        }
//  
//        else // don't use ACK
//        {
//          radio.send(TONODEID, sendbuffer, sendlength);
//        }
        
        sendlength = 8; // reset the packet
  }
}

Photon Code

#include "RFM69-Particle/RFM69-Particle.h"
#include "RFM69-Particle/RFM69_ATC.h"
#include "RFM69-Particle/RFM69registers.h"

// Adjustments to library to work with Particle Photon including in Web IDE by Jurie Pieterse
// Forked library for Photon at https://github.com/bloukingfisher/RFM69/
// Serial NOT required to confirm working - you can watch your Particle Console logs!

/* RFM69 library and code by Felix Rusu - felix@lowpowerlab.com
// Get libraries at: https://github.com/LowPowerLab/
// Make sure you adjust the settings in the configuration section below !!!
// **********************************************************************************
// Copyright Felix Rusu, LowPowerLab.com
// Library and code by Felix Rusu - felix@lowpowerlab.com
// **********************************************************************************
// License
// **********************************************************************************
// This program is free software; you can redistribute it 
// and/or modify it under the terms of the GNU General    
// Public License as published by the Free Software       
// Foundation; either version 3 of the License, or        
// (at your option) any later version.                    
//                                                        
// This program is distributed in the hope that it will   
// be useful, but WITHOUT ANY WARRANTY; without even the  
// implied warranty of MERCHANTABILITY or FITNESS FOR A   
// PARTICULAR PURPOSE. See the GNU General Public        
// License for more details.                              
//                                                        
// You should have received a copy of the GNU General    
// Public License along with this program.
// If not, see <http://www.gnu.org/licenses></http:>.
//                                                        
// Licence can be viewed at                               
// http://www.gnu.org/licenses/gpl-3.0.txt
//
// Please maintain this license information along with authorship
// and copyright notices in any redistribution of this code
// **********************************************************************************/


//*********************************************************************************************
// *********** IMPORTANT SETTINGS - YOU MUST CHANGE/CONFIGURE TO FIT YOUR HARDWARE *************
//*********************************************************************************************
int16_t NETWORKID = 0;  //the same on all nodes that talk to each other
int16_t NODEID = 3;  

//Match frequency to the hardware version of the radio on your Feather
//#define FREQUENCY     RF69_433MHZ
//#define FREQUENCY     RF69_868MHZ
#define FREQUENCY      RF69_915MHZ
//#define ENCRYPTKEY     "sampleEncryptKey" //exactly the same 16 characters/bytes on all nodes!
#define IS_RFM69HCW    false // set to 'true' if you are using an RFM69HCW module

//*********************************************************************************************

#define RFM69_CS      A2 
#define RFM69_IRQ     2
#define RFM69_IRQN    2 //On Photon it is the same unlike Arduino
#define RFM69_RST     6

int16_t packetnum = 0;  // packet counter, we increment per xmission

RFM69 radio = RFM69(RFM69_CS, RFM69_IRQ, IS_RFM69HCW, RFM69_IRQN);  //initialize radio with potential custom pin outs; otherwise you may use for default: RFM69 radio;

//*********************************************************************************************
// ***********                  Wiring the RFM69 Radio to Photon                  *************
//*********************************************************************************************
/* Arduino wiring provided for reference, color 
    Photon      Arduino	    RFM69	Color
    GND         GND	        GND	    Black
    3V3         3.3V	    VCC	    Red
    A2          10	        NSS	    Yellow
    A3          13	        SCK	    Green
    A5          11	        MOSI	Blue
    A4          12	        MISO	Violet
    D2          2	        DI00	Gray
                            ANA	    Antenna
    D6                      RST     Optional
*/

void setup() 
{
 
    Serial.begin(115200); // Open serial monitor at 115200 baud to see ping results.
    Particle.publish("RFM69 RX Startup setup","Completed",360,PRIVATE);
    Particle.publish("WiFi signal",String(WiFi.RSSI()),360,PRIVATE);
    Serial.println("RFM69 Based Receiver");
  
    // Hard Reset the RFM module - Optional
  pinMode(RFM69_RST, OUTPUT);
  digitalWrite(RFM69_RST, HIGH);
  delay(100);
  digitalWrite(RFM69_RST, LOW);
  delay(100);
  
    // Initialize radio
  radio.initialize(FREQUENCY,NODEID,NETWORKID);
  if (IS_RFM69HCW) {
    radio.setHighPower();    // Only for RFM69HCW & HW!
  }
  
  // To improve distance set a lower bit rate. Most libraries use 55.55 kbps as default
  // See https://lowpowerlab.com/forum/moteino/rfm69hw-bit-rate-settings/msg1979/#msg1979
  // Here we will set it to 9.6 kbps instead 
  radio.writeReg(0x03,0x0D); //set bit rate to 9k6
  radio.writeReg(0x04,0x05);
  
  radio.setPowerLevel(10); // power output ranges from 0 (5dBm) to 31 (20dBm)
                          // Note at 20dBm the radio sources up to 130 mA! 
                         // Selecting a power level between 10 and 15 will use ~30-44 mA which is generally more compatible with Photon power sources
                        // As reference, power level of 10 transmits successfully at least 300 feet with 0% packet loss right through a home, sufficient for most use
    
  //radio.encrypt(ENCRYPTKEY);
  
  Serial.print("\nListening at ");
  Serial.print(FREQUENCY==RF69_433MHZ ? 433 : FREQUENCY==RF69_868MHZ ? 868 : 915);
  Serial.println(" MHz");
  radio.receiveDone(); //put radio in RX mode
}


//=========================MAIN LOOP===========================================
void loop() {

Serial.print("."); //THis gives us a neat visual indication of time between messages received

  //check if something was received (could be an interrupt from the radio)
  if (radio.receiveDone())
  {
    //print message received to serial
    Serial.println(" ");
    Serial.print('[');Serial.print(radio.SENDERID);Serial.print("] ");
    Serial.print((char*)radio.DATA);
    Serial.print("   [RX_RSSI:");Serial.print(radio.RSSI);Serial.print("]");
    
    //send message to Particle console if not using serial
    String RXMessage = "[" + String(radio.SENDERID) + "]  " + String((char*)radio.DATA) + " [RSSI: " + String(radio.RSSI) + "]";
    Particle.publish("Message received",RXMessage,360,PRIVATE);

    //check if received message contains Hello
    if (strstr((char *)radio.DATA, "Hello"))
    {
      //check if sender wanted an ACK
      if (radio.ACKRequested())
      {
        radio.sendACK();
        Serial.println(" - ACK sent");
      }
      else {Serial.println(" - No ACK sent");}
    }  
  }

  radio.receiveDone(); //put radio in RX mode
  
  delay(1000);


} //end loop

Thanks in advance for the help guys!


RadioHead library + Photon (Tx) +Electron(Rx) +MiCS-5524 +433Mhz (Sparkfun)Tx/Rx module
#16

Yes! I have confirmed the below code on an Arduino pro mini as transmitter to a Photon. Make changes or for initial testing use the exact sample code from the Photon library (that it is, same network ID, set encryption, etc.) And make sure you’re using the latest RFM69 library on the Arduino (and not the Particle library).

/* RFM69 library and code by Felix Rusu - felix@lowpowerlab.com
// Get libraries at: https://github.com/LowPowerLab/
// Make sure you adjust the settings in the configuration section below !!!
// **********************************************************************************
// Copyright Felix Rusu, LowPowerLab.com
// Library and code by Felix Rusu - felix@lowpowerlab.com
// **********************************************************************************
// License
// **********************************************************************************
// This program is free software; you can redistribute it 
// and/or modify it under the terms of the GNU General    
// Public License as published by the Free Software       
// Foundation; either version 3 of the License, or        
// (at your option) any later version.                    
*/

#include <RFM69.h>    //get it here: https://www.github.com/lowpowerlab/rfm69
#include <SPI.h>

#include <Arduino.h>            // assumes Arduino IDE v1.0 or greater
#include <avr/sleep.h>
#include <avr/wdt.h>
#include <avr/power.h>

//watchdog interrupt
ISR (WDT_vect) {
  wdt_disable();
}

//#include <LowPower.h> //get library from: https://github.com/lowpowerlab/lowpower
                      //writeup here: http://www.rocketscream.com/blog/2011/07/04/lightweight-low-power-arduino-library/
                      
//*********************************************************************************************
// *********** IMPORTANT SETTINGS - YOU MUST CHANGE/ONFIGURE TO FIT YOUR HARDWARE *************
//*********************************************************************************************
#define NETWORKID     100  // The same on all nodes that talk to each other
#define NODEID        2    // The unique identifier of this node
#define RECEIVER      1    // The recipient of packets

//Match frequency to the hardware version of the radio on your Feather
//#define FREQUENCY     RF69_433MHZ
//#define FREQUENCY     RF69_868MHZ
#define FREQUENCY     RF69_915MHZ
#define ENCRYPTKEY    "sampleEncryptKey" //exactly the same 16 characters/bytes on all nodes!
#define IS_RFM69HCW   false // set to 'true' if you are using an RFM69HCW module

//*********************************************************************************************
#define SERIAL_BAUD   115200

#define RFM69_CS      10
#define RFM69_IRQ     2
#define RFM69_IRQN    0  // Pin 2 is IRQ 0!
#define RFM69_RST     9

#define LED           13  // onboard blinky


int16_t packetnum = 0;  // packet counter, we increment per xmission

RFM69 radio = RFM69(RFM69_CS, RFM69_IRQ, IS_RFM69HCW, RFM69_IRQN);

void setup() {
 
  pinMode(RFM69_RST, INPUT);
  pinMode(RFM69_CS, OUTPUT);
    digitalWrite(RFM69_CS, LOW);  
  
//  while (!Serial); // wait until serial console is open, remove if not tethered to computer
  Serial.begin(SERIAL_BAUD);

  Serial.println("Arduino RFM69 Transmitter");
  
  // Hard Reset the RFM module
  /*
  pinMode(RFM69_RST, OUTPUT);
  digitalWrite(RFM69_RST, HIGH);
  delay(100);
  digitalWrite(RFM69_RST, LOW);
  delay(100);
*/

  // Initialize radio
  radio.initialize(FREQUENCY,NODEID,NETWORKID);
  if (IS_RFM69HCW) {
  //  radio.setHighPower();    // Only for RFM69HCW & HW!
  }
  
    // https://lowpowerlab.com/forum/moteino/rfm69hw-bit-rate-settings/msg1979/#msg1979
  radio.writeReg(0x03,0x0D); //set bit rade to 9k6
  radio.writeReg(0x04,0x05);
  
  radio.setPowerLevel(10); // power output ranges from 0 (5dBm) to 31 (20dBm)
  
  radio.encrypt(ENCRYPTKEY);
  
  radio.sleep();
  

  pinMode(LED, OUTPUT);
  Serial.print("\nTransmitting at ");
  Serial.print(FREQUENCY==RF69_433MHZ ? 433 : FREQUENCY==RF69_868MHZ ? 868 : 915);
  Serial.println(" MHz");
  
    power_timer1_disable();
  power_timer2_disable();
  power_twi_disable();
  
  
}


void loop() {
  Serial.println("Start loop");
  delay(2000);  // Wait 1 second between transmits, could also 'sleep' here!
    
  char radiopacket[20] = "Hello World #";
  itoa(packetnum++, radiopacket+13, 10);
  Serial.print("Sending "); Serial.println(radiopacket);
    
  if (radio.sendWithRetry(RECEIVER, radiopacket, strlen(radiopacket))) { //target node Id, message as string or byte array, message length
    Serial.println("OK");
  }

  //send the message without retrying
 //  radio.send(RECEIVER, radiopacket, strlen(radiopacket));//target node Id, message as string or byte array, message length
 //   Serial.println("OK, sent without retrying");  
  
  radio.receiveDone(); //put radio in RX mode
  
  Serial.println("Radio going to sleep");
  radio.sleep();
  delay(4000);
  
  Serial.println("Everything going to sleep");
  Serial.flush(); //make sure all serial data is clocked out before sleeping the MCU
  deepsleep();
  
}

void deepsleep() 
{
  // disable ADC
  ADCSRA = 0;  
  // clear various "reset" flags
  MCUSR = 0;
  // allow changes, disable reset
  WDTCSR = bit (WDCE) | bit (WDE);
  //set interrupt mode and an interval
  WDTCSR = bit (WDIE) | bit (WDP3) | bit (WDP0); //set WDIE, and 8 seconds delay
  wdt_reset(); //pat the dog...
  
  set_sleep_mode (SLEEP_MODE_PWR_DOWN);
  noInterrupts(); // timed sequence follows  
  sleep_enable();

  // turn off brown-out enable in software
  // BODS must be set to one and BODSE must be set to zero within four clock cycles
  MCUCR = bit (BODS) | bit (BODSE);
  // The BODS bit is automatically cleared after three clock cycles
  MCUCR = bit (BODS); 
  interrupts();
  sleep_cpu();

  //cancel sleep as a precaution
  sleep_disable();
}

Electron, nRF24L01 and Pro Mini
#17

Thank you so much man. This worked perfectly!


#18

FYI - There was an issue where ATC was not working with Photon. Corrected now. Make sure you use the new library version 0.0.2 (or later). This is pretty cool functionality that will dial down the transmit power level to reach a target RSSI level.


#19

@bloukingfisher What kind of range have you seen when testing these RFM69 modules?

I’ve only used the RFM96 modules that provided a 1-mile range for non-reliable datagram communication and I can not get past 10 feet when trying to use the reliable datagram messaging on a few different RFM96 modules for some reason.


#20

I’ve only been testing for reliable communications in about 150 feet, indoors and outdoors. And they work for that. A couple of challenges in the process. Once the dust settles I’ll try to take them for a walk to get an idea of longer range (I’ve read other people getting long range especially using the ‘H’ versions for higher power and turning down the rate.