Communication between 2 LoRa SX1262 modules

you therefore require a transmitter to test the switch and hence a receiver to check if it worked

EDIT: looking back see you have a Raspberry Pi Pico RP2040 - you should be able to connect your SX1262 and test it using RadioLib
I have a RP2040 somewhere about will see if I can find it

One MUST be connected, as the transceiver can be destroyed if you transmit at full power without an antenna.

Exactly ! That's why I opened this thread... My SX1262 module has a RF Switch inside, and it is controlled with 2 external pins: RX_EN / TX_EN. But I'm not sure about the polarity of those signals... See the discusion from the begining.

if you have a Raspberry Pi Pico RP2040 this code transmits OK

// RPi Pico RP2040_SX1262 _Transmit_Interrupt

// File>Examples>RadioLib>SX126x>SX126x_Transmit_Interrupt

// EDITs:
//  radio.begin frequency set to 868.0
//  transmitting byte array and printing it

/*
  RadioLib SX126x Transmit with Interrupts Example

  This example transmits LoRa packets with one second delays
  between them. 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)

  Other modules from SX126x family can also be used.

  For default module settings, see the wiki page
  https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx126x---lora-modem

  For full API reference, see the GitHub Pages
  https://jgromes.github.io/RadioLib/
*/

// include the library
#include <RadioLib.h>

// RPi Pico RP2040
//MOSI: 19
//MISO: 16
//SCK: 18
//SS: 17
// NSS pin:   17
// DIO1 pin:  14
// NRST pin:  12
// BUSY pin:  13
SX1262 radio = new Module(17, 14, 12, 13);

// or detect the pinout automatically using RadioBoards
// https://github.com/radiolib-org/RadioBoards
/*
#define RADIO_BOARD_AUTO
#include <RadioBoards.h>
Radio radio = new RadioModule();
*/

// save transmission state between loops
int transmissionState = RADIOLIB_ERR_NONE;

// flag to indicate that a packet was sent
volatile bool transmittedFlag = false;

// 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!
#if defined(ESP8266) || defined(ESP32)
ICACHE_RAM_ATTR
#endif
void setFlag(void) {
  // we sent a packet, set the flag
  transmittedFlag = true;
}

void setup() {
  Serial.begin(115200);
  delay(2000);
  // initialize SX1262 with default settings
  Serial.print(F("\n\nRPi Pico RP2040 [SX1262] Initializing ... "));
  int state = radio.begin(868.0);
  if (state == RADIOLIB_ERR_NONE) {
    Serial.println(F("success!"));
  } else {
    Serial.print(F("failed, code "));
    Serial.println(state);
    while (true) { delay(10); }
  }

  // set the function that will be called
  // when packet transmission is finished
  radio.setPacketSentAction(setFlag);

  // start transmitting the first packet
  Serial.print(F("[SX1262] Sending first packet ... "));

  // you can transmit C-string or Arduino string up to
  // 256 characters long
  transmissionState = radio.startTransmit("Hello World!");

  // you can also transmit byte array up to 256 bytes long
  /*
    byte byteArr[] = {0x01, 0x23, 0x45, 0x67,
                      0x89, 0xAB, 0xCD, 0xEF};
    state = radio.startTransmit(byteArr, 8);
  */
}

// counter to keep track of transmitted packets
int count = 0;

void loop() {
  // check if the previous transmission finished
  if (transmittedFlag) {
    // reset flag
    transmittedFlag = false;

    if (transmissionState == RADIOLIB_ERR_NONE) {
      // packet was successfully sent
      Serial.println(F("transmission finished!"));

      // NOTE: when using interrupt-driven transmit method,
      //       it is not possible to automatically measure
      //       transmission data rate using getDataRate()

    } else {
      Serial.print(F("failed, code "));
      Serial.println(transmissionState);
    }

    // clean up after transmission is finished
    // this will ensure transmitter is disabled,
    // RF switch is powered down etc.
    radio.finishTransmit();

    // wait a second before transmitting again
    delay(1000);

    // send another one
    Serial.print(F("[SX1262] Sending another packet ... "));

    // you can transmit C-string or Arduino string up to
    // 256 characters long
    //String str = "Hello World! #" + String(count++);
    //transmissionState = radio.startTransmit(str);

    // you can also transmit byte array up to 256 bytes long
    static byte byteArr[] = { 0x01, 0x23, 0x45, 0x67,
                              0x89, 0xAB, 0xCD, 0xEF };
    for (int i = 0; i < sizeof(byteArr); i++)
      Serial.printf("%d ", byteArr[i]);
    transmissionState = radio.startTransmit(byteArr, 8);
    byteArr[0]++;
  }
}

RP2040 serial monitor output

