Navigation

    LILYGO

    • Register
    • Login
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups

    RadioLib PingPong not working

    Common problems
    1
    1
    478
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • V
      vimu last edited by

      I could need some help with LoRa communication between an T-Beam SoftRF SX1626 and a T-Beam Mashtastic. I tried to use the transmitter and receiver code from:
      https://github.com/Xinyuan-LilyGO/LilyGo-LoRa-Series/tree/master/examples/RadioLibExamples

      but this didn't work.

      then i used the base of this code (utilities.h, LoRaBoards.h, LoRaBoards.cpp) and changed the main.ino to this:

      /*
         RadioLib Transmit with Interrupts Example
      
         This example transmits packets using SX1276/SX1278/SX1262/SX1268/SX1280/LR1121 LoRa radio module.
         Each packet contains up to 256 bytes of data, in the form of:
          - Arduino String
          - null-terminated char array (C-string)
          - arbitrary binary data (byte array)
      
         For full API reference, see the GitHub Pages
         https://jgromes.github.io/RadioLib/
      */
      
      #include "LoRaBoards.h"
      #include <RadioLib.h>
      
      // save transmission states between loops
      int transmissionState = RADIOLIB_ERR_NONE;
      
      // flag to indicate transmission or reception state
      bool transmitFlag = false;
      
      // flag to indicate that a packet was sent or received
      volatile bool operationDone = false;
      
      #if     defined(USING_SX1276)
      #define CONFIG_RADIO_FREQ           868.0
      #define CONFIG_RADIO_OUTPUT_POWER   15
      #define CONFIG_RADIO_BW             125.0
      SX1276 radio = new Module(RADIO_CS_PIN, RADIO_DIO0_PIN, RADIO_RST_PIN, RADIO_BUSY_PIN);
      
      #elif   defined(USING_SX1278)
      #define CONFIG_RADIO_FREQ           433.0
      #define CONFIG_RADIO_OUTPUT_POWER   17
      #define CONFIG_RADIO_BW             125.0
      SX1278 radio = new Module(RADIO_CS_PIN, RADIO_DIO0_PIN, RADIO_RST_PIN, RADIO_BUSY_PIN);
      
      #elif   defined(USING_SX1262)
      #define CONFIG_RADIO_FREQ           868.0
      #define CONFIG_RADIO_OUTPUT_POWER   22
      #define CONFIG_RADIO_BW             125.0
      
      SX1262 radio = new Module(RADIO_CS_PIN, RADIO_DIO1_PIN, RADIO_RST_PIN, RADIO_BUSY_PIN);
      
      #elif   defined(USING_SX1280)
      #define CONFIG_RADIO_FREQ           2400.0
      #define CONFIG_RADIO_OUTPUT_POWER   13
      #define CONFIG_RADIO_BW             203.125
      #ifdef T3_S3_V1_2_SX1280_PA
      // PA Version power range : -18 ~ 3dBm
      #undef CONFIG_RADIO_OUTPUT_POWER
      #define CONFIG_RADIO_OUTPUT_POWER  3
      #endif
      SX1280 radio = new Module(RADIO_CS_PIN, RADIO_DIO1_PIN, RADIO_RST_PIN, RADIO_BUSY_PIN);
      
      #elif   defined(USING_SX1268)
      #define CONFIG_RADIO_FREQ           433.0
      #define CONFIG_RADIO_OUTPUT_POWER   22
      #define CONFIG_RADIO_BW             125.0
      SX1268 radio = new Module(RADIO_CS_PIN, RADIO_DIO1_PIN, RADIO_RST_PIN, RADIO_BUSY_PIN);
      
      #elif   defined(USING_LR1121)
      #define CONFIG_RADIO_FREQ           868.0
      #define CONFIG_RADIO_OUTPUT_POWER   22
      #define CONFIG_RADIO_BW             125.0
      LR1121 radio = new Module(RADIO_CS_PIN, RADIO_DIO9_PIN, RADIO_RST_PIN, RADIO_BUSY_PIN);
      #endif
      
      void drawMain();
      
      // flag to indicate that a packet was sent
      static volatile bool transmittedFlag = false;
      static uint32_t counter = 0;
      static String payload;
      
      // this function is called when a complete packet
      // is transmitted by the module
      // IMPORTANT: this function MUST be 'void' type
      //            and MUST NOT have any arguments!
      void setFlag(void) {
        // we sent or received a packet, set the flag
        operationDone = true;
      }
      
      void setup()
      {
        setupBoards();
      
        // When the power is turned on, a delay is required.
        delay(1500);
      
      
        int state = radio.begin();
        if (state == RADIOLIB_ERR_NONE) {
          Serial.println(F("success!"));
        } else {
          Serial.print(F("failed, code "));
          Serial.println(state);
          while (true);
        }
      
        // set the function that will be called
        // when new packet is received
      #ifdef USING_SX1262
        radio.setDio1Action(setFlag);
      #endif
      
      #ifdef USING_SX1276
          radio.setDio0Action(setFlag, RISING);
      #endif
      
      
        /*
            Sets carrier frequency.
            SX1278/SX1276 : Allowed values range from 137.0 MHz to 525.0 MHz.
            SX1268/SX1262 : Allowed values are in range from 150.0 to 960.0 MHz.
            SX1280        : Allowed values are in range from 2400.0 to 2500.0 MHz.
            LR1121        : Allowed values are in range from 150.0 to 960.0 MHz, 1900 - 2200 MHz and 2400 - 2500 MHz. Will also perform calibrations.
        * * * */
      
        if (radio.setFrequency(CONFIG_RADIO_FREQ) == RADIOLIB_ERR_INVALID_FREQUENCY) {
          Serial.println(F("Selected frequency is invalid for this module!"));
          while (true);
        }
      
        /*
            Sets LoRa link bandwidth.
            SX1278/SX1276 : Allowed values are 10.4, 15.6, 20.8, 31.25, 41.7, 62.5, 125, 250 and 500 kHz. Only available in %LoRa mode.
            SX1268/SX1262 : Allowed values are 7.8, 10.4, 15.6, 20.8, 31.25, 41.7, 62.5, 125.0, 250.0 and 500.0 kHz.
            SX1280        : Allowed values are 203.125, 406.25, 812.5 and 1625.0 kHz.
            LR1121        : Allowed values are 62.5, 125.0, 250.0 and 500.0 kHz.
        * * * */
        if (radio.setBandwidth(CONFIG_RADIO_BW) == RADIOLIB_ERR_INVALID_BANDWIDTH) {
          Serial.println(F("Selected bandwidth is invalid for this module!"));
          while (true);
        }
      
      
        /*
          Sets LoRa link spreading factor.
          SX1278/SX1276 :  Allowed values range from 6 to 12. Only available in LoRa mode.
          SX1262        :  Allowed values range from 5 to 12.
          SX1280        :  Allowed values range from 5 to 12.
          LR1121        :  Allowed values range from 5 to 12.
        * * * */
        if (radio.setSpreadingFactor(10) == RADIOLIB_ERR_INVALID_SPREADING_FACTOR) {
          Serial.println(F("Selected spreading factor is invalid for this module!"));
          while (true);
        }
      
        /*
          Sets LoRa coding rate denominator.
          SX1278/SX1276/SX1268/SX1262 : Allowed values range from 5 to 8. Only available in LoRa mode.
          SX1280        :  Allowed values range from 5 to 8.
          LR1121        :  Allowed values range from 5 to 8.
        * * * */
        if (radio.setCodingRate(6) == RADIOLIB_ERR_INVALID_CODING_RATE) {
          Serial.println(F("Selected coding rate is invalid for this module!"));
          while (true);
        }
      
        /*
          Sets LoRa sync word.
          SX1278/SX1276/SX1268/SX1262/SX1280 : Sets LoRa sync word. Only available in LoRa mode.
        * * */
        if (radio.setSyncWord(0xAB) != RADIOLIB_ERR_NONE) {
          Serial.println(F("Unable to set sync word!"));
          while (true);
        }
      
        /*
          Sets transmission output power.
          SX1278/SX1276 :  Allowed values range from -3 to 15 dBm (RFO pin) or +2 to +17 dBm (PA_BOOST pin). High power +20 dBm operation is also supported, on the PA_BOOST pin. Defaults to PA_BOOST.
          SX1262        :  Allowed values are in range from -9 to 22 dBm. This method is virtual to allow override from the SX1261 class.
          SX1268        :  Allowed values are in range from -9 to 22 dBm.
          SX1280        :  Allowed values are in range from -18 to 13 dBm. PA Version range : -18 ~ 3dBm
          LR1121        :  Allowed values are in range from -9 to 22 dBm (high-power PA) or -17 to 14 dBm (low-power PA)
        * * * */
        if (radio.setOutputPower(CONFIG_RADIO_OUTPUT_POWER) == RADIOLIB_ERR_INVALID_OUTPUT_POWER) {
          Serial.println(F("Selected output power is invalid for this module!"));
          while (true);
        }
      
      #if !defined(USING_SX1280) && !defined(USING_LR1121)
        /*
          Sets current limit for over current protection at transmitter amplifier.
          SX1278/SX1276 : Allowed values range from 45 to 120 mA in 5 mA steps and 120 to 240 mA in 10 mA steps.
          SX1262/SX1268 : Allowed values range from 45 to 120 mA in 2.5 mA steps and 120 to 240 mA in 10 mA steps.
          NOTE: set value to 0 to disable overcurrent protection
        * * * */
        if (radio.setCurrentLimit(140) == RADIOLIB_ERR_INVALID_CURRENT_LIMIT) {
          Serial.println(F("Selected current limit is invalid for this module!"));
          while (true);
        }
      #endif
      
        /*
          Sets preamble length for LoRa or FSK modem.
          SX1278/SX1276 : Allowed values range from 6 to 65535 in %LoRa mode or 0 to 65535 in FSK mode.
          SX1262/SX1268 : Allowed values range from 1 to 65535.
          SX1280        : Allowed values range from 1 to 65535. preamble length is multiple of 4
          LR1121        : Allowed values range from 1 to 65535.
        * * */
        if (radio.setPreambleLength(16) == RADIOLIB_ERR_INVALID_PREAMBLE_LENGTH) {
          Serial.println(F("Selected preamble length is invalid for this module!"));
          while (true);
        }
      
        // Enables or disables CRC check of received packets.
        if (radio.setCRC(false) == RADIOLIB_ERR_INVALID_CRC_CONFIGURATION) {
          Serial.println(F("Selected CRC is invalid for this module!"));
          while (true);
        }
      
      #ifdef USING_DIO2_AS_RF_SWITCH
      #ifdef USING_SX1262
        // Some SX126x modules use DIO2 as RF switch. To enable
        // this feature, the following method can be used.
        // NOTE: As long as DIO2 is configured to control RF switch,
        //       it can't be used as interrupt pin!
        if (radio.setDio2AsRfSwitch() != RADIOLIB_ERR_NONE) {
          Serial.println(F("Failed to set DIO2 as RF switch!"));
          while (true);
        }
      #endif //USING_SX1262
      #endif //USING_DIO2_AS_RF_SWITCH
      
      #ifdef RADIO_RX_PIN
        // SX1280 PA Version
        radio.setRfSwitchPins(RADIO_RX_PIN, RADIO_TX_PIN);
      #endif
      
      #ifdef RADIO_SWITCH_PIN
        // T-MOTION
        const uint32_t pins[] = {
          RADIO_SWITCH_PIN, RADIO_SWITCH_PIN, RADIOLIB_NC,
        };
        static const Module::RfSwitchMode_t table[] = {
          {Module::MODE_IDLE,  {0,  0} },
          {Module::MODE_RX,    {1, 0} },
          {Module::MODE_TX,    {0, 1} },
          END_OF_MODE_TABLE,
        };
        radio.setRfSwitchTable(pins, table);
      #endif
      
      
      
        delay(1000);
      
      }
      
      void loop() {
        // check if the previous operation finished
        if (operationDone) {
          // reset flag
          operationDone = false;
      
          if (transmitFlag) {
            // the previous operation was transmission, listen for response
            // print the result
            if (transmissionState == RADIOLIB_ERR_NONE) {
              // packet was successfully sent
              Serial.println(F("transmission finished!"));
      
            } else {
              Serial.print(F("failed, code "));
              Serial.println(transmissionState);
      
            }
      
            // listen for response
            radio.startReceive();
            transmitFlag = false;
      
          } else {
            // the previous operation was reception
            // print data and send another packet
            String str;
            int state = radio.readData(str);
      
            if (state == RADIOLIB_ERR_NONE) {
              // packet was successfully received
              Serial.println(F("[SX1262] Received packet!"));
      
              // print data of the packet
              Serial.print(F("[SX1262] Data:\t\t"));
              Serial.println(str);
      
              // print RSSI (Received Signal Strength Indicator)
              Serial.print(F("[SX1262] RSSI:\t\t"));
              Serial.print(radio.getRSSI());
              Serial.println(F(" dBm"));
      
              // print SNR (Signal-to-Noise Ratio)
              Serial.print(F("[SX1262] SNR:\t\t"));
              Serial.print(radio.getSNR());
              Serial.println(F(" dB"));
      
            }
      
            // wait a second before transmitting again
            delay(1000);
      
            // send another one
            Serial.print(F("[SX1262] Sending another packet ... "));
            transmissionState = radio.startTransmit("Hello World!");
            transmitFlag = true;
          }
      
        }
      }
      

      but the flag is not changed and therefore no packet is sent or received. i use arduino ide for programming. i think it maybe is just a wrong pin ? i also changed between "T_BEAM_SX1262" and "T_BEAM_SX1276" when programming but both boards give the same output which is like:

      23:43:26.367 -> ets Jul 29 2019 12:21:46
      23:43:26.367 -> 
      23:43:26.367 -> rst:0x1 (POWERON_RESET),boot:0x13 (S_I_Fdrv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
      23:43:26.367 -> mode:DIO, clock div:1
      23:43:26.367 -> load:0x3fff0030,len:1184
      23:43:26.367 -> load:0x40078000,len:13260
      23:43:26.367 -> load:0x40080400,len:3028
      23:43:26.367 -> entry 0x400805e4
      23:43:26.434 -> setupBoards
      23:43:26.434 -> -----------------------------------
      23:43:26.434 -> Reset reason: In case of deep sleep, reset was not caused by exit from deep sleep
      23:43:26.434 -> PSRAM is disable!
      23:43:26.466 -> Flash:4 MB
      23:43:26.466 -> Flash speed:80 M
      23:43:26.466 -> Model:ESP32-D0WDQ6-V3
      23:43:26.466 -> Chip Revision:3
      23:43:26.466 -> Freq:240 MHZ
      23:43:26.466 -> SDK Ver:v4.4.5
      23:43:26.466 -> DATE:Jun 10 2024
      23:43:26.466 -> TIME:23:35:19
      23:43:26.466 -> EFUSE MAC: C86CA01FB608
      23:43:26.466 -> -----------------------------------
      23:43:26.466 -> AXP2101 PMU init succeeded, using AXP2101 PMU
      23:43:26.500 -> =========================================
      23:43:26.500 -> DC1  : +   Voltage: 3300 mV 
      23:43:26.500 -> DC2  : -   Voltage: 0500 mV 
      23:43:26.500 -> DC3  : -   Voltage: 0500 mV 
      23:43:26.500 -> DC4  : -   Voltage: 1800 mV 
      23:43:26.500 -> DC5  : -   Voltage: 3300 mV 
      23:43:26.500 -> ALDO1: -   Voltage: 1800 mV 
      23:43:26.500 -> ALDO2: +   Voltage: 3300 mV 
      23:43:26.500 -> ALDO3: +   Voltage: 3300 mV 
      23:43:26.500 -> ALDO4: -   Voltage: 3300 mV 
      23:43:26.500 -> BLDO1: -   Voltage: 1800 mV 
      23:43:26.500 -> BLDO2: -   Voltage: 3300 mV 
      23:43:26.500 -> =========================================
      23:43:26.533 -> PowerKeyPressOffTime:4 Second
      23:43:26.533 -> Warning: Failed to find Display at 0x3C address
      23:43:26.533 -> init done . 
      23:43:28.024 -> success!
      

      and then just stop printing anything. maybe someone has an idea how to fix this or debug it ? would be great

      1 Reply Last reply Reply Quote 0
      • First post
        Last post
      Powered by NodeBB | Contributors