LoRa modules can transmit but not recieve ( sx1276 915m30s )

have an elegoo mega 2650 rev3 and an uno R4. the modules are the 915m30s both with the 915 1/2 antenna.

heres the current wiring for the mega:

VCC (Power): Connect to the 5V pin

GND (Ground): All GND connect to the GND pins

3.3V (Logic): Connect to the 3.3V pin

SDI (MOSI): Connect to pin 51

SDO (MISO): Connect to pin 50

SCK: Connect to pin 52

NSS (CS): Connect to pin 10

RST (Reset): Connect to pin 9

DIO0: Connect to pin 2

DIO1: Connect to pin 3

TX_ENABLE: Connect to pin 5

RX_ENABLE: Connect to pin 4

and for the UNO:

VCC (Power): Connect to the 5V pin

GND (Ground): All GND connect to the GND pins

3.3V (Logic): Connect to the 3.3V pin

SDI (MOSI): Connect to pin 11

SDO (MISO): Connect to pin 12

SCK: Connect to pin 13

NSS (CS): Connect to pin 10

RST (Reset): Connect to pin 9

DIO0: Connect to pin 2

DIO1: Connect to pin 3

TX_ENABLE: Connect to pin 5

RX_ENABLE: Connect to pin 4

so i set the controllers to loop into themselves to test the LEDs on the boards(rx and tx) when doing this both boards randomly would actually tx and rx, as i lowered the delay the uno received more and more actual tx from the mega.

but when i set each device to be a dedicated tx or rx, they don’t work. im currently using 1.221.1 Radiohead

heres the loop example:

#include <RadioLib.h>

// SX1276 requires the following connections:
int pin_cs = 10;        // Chip Select
int pin_dio0 = 2;       // DIO0
int pin_nrst = 9;       // Reset
int pin_dio1 = 3;       // DIO1
int pin_rx_enable = 4;  // RX Enable
int pin_tx_enable = 5;  // TX Enable

SX1276 radio = new Module(pin_cs, pin_dio0, pin_nrst, pin_dio1);

void setup() {
  Serial.begin(9600);  // Initialize serial communication at 9600 baud rate
  delay(500); // Wait for Arduino to be ready to print

  Serial.print("[SX1276] Initializing ... ");
  int state = radio.begin(915.0); // 915 gang
  if (state == RADIOLIB_ERR_NONE) {
    Serial.println("init success!");
  } else {
    Serial.print("failed, code ");
    Serial.println(state);
    while (true); // Halt execution if initialization fails
  }

  radio.setRfSwitchPins(pin_tx_enable, pin_rx_enable);
}

void loop() {
  Serial.print("[SX1276] Transmitting packet ... ");
  char output[] = "Hello, LoRa!";
  int state = radio.transmit(output);

  if (state == RADIOLIB_ERR_NONE) {
    Serial.println("success!");
  } else {
    Serial.print("failed, code ");
    Serial.println(state);
  }

  delay(1000); // Wait for a second before receiving

  Serial.print("[SX1276] Receiving packet ... ");
  String receivedMessage;
  state = radio.receive(receivedMessage);

  if (state == RADIOLIB_ERR_NONE) {
    Serial.print("Received message: ");
    Serial.println(receivedMessage);
  } else {
    Serial.print("Receive failed, code ");
    Serial.println(state);
  }

  delay(2000); // Wait before the next loop
}

Heres the rx code for the mega:

#include <RadioLib.h>

// SX1276 requires the following connections:
int pin_cs = 10;        // Chip Select
int pin_dio0 = 2;       // DIO0
int pin_nrst = 9;       // Reset
int pin_dio1 = 3;       // DIO1
int pin_rx_enable = 4;  // RX Enable
int pin_tx_enable = 5;  // TX Enable

SX1276 radio = new Module(pin_cs, pin_dio0, pin_nrst, pin_dio1);

void setup() {
  Serial.begin(9600);  // Initialize serial communication at 9600 baud rate
  delay(500); // Wait for Arduino to be ready to print

  Serial.print("[SX1276] Initializing ... ");
  int state = radio.begin(915.0); // Use the correct frequency for your region
  if (state == RADIOLIB_ERR_NONE) {
    Serial.println("init success!");
  } else {
    Serial.print("failed, code ");
    Serial.println(state);
    while (true); // Halt execution if initialization fails
  }

  radio.setRfSwitchPins(pin_tx_enable, pin_rx_enable);
}

void loop() {
  Serial.println("Checking for data...");
  if (radio.available()) {
    String receivedMessage;
    int state = radio.receive(receivedMessage);

    if (state == RADIOLIB_ERR_NONE) {
      Serial.print("Received message: ");
      Serial.println(receivedMessage);

      // Get and print the RSSI value
      int rssi = radio.getRSSI();
      Serial.print("RSSI: ");
      Serial.println(rssi);
    } else {
      Serial.print("Receive failed, code ");
      Serial.println(state);
    }
  } else {
    Serial.println("No data available");
  }

  delay(1000); // Adjust delay to ensure the receiver has time to process data
}

heres the uno’s tx code:

#include <RadioLib.h>

// SX1276 requires the following connections:
int pin_cs = 10;        // Chip Select
int pin_dio0 = 2;       // DIO0
int pin_nrst = 9;       // Reset
int pin_dio1 = 3;       // DIO1
int pin_rx_enable = 4;  // RX Enable
int pin_tx_enable = 5;  // TX Enable

