Problems with Teensy 3.6 and Adafruit RFM9x LoRa

mperdue

Member
I'm hoping someone can point me in the right direction. I'm trying to get LoRa working with a Teensy 3.6 in the hope that I can use it to replace a Feather M0 in a current project. When I try to init the radio I get the message "LoRa radio init failed" from the program. Obviously, I can't get far with this if I can't even init the radio. This works fine with the Feather M0 so it's very probably something I've set up incorrectly.

The code is very simple stuff so far...

Any help would be greatly appreciated

Code:
#include <SPI.h>
#include <RH_RF95.h>

#define DEBUG true

#define RFM95_CS 10     // Chip Select
#define RFM95_RST 9     // Reset
#define RFM95_INT 3     // Interupt

// radio xmit power level (20 = MAX)
#define RFM95_POWER 13

// Change to 434.0 or other frequency, must match TX's freq!
#define RF95_FREQ 915.0

// create a singleton instance of the radio driver
RH_RF95 rf95(RFM95_CS, RFM95_INT);

void setup()
{

  pinMode(RFM95_RST, OUTPUT);         // Enable Reset control
  digitalWrite(RFM95_RST, HIGH);      // Clear reset (active low)

  if (DEBUG)
  {
    Serial.begin(115200);             // Set the serial port baud rate for diagnostic messages
    while (!Serial) delay(1);
  }

  delay(100);

  if(DEBUG) Serial.println("Starting Teensy LoRa Test\n");
  
  pinMode(RFM95_CS, OUTPUT);          // Chip Select is an output
  
  // manually reset the radio by toggling the RFM95_RST line
  digitalWrite(RFM95_RST, LOW);       // Force reset low (active low)
  delay(10);                          // Hold low for 10mS
  digitalWrite(RFM95_RST, HIGH);      // Release the reset signal
  delay(10);                          // pause 10mS before continuing

  while (!rf95.init()) {
    // if not init the fail
    if (DEBUG) Serial.println("LoRa radio init failed");
    while (1);
  }

  // LoRa initialized
  if (DEBUG) Serial.println("LoRa radio init OK!");

  // Defaults after reset are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM
  // change the frequency to 915 mHz
  if (!rf95.setFrequency(RF95_FREQ)) {
    if (DEBUG) Serial.println("setFrequency failed");
    while (1);
  }

  // Output frequency diagnostic message
  if (DEBUG) Serial.print("Set Freq to: ");
  if (DEBUG) Serial.println(RF95_FREQ);

  // set transmitter powers from 5 to 23 dBm:
  rf95.setTxPower(RFM95_POWER, false);
  // Output power diagnostic message
  if (DEBUG) Serial.print("Set Power to: ");
  if (DEBUG) Serial.println(23);
}

void loop() {
  // put your main code here, to run repeatedly:

}
 
When you say you can not init.

Are you saying that it won't build?

Or are you dying in: if (DEBUG) Serial.println("LoRa radio init failed");
Or did something else fail?

I assume you have it setup on the SPI pins 11-13. Again always helps to see pictures, where we can find simple things like, you have this in a breadboard, but the pins are not soldered to the Teensy...

Other common issue is: What version of the RadioHead library are you using?

I am using my own fork of it, but it is in sync with PaulStoffregen (PJRC) version up at: https://github.com/PaulStoffregen/RadioHead

There may be other versions out there that are not setup to fully work with Teensy.
 
The code builds OK but it fails when I call rf96.init() so with DEBUG set "LoRa radio init failed" is set to the serial output. Yes, I am using pins 11-13 for SPI. The RH version is 1.92 according to the download link. This is assembled on a breadboard using a teensy 3.6 with the pins pre-soldered. I did solder the pins on the adafruit lora board but I have had a fair amount of soldering experience and have checked that. I also get the same results with a different lora board.
 
If it were me, as an experiment, I would move the current version of the Radiohead library to somewhere else and download the one that I linked to above and see if that works for you.

