Newbie here. I'm trying to connect the RFM9x LoRa to Arduino Uno to make it work. I followed the everything in the adafruit tutorial and used the code in this link RFM9X Test | Adafruit RFM69HCW and RFM9X LoRa Packet Radio Breakouts | Adafruit Learning System .However I'm getting this error (LoRa radio init failed
) . May I humbly ask for any recommendations I could take on this matter? Thanks in advance...
@lostresearcher, your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advise on) your project See About the Installation & Troubleshooting category.
Please post your code here (and, just in case, don't forget to use code tags). Please post a wiring diagram of your setup; a clear photo in daylight might also be helpful.
Thank you @sterretje I am not aware of the categories since I am kinda new here.
My wiring goes like this...
Arduino Uno ----- RFM9x Lora Module (434 MHz)
5V ----- Vin
GND ----- GND
D2 ----- GO (interrupt)
D13 ----- SCK
D12 ----- MISO
D11 ----- MOSI
D10 ----- CS
D9 ----- RST
Here's the code I'm trying. I copied them based on adafruit's RFM9x Lora Module tutorial.
Transmiter's Code
// LoRa 9x_TX
// -*- mode: C++ -*-
// Example sketch showing how to create a simple messaging client (transmitter)
// with the RH_RF95 class. RH_RF95 class does not provide for addressing or
// reliability, so you should only use RH_RF95 if you do not need the higher
// level messaging abilities.
// It is designed to work with the other example LoRa9x_RX
#include <SPI.h>
#include <RH_RF95.h>
#define RFM95_CS 10
#define RFM95_RST 9
#define RFM95_INT 2
// Change to 434.0 or other frequency, must match RX's freq!
#define RF95_FREQ 434.0
// Singleton instance of the radio driver
RH_RF95 rf95(RFM95_CS, RFM95_INT);
void setup()
{
pinMode(RFM95_RST, OUTPUT);
digitalWrite(RFM95_RST, HIGH);
while (!Serial);
Serial.begin(9600);
delay(100);
Serial.println("Arduino LoRa TX Test!");
// manual reset
digitalWrite(RFM95_RST, LOW);
delay(10);
digitalWrite(RFM95_RST, HIGH);
delay(10);
while (!rf95.init()) {
Serial.println("LoRa radio init failed");
while (1);
}
Serial.println("LoRa radio init OK!");
// Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM
if (!rf95.setFrequency(RF95_FREQ)) {
Serial.println("setFrequency failed");
while (1);
}
Serial.print("Set Freq to: "); Serial.println(RF95_FREQ);
// Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on
// The default transmitter power is 13dBm, using PA_BOOST.
// If you are using RFM95/96/97/98 modules which uses the PA_BOOST transmitter pin, then
// you can set transmitter powers from 5 to 23 dBm:
rf95.setTxPower(23, false);
}
int16_t packetnum = 0; // packet counter, we increment per xmission
void loop()
{
Serial.println("Sending to rf95_server");
// Send a message to rf95_server
char radiopacket[20] = "Hello World # ";
itoa(packetnum++, radiopacket+13, 10);
Serial.print("Sending "); Serial.println(radiopacket);
radiopacket[19] = 0;
Serial.println("Sending..."); delay(10);
rf95.send((uint8_t *)radiopacket, 20);
Serial.println("Waiting for packet to complete..."); delay(10);
rf95.waitPacketSent();
// Now wait for a reply
uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
Serial.println("Waiting for reply..."); delay(10);
if (rf95.waitAvailableTimeout(1000))
{
// Should be a reply message for us now
if (rf95.recv(buf, &len))
{
Serial.print("Got reply: ");
Serial.println((char*)buf);
Serial.print("RSSI: ");
Serial.println(rf95.lastRssi(), DEC);
}
else
{
Serial.println("Receive failed");
}
}
else
{
Serial.println("No reply, is there a listener around?");
}
delay(1000);
}
Receiver's Code
// Arduino9x_RX
// -*- mode: C++ -*-
// Example sketch showing how to create a simple messaging client (receiver)
// with the RH_RF95 class. RH_RF95 class does not provide for addressing or
// reliability, so you should only use RH_RF95 if you do not need the higher
// level messaging abilities.
// It is designed to work with the other example Arduino9x_TX
#include <SPI.h>
#include <RH_RF95.h>
#define RFM95_CS 10
#define RFM95_RST 9
#define RFM95_INT 2
// Change to 434.0 or other frequency, must match RX's freq!
#define RF95_FREQ 434.0
// Singleton instance of the radio driver
RH_RF95 rf95(RFM95_CS, RFM95_INT);
// Blinky on receipt
#define LED 13
void setup()
{
pinMode(LED, OUTPUT);
pinMode(RFM95_RST, OUTPUT);
digitalWrite(RFM95_RST, HIGH);
while (!Serial);
Serial.begin(9600);
delay(100);
Serial.println("Arduino LoRa RX Test!");
// manual reset
digitalWrite(RFM95_RST, LOW);
delay(10);
digitalWrite(RFM95_RST, HIGH);
delay(10);
while (!rf95.init()) {
Serial.println("LoRa radio init failed");
while (1);
}
Serial.println("LoRa radio init OK!");
// Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM
if (!rf95.setFrequency(RF95_FREQ)) {
Serial.println("setFrequency failed");
while (1);
}
Serial.print("Set Freq to: "); Serial.println(RF95_FREQ);
// Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on
// The default transmitter power is 13dBm, using PA_BOOST.
// If you are using RFM95/96/97/98 modules which uses the PA_BOOST transmitter pin, then
// you can set transmitter powers from 5 to 23 dBm:
rf95.setTxPower(23, false);
}
void loop()
{
if (rf95.available())
{
// Should be a message for us now
uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
if (rf95.recv(buf, &len))
{
digitalWrite(LED, HIGH);
RH_RF95::printBuffer("Received: ", buf, len);
Serial.print("Got: ");
Serial.println((char*)buf);
Serial.print("RSSI: ");
Serial.println(rf95.lastRssi(), DEC);
// Send a reply
uint8_t data[] = "And hello back to you";
rf95.send(data, sizeof(data));
rf95.waitPacketSent();
Serial.println("Sent a reply");
digitalWrite(LED, LOW);
}
else
{
Serial.println("Receive failed");
}
}
}
Please edit your post, select all code and apply code tags using the </>
button; next save your post.
please edit your post, select the code part and press the </> icon in the tool bar to mark it as code. It’s barely readable as it stands. (also make sure you indented the code in the IDE before copying, that’s done by pressing ctrlT on a PC or cmdT on a Mac)
Thank you so much @sterretje I edited it already.
Thank you so much @J-M-L I edited it already.
Thanks for fixing the post.
So it seems like rf95.init()
is failing, indicating and issue with your hardware setup
Based on what I've seen and searched in the internet, it might be rf95.init ()
the problem. I've also tried using different pins I saw in their set-up, bit I'm still getting same error. Could you give me recommendations to take? I am out of ideas already...
Can you post a good picture of the module - both sides? Did you solder the headers yourself?
Have you checked your DuPont wires?
May be change the frequency (whilst staying in your regions approved band - seems like you are in Europe)
I didn't solder the headers but I inserted it on the breadboard. I checked several times the continuity of every wire/connection, and they were all correct.
Here are pictures of RFM9x and Arduino Uno
Are the headers soldered? If not, 99% chances this is your problem
No. I just inserted it on the breadboard. So, if ever do I need to solder the headers in to the RFM9x??
Also, I am from Asia. I think I can use 433MHz here.
Owwwww. Okay. I'll do your recommendation. I didn't know it has an effect in your set up. Thanks for this info!
If they are not soldered, the SPI frequency will create issues even if you think you have good continuity.
They need to be soldered (correctly)
Check the usable frequency (see Frequency Plans by Country | The Things Network)
Thanks for this info. I'll start to solder the headers now. Hope it will work this time.
Finger crossed. Let us know how it goes
OMG. It worked like magic after I soldered the headers. I can't thank you enough.
Glad you solved it now. Have fun!!
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.