SX1276 radio = new Module(pin_cs, pin_dio0, pin_nrst, pin_dio1);

int counter = 0;

void setup() {
  Serial.begin(9600);  // Initialize serial communication at 9600 baud rate
  delay(500); // Wait for Arduino to be ready to print

  Serial.print("[SX1276] Initializing ... ");
  int state = radio.begin(915.0); // 915 gang
  if (state == RADIOLIB_ERR_NONE) {
    Serial.println("init success!");
  } else {
    Serial.print("failed, code ");
    Serial.println(state);
    while (true); // Halt execution if initialization fails
  }

  radio.setRfSwitchPins(pin_tx_enable, pin_rx_enable);
  radio.setOutputPower(2); // Lower the transmission power for close distance
}

void loop() {
  Serial.print("[SX1276] Transmitting packet ... ");
  char output[50];
  sprintf(output, "Counter: %d", counter++);

  int state = radio.transmit(output);

  if (state == RADIOLIB_ERR_NONE) {
    Serial.println("success!");
  } else {
    Serial.print("failed, code ");
    Serial.println(state);
  }

  delay(1000); // Adjust delay to ensure receiver has time to process
}

is it me, the wires, how tx rx is being handled? please help! :?

Got it, figured it out… my issue was that i wasn’t syncing the devices properly. there were a set of parameters i didn’t even add to the code. here’s the proper code for anyone using these 2 microcontrollers.

the mega:

#include <RadioLib.h>

// SX1276 has the following connections:
#define CS_PIN          10
#define DIO0_PIN        2
#define RESET_PIN       9
#define DIO1_PIN        3

SX1276 radio = new Module(CS_PIN, DIO0_PIN, RESET_PIN, DIO1_PIN);

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

  // initialize SX1276 with default settings
  Serial.print(F("[SX1276] Initializing ... "));
  int state = radio.begin(915.0);
  if (state == RADIOLIB_ERR_NONE) {
    Serial.println(F("success!"));
  } else {
    Serial.print(F("failed, code "));
    Serial.println(state);
    while (true);
  }

  // Set additional parameters
  radio.setSyncWord(0x12);           // Set the sync word
  radio.setBandwidth(125.0);         // Set the bandwidth to 125 kHz
  radio.setSpreadingFactor(9);       // Set the spreading factor to 9
  radio.setCodingRate(7);            // Set the coding rate to 4/7
  radio.setOutputPower(10);          // Set output power to 10 dBm
  radio.setPreambleLength(8);        // Set preamble length to 8 symbols
  radio.setCRC(true);                // Enable CRC

  // Ensure RX and TX pins are correctly configured
  radio.setRfSwitchPins(-1, -1);  // If not using hardware switch pins
}

void loop() {
  // attempt to receive packet
  Serial.print(F("[SX1276] Receiving packet ... "));
  String str;
  int state = radio.receive(str);

  if (state == RADIOLIB_ERR_NONE) {
    Serial.println(F("success!"));

    // print data of the packet
    Serial.print(F("[SX1276] Data:\t"));
    Serial.println(str);

    // print RSSI (Received Signal Strength Indicator)
    Serial.print(F("[SX1276] RSSI:\t"));
    Serial.print(radio.getRSSI());
    Serial.println(F(" dBm"));

  } else if (state == RADIOLIB_ERR_RX_TIMEOUT) {
    Serial.println(F("timeout!"));

  } else if (state == RADIOLIB_ERR_CRC_MISMATCH) {
    Serial.println(F("CRC error!"));

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

  delay(1000);  // Delay to avoid flooding the serial output
}

the uno:

#include <RadioLib.h>
#include <SPI.h>

// Define connections
#define NSS 10  // Chip Select
#define DIO0 2  // DIO0
#define RST 9   // Reset
#define DIO1 3  // DIO1

SX1276 radio = new Module(NSS, DIO0, RST, DIO1);

int counter = 0;

void setup() {
  Serial.begin(9600);  // Initialize serial communication
  delay(500);  // Wait for serial to be ready

  Serial.print("[SX1276] Initializing ... ");
  int state = radio.begin(915.0);  // Initialize at 915 MHz
  if (state == RADIOLIB_ERR_NONE) {
    Serial.println("Initialization success!");
  } else {
    Serial.print("Initialization failed, code ");
    Serial.println(state);
    while (true);  // Halt if initialization fails
  }

  // Set additional parameters
  radio.setSyncWord(0x12);           // Set the sync word
  radio.setBandwidth(125.0);         // Set the bandwidth to 125 kHz
  radio.setSpreadingFactor(9);       // Set the spreading factor to 9
  radio.setCodingRate(7);            // Set the coding rate to 4/7
  radio.setOutputPower(10);          // Set output power to 10 dBm
  radio.setPreambleLength(8);        // Set preamble length to 8 symbols
  radio.setCRC(true);                // Enable CRC

  // Ensure RX and TX pins are correctly configured
  radio.setRfSwitchPins(-1, -1);  // If not using hardware switch pins
}

void loop() {
  Serial.print("[SX1276] Transmitting packet ... ");
  char output[50];
  sprintf(output, "Counter: %d", counter++);

  int state = radio.transmit(output);

  if (state == RADIOLIB_ERR_NONE) {
    Serial.println("success!");
  } else {
    Serial.print("failed, code ");
    Serial.println(state);
  }

  delay(1000);  // Wait for a second before transmitting the next packet
}