I have used the RH95 code in a few places.... Example sketch:
Code:
// rf95_client.pde
// -*- mode: C++ -*-
// Example sketch showing how to create a simple messageing client
// 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 rf95_server
// Tested with Anarduino MiniWirelessLoRa, Rocket Scream Mini Ultra Pro with
// the RFM95W, Adafruit Feather M0 with RFM95

#include <SPI.h>
#include <RH_RF95.h>
#include <RHHardwareSPI1.h>

// Singleton instance of the radio driver
//RH_RF95 rf95;
//RH_RF95 rf95(5, 2); // Rocket Scream Mini Ultra Pro with the RFM95W
//RH_RF95 rf95(8, 3); // Adafruit Feather M0 with RFM95 

#define RFM95_INT     2     // RFM 95 Interrupt pin
#define RFM95_MISO    5     // RFM 95 MISO
#define RFM95_SCK     20    // SPI 1 SCK
#define RFM95_MOSI    21    // SPI 1 MOSI used for RFM95
#define RFM95_CS      31    // RFM95 CS
#define RFM95_RST     37    // RFM95 Reset pin

RH_RF95 rf95(RFM95_CS, RFM95_INT, hardware_spi1);

// Need this on Arduino Zero with SerialUSB port (eg RocketScream Mini Ultra Pro)
//#define Serial SerialUSB

void setup() 
{
  // Rocket Scream Mini Ultra Pro with the RFM95W only:
  // Ensure serial flash is not interfering with radio communication on SPI bus
//  pinMode(4, OUTPUT);
//  digitalWrite(4, HIGH);
  pinMode(RFM95_RST, OUTPUT);
  digitalWrite(RFM95_RST, HIGH);

  // Make sure it is reset
  digitalWrite(RFM95_RST, LOW);
  delay(10);
  digitalWrite(RFM95_RST, HIGH);
  delay(10);
  SPI1.setMISO(RFM95_MISO);
  SPI1.setMOSI(RFM95_MOSI);
  SPI1.setSCK(RFM95_SCK);

  Serial.begin(9600);
  while (!Serial) ; // Wait for serial port to be available
  if (!rf95.init())
    Serial.println("init failed");
  // 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.setFrequency(915.0);
  rf95.setTxPower(23, false);
  // If you are using Modtronix inAir4 or inAir9,or any other module which uses the
  // transmitter RFO pins and not the PA_BOOST pins
  // then you can configure the power transmitter power for -1 to 14 dBm and with useRFO true. 
  // Failure to do that will result in extremely low transmit powers.
//  driver.setTxPower(14, true);
}

void loop()
{
  Serial.println("Sending to rf95_server");
  // Send a message to rf95_server
  uint8_t data[] = "Hello World! Lets make this a bit longer to send maybe about 64";
  rf95.send(data, sizeof(data));
  
  rf95.waitPacketSent();
  // Now wait for a reply
  uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
  uint8_t len = sizeof(buf);

  if (rf95.waitAvailableTimeout(3000))
  { 
    // 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("recv failed");
    }
  }
  else
  {
    Serial.println("No reply, is rf95_server running?");
  }
  delay(400);
}
But my version is setup to use SPI1. Added the support earlier as well as SPI2. This was a slightly modified version of their simple client...
 
OK, I've replaced the library with the one you linked to and copied your code example. then I rewired signals to match your defines but it still fails to init. I swapped the lora board and the teensy 3.6 with no difference. I'm certainly open to other ideas...
 
You can try to use this for your interrupt:
Code:
#define RFM95_INT     digitalPinToInterrupt(2)
as opposed to
Code:
#define RFM95_INT    2
 
Next thing I would do is to go into Radiohead sources and edit rh_rfm95.cpp, look for Init function and uncomment the serial outputs, so can localize what is failing
 
I suspect you are right. Unfortunately, I don’t have the time for that at this point. I was planning you use this device to send some packets that the Wireless Launch Control System I’m building wouldn’t recognize to insure that it properly ignores them. I’ll just set up a Feather M0 to do it for now and will get back to this next month when the rocketry event will be over and i have more time.

