LoRa.endPacket();freezes

I am trying to merge programmes, thats SoftwareSerial,RTC and LoRa.

Each programme works fine seperately and Software Serial and RTC play nice togrther.
However when I add Lora to the mix I get a program that freezes at the "LoRa.endPacket();" line and wont go any further.

Looking for advice on what I might be doing wrong this time.

t//...................................................................SENDER.........................SENDER..........................
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 9);//RX, TX //

//   ............................................    RTC   .............................
#include <Wire.h>
#include <ds3231.h>
struct ts t;
//   ............................................    LORA   .............................
#include <SPI.h>
#include <LoRa.h>
byte localAddress = 0xAA;
byte destinationAddress = 0xBB;
//.......................................................   VARIABLES   ....................
int houR = 0;
int miN = 0;
int seC = 0;
int miN1 = 0;//   To change clock once a minute
int staT = 0;
int  te = 0;//       DELETE   Just for testing                                                               DELETE   Just for testing
int adjtime = 54;//       DELETE   Just for testing  Set to currenr miN for testing stations                  DELETE   Just for testing

long lastSendTime = 0;

void setup() {
  Serial.begin(9600); //open the hardware serial port
  Serial.println("Serial On"); //Print this messages when the serial port is connected
  mySerial.begin(9600); // set the data rate for the SoftwareSerial port

  //............................................................   SET UP RTC   ..........
  Wire.begin();
  DS3231_init;

  //..............................................................   SET TIME   ...........
  //t.hour = 16; t.min = 37; t.sec = 10; t.mday = 5; t.mon = 11; t.year = 2021;
  //DS3231_set(t);

  //.............................................................   STARTING LORA   ....................
  Serial.println("Start LoRa duplex  TX  Sender");
  if (!LoRa.begin(915E6)) {
    Serial.println("LoRa init failed. Check your connections.");
    while (true) {}
  }
}
//...........................................................................   VOID NEXTION END ROUTINE    ..............
void NexEnd() {
  mySerial.write(0xff);
  mySerial.write(0xff);
  mySerial.write(0xff);

}
//...........................................................................    VOID WRITE STRING TO NEXTION    ..........,
void writeString(String stringData) { // Used to serially push out a String with Serial.write()

  for (int i = 0; i < stringData.length(); i++)
  {
    mySerial.write(stringData[i]);   // Push each char 1 by 1 on each loop pass
  }
  NexEnd();
}
//..............................................................................   SEND TIME TO NEXTION   ...................
void neXtimE() {


  mySerial.print(F("t0.txt=\""));       //   make sure t number is correct
  mySerial.print(F("Time "));
  mySerial.print(houR);
  mySerial.print(F(":"));
  mySerial.print(miN);
  mySerial.print(F("\""));
  mySerial.write(0xff);
  mySerial.write(0xff);
  mySerial.write(0xff);
}

//..............................................................   VOID SENDING DATA   ...........................
void senddatA()
{

  Serial.println("  VOID SENDDATA");
  String sensorData = String(staT);
  Serial.println("  string to string");
  sendMessage(sensorData);
  //Serial.print("  SENT            " + sensorData); Serial.print("               at  ");        //timE();
  // Serial.print(" from 0x" + String(localAddress, HEX));
  // Serial.println(" to 0x" + String(destinationAddress, HEX));

  Serial.println("  GOING TO SEND MESSAGE");

}
//.............................................................   VOID SEND MESSAGE   .............................
void sendMessage(String outgoing) {
  Serial.println("  start send message");

  LoRa.beginPacket();
  Serial.println("  lora begin packet");
  LoRa.write(destinationAddress);
  Serial.println("  destination address");
  LoRa.write(localAddress);
  Serial.println("  local address");
  LoRa.write(outgoing.length());
  Serial.println("  after outgoing length");
  LoRa.print(outgoing);
  Serial.println("  after outgoing");
  delay(100);
  LoRa.endPacket();
  Serial.println("  after end packet");
  Serial.println("  end send message");
}

//.................................................................................   VOID STATION   .......................
void statioN() {

  //  Adjust adjtime to current miN in Variable setup


  staT = 220;
  senddatA();
  Serial.println("  staT to SenddatA");
  mySerial.print("n22.font=1");
  NexEnd();
  mySerial.print("n22.pco=2016");
  NexEnd();



}
//................................................................................   VOID LOOP   ....................................
void loop() {

  DS3231_get(&t);
  houR = (t.hour);     // SET houR and miN and seC to current time
  miN = (t.min);
  seC = (t.sec);

  if ( miN1 != miN) {    //   Allows to print out only when Minute changes
    neXtimE();
    miN1 = miN;
    delay(100);
  }
  statioN();//
}ype or paste code here

Thanks for any assistance

Not telling us which Arduino you are using and providing a schematic of how its all wired maybe ?

I am using a Mega 2560 with a duinotech lora shield v1 attached.and a Nextion
TJC 4832T035_011 display.

Testing further it would seem that the line ," mySerial.print " ,is causing the freeze.
By deleting these "mySerial.print" lines from the sketch, it works "normally",yet the line
"mySerial.write" does not seem to cause any problem and the sketch works "normally".

Have you checked what pins the LoRa device is using for conflicts with your other connections ?

Thanks srnet, I had not thought to check the LoRa shield pinout.

Pin 9 was used by Lora so I changed the pins to 15 and 16 and all works just fine.

Tx for your help

And pin 10.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.