Newbie: RFM69 serial gateway



  • Hello,

    I'll tried to create a RFM69 Serial Gateway with RFM69HC module

    In a first step, i have only compiled the default sketch with RFM69 options and loaded on an arduino nano but i have no message on the console of the IDE.
    With the NRF24 options, i have the standard message (impossible to initialize radio).
    How to make to have debug message with the RFM69 options?

    Best regards



  • There is no debug message with RFM69.
    If I am right the RFM lib used is not up-to-date and there is some blocking code if the connection is not correctly done.

    Have you tried the hardware with simple code (without MySensors) ?

    David.



  • Thanks for the response

    No, i have not tried with a simple code.

    Do you have an example?

    Regards



  • The code for the transmitter:

    /**************************************************************************************/
    /* Simple sketch to check RFM69 is correctly connected to the Arduino.                */
    /*        Part of the Global Home Automation System GHAS.                             */
    /*                                                                                    */
    /*                                                                                    */
    /* Version: 0.0.5                                                                     */
    /* Date   : 28/12/2015                                                                */
    /* Author : David Carlier                                                             */
    /**************************************************************************************/
    /*                                ---------------                                     */
    /*                            RST |             |  A5                                 */
    /*                            RX  |             |  A4                                 */
    /*                            TX  |   ARDUINO   |  A3                                 */
    /*     RFM69 (DIO0) --------- D2  |     UNO     |  A2                                 */
    /*                            D3  |             |  A1                                 */
    /*                            D4  | ATMEGA 328p |  A0                                 */
    /*            +3.3v --------- VCC |             | GND --------- GND                   */
    /*              GND --------- GND |  8MHz int.  | REF                                 */
    /*                            OSC |             | VCC --------- +3.3v                 */
    /*                            OSC |             | D13 --------- RFM69 (SCK)           */
    /*                            D5  |             | D12 --------- RFM69 (MISO)          */
    /*                            D6  |             | D11 --------- RFM69 (MOSI)          */
    /*                            D7  |             | D10 --------- RFM69 (NSS)           */
    /*                            D8  |             |  D9                                 */
    /*                                ---------------                                     */
    /*                                                                                    */
    /*                                                                                    */
    /**************************************************************************************/
    /*                                                                                    */
    /* Used library:                                                                      */
    /*                                                                                    */
    /*     RFM69  : https://github.com/LowPowerLab/RFM69                                  */
    /*     Jeelib : http://jeelabs.net/projects/jeelib/wiki                               */
    /*                                                                                    */
    /**************************************************************************************/
    
    //Include low power library
    #include <JeeLib.h>
    
    //Include RFM69 library
    #include <RFM69.h>
    #include <SPI.h>
    
    //Active mode debug.
    #define DEBUG
    
    //Define RFM69 settings
    #define GATEWAYID   50
    #define NODEID      35
    #define NETWORKID   5
    #define FREQUENCY   RF69_868MHZ
    #define ENCRYPTKEY  "1234567890123456"	//Encrypt key must be 16 characters
    #define IS_RFM69HW
    
    //Setup the watchdog
    ISR(WDT_vect) {Sleepy::watchdogEvent();}
    
    //Declare RFM69 driver
    RFM69 radio;
    
    //Declare local constants
    #define LOOP_DELAY   58000
    
    //Data table
    typedef struct
      {
      float    rfmTemp;      //Temperature (°C)
      float    humidity;     //Humidity (%)
      float    voltage;      //Voltage of battery capacity (v)
      byte     measure;      //Measure number (from 0 to 250, +1 each new measurement)
      } Payload;
    Payload dataToSend;
    
    //Misc.
    const char VERSION[] = "GHAS RFM69 test (transmitter) v0.0.5";
    
    /**************************************************************************************/
    /* Initialization                                                                     */
    /**************************************************************************************/
    void setup()
      {
      //Open a serial connection to display values
      #ifdef DEBUG
        Serial.begin(115200);
        Serial.print("Starting ");
        Serial.println(VERSION);
      #endif
    
      //Initialize data
      dataToSend.measure = 0;
    
      //Initialize RFM69 driver
      radio.initialize(FREQUENCY, NODEID, NETWORKID);
      radio.setHighPower();
      radio.encrypt(ENCRYPTKEY);
    
      #ifdef DEBUG
        radio.readAllRegs();
        Serial.flush();
      #endif
    
      delay(1000);
      }
    
    /**************************************************************************************/
    /* Main loop                                                                          */
    /**************************************************************************************/
    void loop()
      {
      //Get informations
      dataToSend.voltage = getVoltage() / 100.0;
      dataToSend.rfmTemp = radio.readTemperature(0);
    
      //Insert number of measure
      dataToSend.measure++;
      if (dataToSend.measure > 250) {dataToSend.measure = 0;}
    
      //Send data on serial link
      #ifdef DEBUG
        Serial.print(dataToSend.rfmTemp, 1);
        Serial.print(" degC");
        Serial.print("   ");
        Serial.print(dataToSend.voltage);
        Serial.print(" v");
        Serial.print("   (");
        Serial.print(dataToSend.measure);
        Serial.println(")");
        Serial.flush();
      #endif
    
      //Send data
      if (radio.sendWithRetry(GATEWAYID, (const void*)(&dataToSend), sizeof(dataToSend)))
        {
        #ifdef DEBUG
          Serial.println("Transmission done without problem !");
          Serial.flush();
        #endif
        }
      else
        {
        #ifdef DEBUG
          Serial.println("Error with transmission !");
          Serial.flush();
        #endif
        }
      
      //Waiting time before next measurement (minimum 3 seconds)
      radio.sleep();
      //delay(LOOP_DELAY);
      Sleepy::loseSomeTime(LOOP_DELAY);
      }
    
    /**************************************************************************************/
    /* Allows to get the real Vcc (return value * 100).                                   */
    /**************************************************************************************/
    int getVoltage()
      {
      const long InternalReferenceVoltage = 1056L;
      ADMUX = (0<<REFS1) | (1<<REFS0) | (0<<ADLAR) | (1<<MUX3) | (1<<MUX2) | (1<<MUX1) | (0<<MUX0);
      delay(50);  // Let mux settle a little to get a more stable A/D conversion
      //Start a conversion  
      ADCSRA |= _BV( ADSC );
      //Wait for it to complete
      while (((ADCSRA & (1<<ADSC)) != 0));
      //Scale the value
      int result = (((InternalReferenceVoltage * 1023L) / ADC) + 5L) / 10L;
      return result;
      }
    

    As you can see, some debug informations are displayed in the console.

    The code for the receiver:

    /**************************************************************************************/
    /* Simple sketch to check RFM69 is correctly connected to the Arduino.                */
    /*        Part of the Global Home Automation System GHAS.                             */
    /*                                                                                    */
    /*                                                                                    */
    /* Version: 0.0.1                                                                     */
    /* Date   : 28/12/2015                                                                */
    /* Author : David Carlier                                                             */
    /**************************************************************************************/
    /*                                ---------------                                     */
    /*                            RST |             |  A5                                 */
    /*                            RX  |             |  A4                                 */
    /*                            TX  |   ARDUINO   |  A3                                 */
    /*     RFM69 (DIO0) --------- D2  |     UNO     |  A2                                 */
    /*                            D3  |             |  A1                                 */
    /*                            D4  | ATMEGA 328p |  A0                                 */
    /*            +3.3v --------- VCC |             | GND --------- GND                   */
    /*              GND --------- GND |  8MHz int.  | REF                                 */
    /*                            OSC |             | VCC --------- +3.3v                 */
    /*                            OSC |             | D13 --------- RFM69 (SCK)           */
    /*                            D5  |             | D12 --------- RFM69 (MISO)          */
    /*                            D6  |             | D11 --------- RFM69 (MOSI)          */
    /*                            D7  |             | D10 --------- RFM69 (NSS)           */
    /*                            D8  |             |  D9                                 */
    /*                                ---------------                                     */
    /*                                                                                    */
    /*                                                                                    */
    /**************************************************************************************/
    /*                                                                                    */
    /* Used library:                                                                      */
    /*                                                                                    */
    /*     RFM69  : https://github.com/LowPowerLab/RFM69                                  */
    /*     Jeelib : http://jeelabs.net/projects/jeelib/wiki                               */
    /*                                                                                    */
    /**************************************************************************************/
    
    //Include low power library
    #include <JeeLib.h>
    
    //Include RFM69 library
    #include <RFM69.h>
    #include <SPI.h>
    
    //Active mode debug.
    #define DEBUG
    
    //Define RFM69 settings
    #define NODEID      50
    #define NETWORKID   5
    #define FREQUENCY   RF69_868MHZ
    #define ENCRYPTKEY  "1234567890123456"  //Encrypt key must be 16 characters
    #define IS_RFM69HW
    
    //Setup the watchdog
    ISR(WDT_vect) {Sleepy::watchdogEvent();}
    
    //Declare RFM69 driver
    RFM69 radio;
    
    //Data table
    typedef struct
      {
      float    rfmTemp;      //Temperature (°C)
      float    humidity;     //Humidity (%)
      float    voltage;      //Voltage of battery capacity (v)
      byte     measure;      //Measure number (from 0 to 250, +1 each new measurement)
      } Payload;
    Payload dataReceived;
    
    //Misc.
    const char VERSION[] = "GHAS RFM69 test (receiver) v0.0.1";
    
    /**************************************************************************************/
    /* Initialization                                                                     */
    /**************************************************************************************/
    void setup()
      {
      //Open a serial connection to display values
      #ifdef DEBUG
        Serial.begin(115200);
        Serial.print("Starting ");
        Serial.println(VERSION);
      #endif
    
      //Initialize RFM69 driver
      radio.initialize(FREQUENCY, NODEID, NETWORKID);
      radio.setHighPower();
      radio.encrypt(ENCRYPTKEY);
      radio.promiscuous(true);
    
      #ifdef DEBUG
        char buff[50];
        sprintf(buff, "Listening at %d Mhz...\n", FREQUENCY==RF69_433MHZ ? 433 : FREQUENCY==RF69_868MHZ ? 868 : 915);
        Serial.println(buff);
        radio.readAllRegs();
        Serial.flush();
      #endif
    
      delay(1000);
      }
    
    /**************************************************************************************/
    /* Main loop                                                                          */
    /**************************************************************************************/
    void loop()
      {
      //Check if data have been received
      if (radio.receiveDone())
        {
        int dataValid = 0;
        if (radio.DATALEN != sizeof(dataReceived))
          {
          dataValid = 0;
          #ifdef DEBUG
            Serial.print("Invalid payload received, not matching Payload struct!");
          #endif
          }
        else
          {
          dataValid = 1;
          dataReceived = *(Payload*)radio.DATA;
          }
    
        //Send an ACK if required by the node
        if (radio.ACKRequested())
          {
          //radio.SENDERID = NODEID;
          radio.sendACK();
          #ifdef DEBUG
            Serial.print("[ACK-sent]");
          #endif
          }
      
        //Display information on serial line if required
        #ifdef DEBUG
          Serial.print("[RSSI:");
          Serial.print(radio.RSSI, DEC);
          Serial.print("]");
          Serial.print("[TEMP:");
          Serial.print(dataReceived.rfmTemp, DEC);
          Serial.print("]");
          Serial.print("[VOLTAGE:");
          Serial.print(dataReceived.voltage);
          Serial.print(" v]");
          Serial.print("[MEASURE:");
          Serial.print(dataReceived.measure);
          Serial.print("] ");
          Serial.println();
        #endif
        }
      }
    

    Hope it helps !

    David.



  • Thank's for all



  • Did the last post from @carlierd helps? I.g. have you tried?



  • @carlierd Thanks for providing the test code. I am trying to set up RFM69 modules for the first time and have issues, and your code is very welcome. I have the two RFM69C modules connected to an Arduino Pro Mini each. Both Arduinos are able to read all the registers, and the TX node reads temperate and VCC and sends them off to the RX node
    Most measurements are received several times, but some goes missing

    [ACK-sent][RSSI:-87][TEMP:22.0000000000][VOLTAGE:3.31 v][MEASURE:1]
    [ACK-sent][RSSI:-86][TEMP:22.0000000000][VOLTAGE:3.31 v][MEASURE:1]
    [ACK-sent][RSSI:-87][TEMP:22.0000000000][VOLTAGE:3.31 v][MEASURE:1]
    [ACK-sent][RSSI:-89][TEMP:22.0000000000][VOLTAGE:3.31 v][MEASURE:2]
    [ACK-sent][RSSI:-87][TEMP:22.0000000000][VOLTAGE:3.31 v][MEASURE:2]
    [ACK-sent][RSSI:-88][TEMP:22.0000000000][VOLTAGE:3.31 v][MEASURE:3]
    [ACK-sent][RSSI:-87][TEMP:22.0000000000][VOLTAGE:3.31 v][MEASURE:3]
    [ACK-sent][RSSI:-86][TEMP:22.0000000000][VOLTAGE:3.31 v][MEASURE:4]
    [ACK-sent][RSSI:-89][TEMP:22.0000000000][VOLTAGE:3.31 v][MEASURE:4]
    [ACK-sent][RSSI:-86][TEMP:22.0000000000][VOLTAGE:3.31 v][MEASURE:4]
    [ACK-sent][RSSI:-86][TEMP:22.0000000000][VOLTAGE:3.31 v][MEASURE:7]
    [ACK-sent][RSSI:-87][TEMP:22.0000000000][VOLTAGE:3.31 v][MEASURE:7]
    [ACK-sent][RSSI:-88][TEMP:22.0000000000][VOLTAGE:3.31 v][MEASURE:7]
    

    Notice 5 and 6 are missing

    On the sending side it looks like

    22.0 degC   3.31 v   (1)
    Error with transmission !
    22.0 degC   3.31 v   (2)
    Error with transmission !
    22.0 degC   3.31 v   (3)
    Error with transmission !
    22.0 degC   3.31 v   (4)
    Error with transmission !
    22.0 degC   3.31 v   (5)
    Error with transmission !
    22.0 degC   3.31 v   (6)
    Error with transmission !
    22.0 degC   3.31 v   (7)
    Error with transmission !
    

    Both RFM69's have a 4.7uF capacitor across GND+VCC and both modules are powered from the Arduino VCC pin, and the Arduinos are USB powered. Any suggestions on why this isn't working reliable is much appreciated!
    The modules have external antennas and are 1 meter apart



  • Hello,

    I think that the RSSI is very low especially with external antennas and at 1 meter each other !
    You have the good antenna length ? You could try to increase the caps to 10uF.

    It's a pro mini at 3v ? you have not resistor divider for the RFM ?

    David.



  • @carlierd The antennes are 868 MHz rubber antennas with SMA connectors and supposed to be 2dBi gain. They are connected to a SMA connector wired to the RFM69 with as short wires as possible. The Arduinos are 3.3V, so no level converter is required
    The low RSSI values made me think about if the antennas were faulty (I did buy them from China!), and replaced the antennas with jumper wires and suddenly things started to work, although with -90 dbm RSSI. I replaced the jumper wires with the antennas, one at a time, and still things are OK, but RSSI values are still bad (-84 to -78 dbm). Later today I will try to replace the SMA connectors with a wire soldered directly to the module to rule out bad connectors. Also I will try to change the decouple cap to 10 uF

    I assume I can rule out any issues with the wiring between the module and the Arduinos, since both now sends and receive

    I am right to assume that in my scenario I should expect at least -50 dbm RSSI, even with a non-H version of the RFM69?



  • Arf ! Remove the cable between RFM and SMA connector. Use only RF cables. You can do the job with a cable of 17,3 cm directly connected to the antenna pin of the RFM. It's very good for testing and you can reach more than 100 meters with it.

    David.



  • I think I am missing something very basic about how RFM69 modules work with MySensors!

    Still have 2x Pro Mini 3.3V each with a RFM69CW module. If I install the following sketches on two modules, everything is fine

    Sending:
    https://github.com/LowPowerLab/RFM69/blob/master/Examples/Node/Node.ino

    Receiving:
    https://github.com/LowPowerLab/RFM69/blob/master/Examples/Gateway/Gateway.ino

    One module receives data, and acks go back. RSSI is great and now I feel very confident about the hardware being OK

    I pulled the latest 2.0 beta from github and opened the DallasTemperatureSensor sketch and connected a DS18B20 to pin 3 of the sensor Arduino. Changed MY_RADIO_NRF24 to MY_RADIO_RFM69 and enabled MY_DEBUG. The default values for MySensors seems to be network ID 100 and 868 Mhz, so I should be good to go. Sketch builds and installs and I see messages in the serial debug window - but nothing is seen on the node running the Gateway sketch - even in promiscuous mode

    What am I missing?


  • Admin

    @chrille

    Strange. What does the log say? Wish I could help you more. Can't access my RF69 rig tonight here.

    Also, I'm only having the RFM69W what are the differences compared to RFM69CW?



  • @hek This what I'm seeing in the log on the sensor side

    Starting sensor (RRNNA-, 2.0.0-beta)
    Radio init successful.
    find parent
    send: 255-255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,st=bc:
    find parent
    send: 255-255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,st=bc:
    find parent
    send: 255-255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,st=bc:
    find parent
    send: 255-255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,st=bc:
    Init complete, id=255, parent=255, distance=255
    find parent
    send: 255-255-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,st=bc:
    

    The RFM69C/RFM69CW are a version, that's pin compatible with the RFM12. It happened to be version available from China when I ordered the modules. As I understand it's 100% compatible with the non-C version, except for the pinout

    I think it would be useful if the radio driver could output some info when debugging is turned on, like node id, network id, frequency, pin mappings etc



  • @hek I am still trying to get this to work. Can you confirm that you the following gateway combination working:

    • ESP8266 based gateway (telnet or MQTT)
    • RFM69 (H- or non-H)
    • Mysensors 2.0 beta code

    What version of the board manager do you use? (2.0 or 2.1RC)
    How did you wire the RFM radio to the ESP?
    Could you share the actual sketch you're using (feel free to remove IP/SSID stuff)

    It seems that at least some of my issues were related to my USB Serial adaptor not being able to provide sufficient power to the radio (even with a -13dbm/non-H radio). However I still see crashes of the gateway as soon as the node sends traffic.

    • Jan

  • Admin

    Sorry, I haven't rigged ESP with RFM69 myself yet.


  • Mod

    @chrille this thread might help you, I finally got an esp8266 gateway working tonight.


Log in to reply
 

Suggested Topics

  • 3
  • 6
  • 2
  • 5
  • 6
  • 1

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts