Unable to configure Lilygo LoRa T-Beam 433 Mhz

I am using two t-beams one of which acts as a transmitter connected to a DS18B20 temperature probe and the other t-beam acting as a receiver. now I have used the IDE software to configure both the devices. however the sender and receiver is just able to communicate with each other, the sender says packets sent, the receiver says packets received but the receiver is just not displaying the temperature data or any data per say. I had tested the Lora example code for sender and receiver (to send "Hello world") but that too doesn't work I'm just very unsure why the example code isn't functioning too. please help.
here's the sender code I'm using

#include <OneWire.h>
#include <DallasTemperature.h>
#include <LoRa.h>
#include <SPI.h>

// Pin definitions for LoRa module
#define LORA_SS 18
#define LORA_RST 23
#define LORA_DIO0 26

// Pin definition for DS18B20
#define ONE_WIRE_BUS 22

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

void setup() {
  Serial.begin(115200);
  Serial.println("LoRa Sender");

  sensors.begin();

  // Setup LoRa transceiver module
  LoRa.setPins(LORA_SS, LORA_RST, LORA_DIO0);
  LoRa.setSPIFrequency(1E6); 
  Serial.println("Initializing LoRa...");
  if (!LoRa.begin(433E6)) {
    Serial.println("Starting LoRa failed!");
    while (1);
  }

  LoRa.setTxPower(17);
  LoRa.setSpreadingFactor(12);
  LoRa.setCodingRate4(8);
  LoRa.setSignalBandwidth(250E3);
  LoRa.setSpreadingFactor(12); // Adjust spreading factor as needed
  LoRa.setSignalBandwidth(125E3); // Adjust bandwidth as needed
  
  Serial.println("LoRa initialized successfully!");
}

void loop() {
  sensors.requestTemperatures();
  float temperatureC = sensors.getTempCByIndex(0);
  Serial.print("Preparing to send temperature: ");
  Serial.println(temperatureC);

  char tempBuffer[10]; // Buffer for temperature string
  dtostrf(temperatureC, 4, 2, tempBuffer); // Convert float to string

  // Send temperature over LoRa

  LoRa.beginPacket();
  LoRa.print("TEMP:"); // Add a prefix for data identification
  LoRa.print(tempBuffer);

  if (LoRa.endPacket(true)) {
    Serial.println("Packet sent successfully!");
  } else {
    Serial.println("Packet send failed.");
  }

  delay(1000);
}

The receiver code is as follows:

#include <LoRa.h>
#include <SPI.h>

// LoRa module pin definitions
#define LORA_SS 18
#define LORA_RST 23
#define LORA_DIO0 26

void setup() {
  Serial.begin(115200);
  Serial.println("LoRa Receiver");

  // Setup LoRa transceiver module
  LoRa.setPins(LORA_SS, LORA_RST, LORA_DIO0);
  LoRa.setSPIFrequency(1E6);   
  if (!LoRa.begin(433E6)) {
    Serial.println("Starting LoRa failed!");
    while (1);
  }
  LoRa.setTxPower(17);
  LoRa.setSpreadingFactor(12);
  LoRa.setCodingRate4(8);
  LoRa.setSignalBandwidth(250E3);

  Serial.println("LoRa initialized successfully!");
}

void loop() {
  Serial.println("Checking for packets...");
  
  int packetSize = LoRa.parsePacket(5000); // Increase the timeout
  if (packetSize) {
    Serial.print("Received packet with size: ");
    Serial.println(packetSize);

    String received = "";
    while (LoRa.available()) {
      received += (char)LoRa.read();
    }

    Serial.print("Temperature data received: ");
    Serial.println(received);
  } else {
    Serial.println("No packet received.");
  }

  delay(1000); // Check for packets every 1 second
}

in this picture sometimes after a point I get the data but the data is a garbage data, as in nothing shows up

I would also like to say that I have not just used Arduino IDE ive also used Platform IO and the Meshtastic app as well, however the data doesn't show up there either
Use code tags to format code for the forum(temperature details)

That suggests a fundamental wiring, module or configuration error.

The LoRa example code for sender and receiver, does work, so what error do you get with those known working examples ?

I have connected both the LoRa devices to laptops which are also the power source for the LoRa devices. I have also configured the LoRA CS, RST and DIO pins as per the specification sheet. There are no errors thrown and I'm receiving 1 from LoRa.endpacket(true) callback in the sender script. Although on the receiving side, no packets are being received. LoRa.parsePacket() returns 0 as the packet size.