RPi Pico RP2040 [SX1262] Initializing ... success!
[SX1262] Sending first packet ... transmission finished!
[SX1262] Sending another packet ... 1 35 69 103 137 171 205 239 transmission finished!
[SX1262] Sending another packet ... 2 35 69 103 137 171 205 239 transmission finished!
[SX1262] Sending another packet ... 3 35 69 103 137 171 205 239 transmission finished!
[SX1262] Sending another packet ... 4 35 69 103 137 171 205 239 transmission finished!
[SX1262] Sending another packet ... 5 35 69 103 137 171 205 239 transmission finished!
[SX1262] Sending another packet ... 6 35 69 103 137 171 205 239 transmission finished!
[SX1262] Sending another packet ... 7 35 69 103 137 171 205 239 transmission finished!
[SX1262] Sending another packet ... 8 35 69 103 137 171 205 239 transmission finished!
[SX1262] Sending another packet ... 9 35 69 103 137 171 205 239 transmission finished!
[SX1262] Sending another packet ... 10 35 69 103 137 171 205 239 transmission finished!
[SX1262] Sending another packet ... 11 35 69 103 137 171 205 239 transmission finished!
[SX1262] Sending another packet ... 12 35 69 103 137 171 205 239 transmission finished!
[SX1262] Sending another packet ... 13 35 69 103 137 171 205 239 transmission finished!
[SX1262] Sending another packet ... 14 35 69 103 137 171 205 239 transmission finished!

Heltec LoRa V2 receiver

Heltec LoRa V2  SX1276  [SX1276] Initializing ... success!
[SX1276] Starting to listen ... success!
[SX1276] Received packet!
[SX1276] Data:          3 35 69 103 137 171 205 239
[SX1276] RSSI:          -66.00 dBm
[SX1276] SNR:           9.50 dB
[SX1276] Frequency error:       -3839.89 Hz
[SX1276] Received packet!
[SX1276] Data:          4 35 69 103 137 171 205 239
[SX1276] RSSI:          -65.00 dBm
[SX1276] SNR:           11.25 dB
[SX1276] Frequency error:       -3835.69 Hz
[SX1276] Received packet!
[SX1276] Data:          5 35 69 103 137 171 205 239
[SX1276] RSSI:          -65.00 dBm
[SX1276] SNR:           10.00 dB
[SX1276] Frequency error:       -3835.69 Hz
[SX1276] Received packet!
[SX1276] Data:          6 35 69 103 137 171 205 239
[SX1276] RSSI:          -65.00 dBm
[SX1276] SNR:           11.00 dB
[SX1276] Frequency error:       -3848.27 Hz
[SX1276] Received packet!
[SX1276] Data:          7 35 69 103 137 171 205 239
[SX1276] RSSI:          -67.00 dBm
[SX1276] SNR:           12.75 dB
[SX1276] Frequency error:       -3856.66 Hz
[SX1276] Received packet!
[SX1276] Data:          8 35 69 103 137 171 205 239
[SX1276] RSSI:          -65.00 dBm
[SX1276] SNR:           5.50 dB
[SX1276] Frequency error:       -3785.36 Hz
[SX1276] Received packet!
[SX1276] Data:          9 35 69 103 137 171 205 239
[SX1276] RSSI:          -64.00 dBm
[SX1276] SNR:           10.25 dB
[SX1276] Frequency error:       -3869.25 Hz
[SX1276] Received packet!
[SX1276] Data:          10 35 69 103 137 171 205 239
[SX1276] RSSI:          -65.00 dBm
[SX1276] SNR:           10.50 dB
[SX1276] Frequency error:       -3873.44 Hz
[SX1276] Received packet!
[SX1276] Data:          11 35 69 103 137 171 205 239
[SX1276] RSSI:          -63.00 dBm
[SX1276] SNR:           9.50 dB
[SX1276] Frequency error:       -3881.83 Hz
[SX1276] Received packet!
[SX1276] Data:          12 35 69 103 137 171 205 239
[SX1276] RSSI:          -66.00 dBm
[SX1276] SNR:           11.50 dB
[SX1276] Frequency error:       -3881.83 Hz
[SX1276] Received packet!
[SX1276] Data:          13 35 69 103 137 171 205 239
[SX1276] RSSI:          -66.00 dBm
[SX1276] SNR:           13.00 dB
[SX1276] Frequency error:       -3886.02 Hz
[SX1276] Received packet!
[SX1276] Data:          14 35 69 103 137 171 205 239
[SX1276] RSSI:          -66.00 dBm
[SX1276] SNR:           13.00 dB
[SX1276] Frequency error:       -3898.61 Hz
[SX1276] Received packet!
[SX1276] Data:          15 35 69 103 137 171 205 239
[SX1276] RSSI:          -67.00 dBm
[SX1276] SNR:           13.75 dB
[SX1276] Frequency error:       -3902.80 Hz
[SX1276] Received packet!
[SX1276] Data:          16 35 69 103 137 171 205 239
[SX1276] RSSI:          -66.00 dBm
[SX1276] SNR:           13.00 dB
[SX1276] Frequency error:       -3902.80 Hz
[SX1276] Received packet!
[SX1276] Data:          17 35 69 103 137 171 205 239
[SX1276] RSSI:          -69.00 dBm
[SX1276] SNR:           12.50 dB
[SX1276] Frequency error:       -3902.80 Hz

