sandeepmistry / arduino-LoRa

An Arduino library for sending and receiving data using LoRa radios.
MIT License
1.6k stars 621 forks source link

How to use two lora modules for receiving and sending data, but in two different channels #649

Open MateoGiova opened 1 year ago

MateoGiova commented 1 year ago

Hello everyone! I already succeded interfacing two modules with the same spi bus, but I have another issue. Previously I thought on using different sync word, 0xA3 for receiving, and 0xD1 for sending, each one in different modules SX1278, but the receiving is really poor. I checked the Rssi with a default code for receiving, and with that I receive very well, so the problem is in the sync word. How can I "create" two channels without sync word? My code is:


#include <SPI.h>
#include <Wire.h>

#define LORATX_SS     5
#define LORATX_SCK    18
#define LORATX_MOSI   23
#define LORATX_MISO   19
#define LORATX_RST    32
#define LORATX_DIO0   25
#define TX_WORD       0xD1

#define LORARX_SS     15
#define LORARX_SCK    14
#define LORARX_MOSI   13
#define LORARX_MISO   12
#define LORARX_RST    4
#define LORARX_DIO0   26
#define RX_WORD       0xA3

LoRaClass Loratx;
LoRaClass Lorarx;

int packetSize = 0;
String loraData;

void enableTx(){
  digitalWrite(5, LOW);
  digitalWrite(15, HIGH);
  Loratx.setSyncWord(TX_WORD);
}
void enableRx(){
  digitalWrite(5, HIGH);
  digitalWrite(15,LOW);
  //Lorarx.setSyncWord(RX_WORD);
}

void setup() {
  Serial.begin(115200);

  SPI.begin(LORATX_SCK, LORATX_MISO, LORATX_MOSI);

  pinMode(5, OUTPUT);
  pinMode(15, OUTPUT);
  Lorarx.setPins(LORARX_SS, LORARX_RST, LORARX_DIO0);
  Loratx.setPins(LORATX_SS, LORATX_RST, LORATX_DIO0);

  while(!Lorarx.begin(433E6)){
    Serial.println("[Lorarx] Falló la inicialización!");
    delay(1000);
  }
  Serial.println("[Lorarx] Inicializado.");

  while(!Loratx.begin(433E6)){
    Serial.println("[Loratx] Falló la inicialización!");
    delay(1000);
  }
  Serial.println("[Loratx] Inicializado.");
  enableRx();
  delay(100);
  Serial.println("Listo para encontrar paquetes.");
}

void loop() {
  packetSize = Lorarx.parsePacket();
  if(packetSize){
    Serial.println("Se encontró un paquete.");
    while (Lorarx.available()) {
      loraData += Lorarx.readString();
      }
      Serial.print(loraData);
      Serial.println(Lorarx.packetRssi());
      /*enableTx();
      Serial.println("Mandando paquete");
      Loratx.beginPacket();
      Loratx.print(loraData);
      Loratx.endPacket();
      delay(1000);
      Serial.println("Paquete enviado.");
      enableRx();
      Serial.println("Recibiendo...");*/
      loraData = "";
    }
  }
morganrallen commented 1 year ago

Using the Invert IQ functions is commonly used for exactly this.

Kongduino commented 1 year ago

You could do what LoRaWAN does, ie use different frequencies for sending and receiving. You keep everything else the same.