I have also tried putting these devices on external 3.7V battery but it didn't change the behaviour. Is there something I can do debug this issue?

On the sender side, print what you send just to be sure something is going out.
I have a couple of those and they came with sample code that works. Maybe try that so you can prove the two radios work or not.

So you have tried the library examples 'LoRaSender' and 'LoRaReceiver' and the only changes you made were to set the NSS, RST, DIO0 pins to the correct GPIOs and used LoRa.begin(433E6) ?

Yes, I'm using the example from File>Examples>LoRa>LoRaSender and File>Examples>LoRa>LoRaReceiver. If I don't set the pins for CS, RST, DIO0 then I get an error saying "Starting LoRa failed!". And LoRa.begin(433E6) is being used in both the devices.

Here is the data sheet for my LoRa device:
Link to datasheet

Thank you for the suggestion but I have one doubt regarding this. If I do Serial.print on the sender side then how does it verify if the radios are working? Or am I missing something here? I'm new to LoRa modules, are there any other kind of print calls that I can do?

To write to the LoRa, I use LoRa.print("hello") but this will not be printed on the sender device right?

The void loop() is being called every 5 seconds and which I have verified through the Serial.print lines.

Try this test program on both devices, its standalone, it checks the registers on the LoRa device can be read correctly;


/*******************************************************************************************************
  Program Operation - This program is stand alone, it is not necessary to install a LoRa library to use
  it. This test program is for the SX127X LoRa devices.

  The program checks that a LoRa device can be accessed by doing a test register write and read.
  If there is no device found a message is printed on the serial monitor. The contents of the registers
  from 0x00 to 0x0F are then printed.

  The Arduino pin number that NSS on the LoRa device is connected to must be specified in #define NSS
  line below. The DIO0 pin is not needed and you can leave the NRESET not connected as well.

  Typical printout;

  85_SX127X_LoRa_Device_Check Starting
  LoRa Device found
  Device version 0x12
  Frequency 434000000

  Registers
  Reg    0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F
  0x00  00 09 1A 0B 00 52 6C 80 00 4F 09 2B 20 08 02 0A

  Note: An SX1272 will report as version 0x22 and the frequency at power up is 915000000hz.

  ESP32
  -----
  For an ESP32 microcontroller you can specify the SCK, MOSI and MOSI pins used by the SPI interface by
  adding these defines;

  #define SCK 14
  #define MISO 12
  #define MOSI 13

  Then begin the SPI interface like this;

  SPI.begin(SCK, MISO, MOSI);


  Serial monitor baud rate is set at 115200.
*******************************************************************************************************/

const uint8_t REG_FRMSB = 0x06;                 //register number for setting and reading frequency, high byte
const uint8_t REG_FRMID = 0x07;                 //register number for setting and reading frequency, mid byte
const uint8_t REG_FRLSB = 0x08;                 //register number for setting and reading frequency, low byte
const uint8_t REG_VERSION = 0x42;               //register containg version number of device


//*********  Setup hardware pin definition here ! **************
#define NSS 18                                  //LoRa device select
#define NRESET 23                               //can be left not connected for this test program

#define SCK 5                                   //for ESP32, make sure the pin is avaialble to use on the ESP32
#define MISO 19                                 //for ESP32, make sure the pin is avaialble to use on the ESP32
#define MOSI 27                                 //for ESP32, make sure the pin is avaialble to use on the ESP32  
//**************************************************************/

#include <SPI.h>

uint32_t frequency;


void setup()
{
  Serial.begin(115200);
  Serial.println(F("85_SX127X_LoRa_Device_Check_ESP32 Starting"));

  SPI.begin(SCK, MISO, MOSI);                  //for ESP32

  SPI.beginTransaction(SPISettings(8000000, MSBFIRST, SPI_MODE0));

  //The begin function setups the hardware pins used by device and then checks if device is found
  if (begin(NSS, NRESET))
  {
    Serial.println(F("LoRa Device found"));
  }
  else
  {
    Serial.println(F("No device responding"));
  }

  Serial.print(F("Device version 0x"));
  uint8_t deviceversion = readRegister(REG_VERSION);

  if (deviceversion < 0x10)
  {
    Serial.print(F("0"));
  }
  Serial.println(deviceversion, HEX);

  frequency = getFreqInt();                    //read the default set frequency following a powerup
  Serial.print(F("Frequency "));
  Serial.println(frequency);
  Serial.println();
  Serial.println(F("Registers "));             //show registers
  printRegisters(0x00, 0x0F);
}


void loop()
{
}


uint8_t readRegister(uint8_t address)
{
  uint8_t regdata;
  digitalWrite(NSS, LOW);                    //set NSS low
  SPI.transfer(address & 0x7F);              //mask address for read
  regdata = SPI.transfer(0);                 //read the byte
  digitalWrite(NSS, HIGH);                   //set NSS high
  return regdata;
}


void writeRegister(uint8_t address, uint8_t value)
{
  digitalWrite(NSS, LOW);                    //set NSS low
  SPI.transfer(address | 0x80);              //mask address for write
  SPI.transfer(value);                       //write the byte
  digitalWrite(NSS, HIGH);                   //set NSS high
}


void printRegisters(uint16_t Start, uint16_t End)
{
  //prints the contents of lora device registers to serial monitor
  uint16_t Loopv1, Loopv2, RegData;

  Serial.print(F("Reg    0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F"));
  Serial.println();

  for (Loopv1 = Start; Loopv1 <= End;)
  {
    Serial.print(F("0x"));
    if (Loopv1 < 0x10)
    {
      Serial.print(F("0"));
    }
    Serial.print((Loopv1), HEX);
    Serial.print(F("  "));
    for (Loopv2 = 0; Loopv2 <= 15; Loopv2++)
    {
      RegData = readRegister(Loopv1);
      if (RegData < 0x10)
      {
        Serial.print(F("0"));
      }
      Serial.print(RegData, HEX);
      Serial.print(F(" "));
      Loopv1++;
    }
    Serial.println();
  }
}


bool begin(int8_t pinNSS, int8_t pinNRESET)
{
  pinMode(pinNSS, OUTPUT);
  digitalWrite(pinNSS, HIGH);

  pinMode(pinNRESET, OUTPUT);
  digitalWrite(pinNRESET, HIGH);
  delay(10);
  digitalWrite(pinNRESET, LOW);
  delay(10);
  digitalWrite(pinNRESET, HIGH);

  if (checkDevice())
  {
    return true;
  }

  return false;
}


bool checkDevice()
{
  //check there is a device out there, writes a register and reads back
  uint8_t Regdata1, Regdata2;
  Regdata1 = readRegister(REG_FRMID);               //low byte of frequency setting
  writeRegister(REG_FRMID, (Regdata1 + 1));
  Regdata2 = readRegister(REG_FRMID);               //read changed value back
  writeRegister(REG_FRMID, Regdata1);               //restore register to original value

  if (Regdata2 == (Regdata1 + 1))
  {
    return true;
  }
  else
  {
    return false;
  }
}


uint32_t getFreqInt()
{
  //get the current set LoRa device frequency, return as long integer
  uint8_t Msb, Mid, Lsb;
  uint32_t uinttemp;
  float floattemp;
  Msb = readRegister(REG_FRMSB);
  Mid = readRegister(REG_FRMID);
  Lsb = readRegister(REG_FRLSB);
  floattemp = ((Msb * 0x10000ul) + (Mid * 0x100ul) + Lsb);
  floattemp = ((floattemp * 61.03515625) / 1000000ul);
  uinttemp = (uint32_t)(floattemp * 1000000);
  return uinttemp;
}

I ran the programs on both the devices. These are the outputs from the devices.

Output from device 1:

Output from device 2:

i have same problem buddy thanks for your guidance.

So both LoRa devices appear to be responding over SPI.

You need something to check that the transmitter is actually transmitting, say an SDR or a UHF handheld transceiver.

It is an admittedly poor test, but at this point you do not have any idea if there is any data being sent. This test at least proves the variable being sent does contain data. The rule in debugging is never assume anything.

I don't have SDR right now. But to test if they are transmitting data, I set them up from "Meshtastic App" which supports the boards natively. I connected one mobile device to one LoRa device and another one to another mobile device. I am able to send and receive messages from the app.

Just as a precaution, the mobile devices were on aeroplane mode and the distance between the devices was around 50 meters. Is this a valid test to check the same? Or do I still need to validate through SDR? If you need any more details, feel free to ask.

If the LoRa device work through Meshtastic, then presumably they are working.

Not sure why the T-Beams dont appear to work through the LoRa.h library.

One potential issue is the AXP2101 power management that is used on the T-Beams, the Meshtastic software appears to set the AXP2101 up, I doubt the LoRa.h library does, but normally the AXP2101 defaults are OK.