Thanks for your help.
 
FWIW I have some 434MHz adafruit breakouts that i have run with T3.2. I hooked one up to T3.6 and confirmed that it works. I also ran your sketch (with 434 frequency) and confirmed your sketch on my T3.6 talks to Adafruit RFM96W

Code:
Starting Teensy LoRa Test

LoRa radio init OK!
Set Freq to: 434.00
Set Power to: 23

i'm running 1.8.8 1.47-beta4 and using Teensyduino's RadioHead lib
 
Good luck with the event,

I still suspect that something is not hook up right. I have tested it before using the adafruit RFM95: https://www.adafruit.com/product/3072
And I have done my own boards with the actual RFM95 chip(sub-board) soldered directly to mine....
TGST-Top.jpg

I suspect something is not connected correctly.

Which again pictures help in cases like this.
 
Yes, I suspect the same thing. When I find it I will probably beat my head against the wall for the better part of a day for overlooking something so obvious. Your PCB is very much like what I will be building when I get this sorted. Do you make the boards yourself or do you contract that out?
 
And it works! All of this due to a broken jumper lead! I'm going to just go bang my head against the wall now...
 
Yes, I suspect the same thing. When I find it I will probably beat my head against the wall for the better part of a day for overlooking something so obvious. Your PCB is very much like what I will be building when I get this sorted. Do you make the boards yourself or do you contract that out?

All of this is just a hobby for me, including making my own boards. The one above was one for a Well monitor system, which I never fully completed, and probably should... I usually get interested when something goes wrong with our wells setup and we are out of water... Since right now water is flowing ...

The board is setup that a PJRC ili9341 with touch display goes on the other side, has some setup to read in some analog values to try to figure out which pumps are running... And threw in a few things like a speaker, NeoPixel, ...

Again I only do as a hobby so probably many things could be improved!
 
Hello i know it's been 3 years but if you solve your problem can you help me i couldnt get proper answer. I have 2 xbee s2c pros and i am using them to transmit data with 300 kb size to about 1 km distance. But once i received it with xbee i want to send data to lora radio and transmit it to another Lora Radio device. Also my xbees works with Teensy 3.6 so my Lora must work with Teensy too. I am searching for a lora 433Hz or 868Hz radio. I have picked some but i wanted to ask you guys for some suggestions for both about radio selection and using radiohead library in teensy 3.6. Here is my picks: https://www.adafruit.com/product/3073 https://www.adafruit.com/product/3232 https://www.adafruit.com/product/3178 Also i have no idea what is the difference beetwen feather/featherwing/feather M0 or just using the hoperf RFM95/96/97/98(W) itself would work fine. I only used this https://www.makerfabs.com/maduino-lo...868m-915m.html but it has ATmage328 embedded. I suppose i need just the radio for teensy so could you help me about what to chose and how to implement it to teensy. I'm a bit confused since there isn't much in the internet about using lora on teensy.
 
I'm currently using the Adafruit RFM95 module ( https://www.adafruit.com/product/3072 ) with the Teensy 3.6. It works very well. FWIW, the Feather is their version of an Arduino, a Featherwing is a device designed to have a Feather plugged into it and the Feather M0 is a Feather with LoRa built in. I originally used the Feather M0 for my wireless launch system but changed to the Teensy 3.6 because I needed more pins.
 
I have been using EByte Lora modules very effectively with no problems.
Those that I have been using have a Uart interface which makes them very easy to use.
No need for the radiohead library, which I have read can be problematic.
EByte also do SPI interface versions as well.
If you need any help using the EByte devices let me know.
I have libraries that I have developed for the E32, E220 and E22 family of modules.
See here for a good price I have found on modules.
EDIT:
The Uart devices are limited to an air data rate of 62.5kbps whereas the spi devices stop at 300kbps.
 
Last edited:
I’ve been thinking about the EByte LoRa modules for an updated design using the Teensy 4.1. I’ve never had issues with the Radiohead libraries though.
 
Back
Top