Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 16 of 16

Thread: Problems with Teensy 3.6 and Adafruit RFM9x LoRa

  1. #1
    Junior Member
    Join Date
    Jul 2019
    Posts
    9

    Problems with Teensy 3.6 and Adafruit RFM9x LoRa

    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:
    
    }

  2. #2
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    5,068
    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.

  3. #3
    Junior Member
    Join Date
    Jul 2019
    Posts
    9
    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.

  4. #4
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    5,068
    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...

  5. #5
    Junior Member
    Join Date
    Jul 2019
    Posts
    9
    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...

  6. #6
    Senior Member+
    Join Date
    Jul 2014
    Location
    New York
    Posts
    3,702
    You can try to use this for your interrupt:
    Code:
    #define RFM95_INT     digitalPinToInterrupt(2)
    as opposed to
    Code:
    #define RFM95_INT    2

  7. #7
    Junior Member
    Join Date
    Jul 2019
    Posts
    9
    Makes no difference. It's just about got to be something I'm doing wrong but I'm stumped.

  8. #8
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    5,068
    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

  9. #9
    Junior Member
    Join Date
    Jul 2019
    Posts
    9
    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.

  10. #10
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    2,092
    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

  11. #11
    Junior Member
    Join Date
    Jul 2019
    Posts
    9
    Thanks, I appreciate you taking the time to do that. I actually have a couple of those devices so I may try one of them as well.

    FWIW, if you're on Facebook you can see what I'm working on here... https://www.facebook.com/WLCS-Wirele...4524267297756/

    I'm wanting to switch to a device with more pins for future expansion.

  12. #12
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    5,068
    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....
    Click image for larger version. 

Name:	TGST-Top.jpg 
Views:	6 
Size:	67.7 KB 
ID:	17020

    I suspect something is not connected correctly.

    Which again pictures help in cases like this.

  13. #13
    Junior Member
    Join Date
    Jul 2019
    Posts
    9
    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?

  14. #14
    Junior Member
    Join Date
    Jul 2019
    Posts
    9
    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...

  15. #15
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    5,068
    Quote Originally Posted by mperdue View Post
    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!

  16. #16
    Junior Member
    Join Date
    Jul 2019
    Posts
    9
    It’s also a hobby for me. Everything is a hobby since I retired.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •