Code got stuck after initialization with RFM69

Hello. I'm working on RFM69 connected to an Arduino Uno. Currently, I was able to initialize the RFM69 using the a code I modified from the internet. However, my Receiver part always encounters error. It doesn't sometimes proceed and sometimes got stuck in the initialization loop. Yesterday, my Transmitter managed to work properly but today, sometimes I also observed same problem with my Receiver.

Here's my wiring.

The code I'm using for both Transmitter and Receiver

#include <SPI.h>
#include <RH_RF69.h>

/************ Radio Setup ***************/

// Change to 434.0 or other frequency, must match RX's freq!
#define RF69_FREQ 434.0

#define RFM69_CS 10
#define RFM69_INT 2
#define RFM69_RST 9
#define LED 13

// Singleton instance of the radio driver
RH_RF69 rf69(RFM69_CS, RFM69_INT);

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

void setup() 
{
  Serial.begin(9600);
  //while (!Serial) { delay(1); } // wait until serial console is open, remove if not tethered to computer

  pinMode(LED, OUTPUT);     
  pinMode(RFM69_RST, OUTPUT);
  //digitalWrite(RFM69_RST, LOW);
  //from this point I added it
  digitalWrite (RFM69_RST, HIGH);
  delay (100);
  digitalWrite (RFM69_RST, LOW);
  delay (100);

  Serial.println("LoRa Daughter Board (RFM69) - Transmitter");
  Serial.println();

  // manual reset
  digitalWrite(RFM69_RST, HIGH);
  delay(10);
  digitalWrite(RFM69_RST, LOW);
  delay(10);
  
  if (!rf69.init()) {
    Serial.println("RFM69 Initialization Failed!");
    while (1);
  }
  Serial.println("RFM69 Initialization Success!");
  // Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM (for low power module)
  // No encryption
  if (!rf69.setFrequency(RF69_FREQ)) {
    Serial.println("setFrequency failed");
  }

  // If you are using a high power RF69 eg RFM69HW, you *must* set a Tx power with the
  // ishighpowermodule flag set like this:
  //rf69.setTxPower(20, true);  // range from 14-20 for power, 2nd arg must be true for 69HCW

  // The encryption key has to be the same as the one in the server
  uint8_t key[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
                    0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
  rf69.setEncryptionKey(key);
  
  pinMode(LED, OUTPUT);

  Serial.print("RFM69 Frequency: ");  Serial.print((int)RF69_FREQ);  Serial.println(" MHz");
}



void loop() {
  delay(1000);  // 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);
  
  // Send a message!
  rf69.send((uint8_t *)radiopacket, strlen(radiopacket));
  rf69.waitPacketSent();

  // Now wait for a reply
  uint8_t buf[RH_RF69_MAX_MESSAGE_LEN];
  uint8_t len = sizeof(buf);

  if (rf69.waitAvailableTimeout(500))  { 
    // Should be a reply message for us now   
    if (rf69.recv(buf, &len)) {
      Serial.print("Got a reply: ");
      Serial.println((char*)buf);
      Blink(LED, 50, 3); //blink LED 3 times, 50ms between blinks
    } else {
      Serial.println("Receive failed");
    }
  } else {
    Serial.println("No reply, is another RFM69 listening?");
  }
}

void Blink(byte PIN, byte DELAY_MS, byte loops) {
  for (byte i=0; i<loops; i++)  {
    digitalWrite(PIN,HIGH);
    delay(DELAY_MS);
    digitalWrite(PIN,LOW);
    delay(DELAY_MS);
  }
}

Here's a screenshot of the result
Taken yesterday: Mar 16

Taken today: Mar 17

I hope someone could help me with. Thank you in advance.

1 Like

IMO, best approach is to change the library/sketch code; lots of examples.
This tutorial covers several boards, hookup, and LowPowerLab's radio library:

RFM69HCW Hookup Guide - learn.sparkfun.com

Hi @mrburnette thank you for always responding to my questions. I appreciate it a lot since I'm newbie here.

Actually, when I started this project that article was my basis. I followed everything on that blog, however, every time I used that, RFM69 were not communicating at all. That's the start when I looked for other codes in the internet such as the one I posted in this thread.

Very Interesting!

Felix @ lowpowerlab.com is an exceptional programmer, but libraries and Arduino "cores" can get out-of-sync.

Give Limor's code a try:
Using the RFM69 Radio | Adafruit RFM69HCW and RFM9X LoRa Packet Radio Breakouts | Adafruit Learning System

Hi @mrburnette actually the code I posted here is based on the link that you've shared.

Tbh, I already tried numerous codes from different libraries I found in the internet. Some worked then eventually failed. I'm losing all possible ways I know

two thoughts
1 the level shifters are too slow for spi [ i use simple resistive divider]
2 the 3.3v supply from the uno is not able to run a rfm69hw
i run a ldo 3,3v reg [ with suitable caps] from the 5v rail

Have to agree with @mrburnette here. I tried the MySensors library and the RadioHead library with my RFM69 boards and got nowhere. The LowPower library worked perfectly for me.

What i would suggest, and what got me out of many frustrating hours of programming/debugging, is to add in the Reset signal to the RFM69 module from a spare digital output. You can use a potential divider to drop the 5v down to 3v3 and then generate a hard reset at the start of your sketch.

Oww I see. Thanks for this @racpi I appreciated it.

Currently, the 3.3V of the RFM69 comes from a regulator that outputs 3.3V and 150 mA Imax. My assumption is that the problem comes from the level shifters huhuhu. So youre suggesting to use a resistive divider instead?

Okay. I cant remember if I tried already the LowPower library. Thanks for this @markd833

What i would suggest, and what got me out of many frustrating hours of programming/debugging, is to add in the Reset signal to the RFM69 module from a spare digital output. You can use a potential divider to drop the 5v down to 3v3 and then generate a hard reset at the start of your sketch.

Actually, I assigned pin 9 of the Uno for the RESET. And add this(see attached code) in the code. That's the time it initialized. However my problem is that, it got stock and sometimes they weren't communicating.

pinMode(LED, OUTPUT);     
  pinMode(RFM69_RST, OUTPUT);
  //digitalWrite(RFM69_RST, LOW);
  //from this point I added it
  digitalWrite (RFM69_RST, HIGH);
  delay (100);
  digitalWrite (RFM69_RST, LOW);
  delay (100);

Hi,
What are you using for antennas for the two RFM units?

Can you please post some images of your project so we can see your component layout?

Thanks.. Tom... :smiley: :+1: :australia: :coffee:

Hello @TomGeorge thanks for responding.

I only soldered a piece of wire measuring 164 mm to the antenna pads, as discussed here RFM69 Hook-up Guide by SparkFun. Is it okay @TomGeorge ???

Just a bit of clarification, which RFM69 module do you have. Is it the HCW variant shown in the fritzing diagram in post #1, or another variant.

Hello @markd833 I'm using RFM69HCW module.

If you try the LowPowerLab RFM69 library - mine is at v1.5.1 - available through the IDE library manager - look for RFM69_LowPowerLab, then have a look through the extensive examples for one called TxRxBlinky. I recall that it is one of the simplest examples and the one that I used to get me going when I started out with RFMs.

Make sure that you check the #define IS_RFM69HW_HCW is uncommented - I think it is in the examples.

I am reporting the same issue. I have a nano 33 IoT board connected to a Sparkfun RFM69HCW board - so no level shifter - all running at 3.3V.

It was working perfectly until a few days ago it started giving the same error as above. Tested multiple radio boards. Same result.

I didn't install any new board package. But something obviously changed.

Hi @cmatt were you able to solve this project? Because personally, I didn't solve the issue.

I have a system working that's using the RadioHead library version 1.121 (as listed in the library.properties file. I used the rf69_reliable_datagram_client/server.pde sketches but have modified them for my own application.

I found that I had several different libraries on my system. I quarantined the libraries, testing one by one until I found the version that worked. I also tested each one with various
BSP versions.

Here are notes from my sketch header:

Radiohead Library checksum:

  • 193 files
  • 104 folders
  • Size on disk: 1.92 MB (2,015,232 bytes)

Arduino Board Package:

  • Arduino SAMD21 M0
  • 1.8.11

I'm using the Sparkfun RFM69 Breakout (915MHz).

Regarding the antenna, the length for 915Mhz should be 74mm.

Hope this helps.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.