rather than soldering connections direct to the SX1262 module (photo in post 18) I use (try a search on Ebay)
"ESP8266 breakout board adapter plate for ESP-07, ESP-08 and ESP-12"

remove the surface mount resistors and solder the SX1262 directly onto the pads

I finally did it: My first LoRa connection ! :grinning_face: After a month of hard working...

I connected both modules to the same laptop and it seems that in VSCode I can open 2 serial monitors at the same time, to watch both modules. The software I made, for ESP32 and for Pico, both worked perfectly from the first time without any errors (I don't think this has ever happened to me, to write a perfect software from the first time, especially since it's also the first time I've used C++ and this LoRa technology).

And now, regarding the RS Switch, it seems that the mystery of the polarity of the control signals of the antenna RF Switch has been solved. I used the polarity that is seen on the @horace oscilloscope and also emerged from the LoRa module schematic and from the logic in the RF Switch datasheet, that is, Reception = RX_EN: High / TX_EN: Low, and Emission: RX_En: Low / TX_EN: High. This was also the default in RadioLib. So those people from Waveshare they don't know what they're talking about when they say on their website that the polarity of the signals are reversed.

Could I be sure that this is the correct polarity, if I transmitted and received correctly ? Or at the 50 cm distance at which I did the test would it have worked anyway, even without antennas ?

I finally did the field test... I attached the modules and the antenna to a piece of cardboard and attached them to the top of a stick. I left one right at the gate, where my yard begins (it's 350m long and 11m wide), then I took my laptop with me, along with the other module connected via USB and tested the connection from place to place, sending a command to the stationary LoRa server and receiving a packet back from it. The results are as follows:

  1 m,  RSSI =  -17.00 dBm,  SNR = 11.00 dB,  Freq. Error =  -91.06 Hz
 47 m,  RSSI =  -58.00 dBm,  SNR = 10.75 dB,  Freq. Error = -118.19 Hz  (behind a wooden cabin)
 68 m:  RSSI =  -78.00 dBm,  SNR = 10.75 dB,  Freq. Error = -110.44 Hz
 98 m:  RSSI =  -82.00 dBm,  SNR = 10.75 dB,  Freq. Error = -110.44 Hz
141 m:  RSSI =  -85.00 dBm,  SNR = 10.75 dB,  Freq. Error = -114.31 Hz
218 m:  RSSI =  -93.00 dBm,  SNR = 10.75 dB,  Freq. Error = -118.19 Hz  (here the orchard begins.)
245 m:  RSSI = -106.00 dBm,  SNR =  6.25 dB,  Freq. Error = -118.19 Hz  (a valley begins here)
280 m:  RSSI = -107.00 dBm,  SNR =  5.50 dB,  Freq. Error = -122.06 Hz
320 m:  RSSI = -114.00 dBm,  SNR = -1.50,dB,  Freq. Error = -102.69 Hz

Both modules have 5 dBi stick antennas and were configured as follows:

#define FREQ       869.5   // Frequency: P band, 500mW (27dBm), 10% 
#define BW         125.0   // Bandwidth (KHz)
#define SF         9       // Spreading Factor [5..12]
#define CR         7       // Coding Rate: 4/7 [5..8]
#define SYNCW      0xE3    // Sync Word: Custom [Private: 0x12, Public: 0x34] 
#define TX_PWR     9       // TX Power (dBm) [-9..22] / with 5 dBi antenna = 14 dBm (25 mW)
#define TX_DC      10.0    // TX Duty Cycle (% percent)
#define PAMB       8       // Preamble Length [6..20] 
#define XOV        1.7     // TCXO Voltage (V)
#define LDO        false   // Use LDO only ? [false:LDO and DC-DC, true: just LDO]

The full software can be found here:
https://github.com/MarusGradinaru/lora-p2p
It works on ESP32 and Raspberry Pi Pico.

What do you think ? :grinning_face:

If the radio does what you need it to do, you are all set!

Have fun.

Stick to the two standard private and public syncwords, they are known to work well.

Other syncwords may;

Not work
Be leaky, as in accepting packets with other syncwords
Reduce receiver sensitivity

But the Sync Word isn't supposed to be particular for each module, so that SX1262 should not be disturbed with other packages from unknown sources ? :thinking:

Just using a 'unique' syncword does not guarantee that you wont receive LoRa packets from other unknown LoRa transmitters.

Why did you not use one of the two standard syncwords ?