ULTIMAGE gps AND LoRa radio 433MHz, RX TX problems

Hello all, I'm working on an arduino project that uses several modules including the LoRa grove radio 433MHz (from seeedstudio) and the Ultimate gps Adafruit.

The fact is that these 2 modules communicate with my microcontroller (Mega2560 PRO (embed) CH-340G / ATmega2560-16AU from RobotDyn) on serial ports.

Ultimate gps : 10-9 RX TX
LoRa: 13-14 RX TX

What happens is that the last of the 2 modules I initialized in my Setup will work in the rest of the code, but not the first module.
I did several tests to identify the problem and i'm sure it comes from that.
For example if I initiate the GPS before the Lora, the Lora will work but the gps and vice versa.
I think I should use the.listen() function, but being a young arduino amateur I don't yet know how to use this function correctly.
Help wouldn't be a refusal.

Here is my code: (Gps init first before LoRa, gps not working. If i do the opposite init, Gps work)

#include <BlockDriver.h>
#include <FreeStack.h>
#include <MinimumSerial.h>
#include <SdFat.h>
#include <SdFatConfig.h>
#include <sdios.h>
#include <SysCall.h>
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_GPS.h>
#include <SoftwareSerial.h>

#include <RH_RF95.h>

#include <Adafruit_INA260.h>

Adafruit_INA260 ina260 = Adafruit_INA260();
Adafruit_INA260 ina260B = Adafruit_INA260();

SdFat SD;

const int chipSelect = 53;

SoftwareSerial mySerial(10, 9);
Adafruit_GPS GPS(&mySerial);
#define GPSECHO  true

#ifdef __AVR__
SoftwareSerial SSerial(13,14); // RX, TX
#define COMSerial SSerial
#define ShowSerial Serial 

RH_RF95<SoftwareSerial> rf95(COMSerial);
#endif

#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE
#define COMSerial Serial1
#define ShowSerial SerialUSB 

RH_RF95<Uart> rf95(COMSerial);
#endif

#ifdef ARDUINO_ARCH_STM32F4
#define COMSerial Serial
#define ShowSerial SerialUSB 

RH_RF95<HardwareSerial> rf95(COMSerial);
#endif

struct datax{
  unsigned long ms;
  float cur_A;
  float power_A;
  float voltage_A;
  float energy_A;
  float cur_B;
  float power_B;
  float voltage_B;
  float energy_B;
  
  int annee;
  int mois;
  int jours;
  int heure;
  int minuts;
  int sec;
  
  int latitude;
  float lat;
  int longitude;
  float longe;
  int altitudz;
  
  //float windspeed;
}datasend;

float cur_A = 0;
float powe_A = 0;
float volt_A = 0;
float energy_A = 0;

float cur_B = 0;
float powe_B = 0;
float volt_B = 0;
float energy_B = 0;


//        TEMPS
unsigned long previousMillis = 0;
unsigned long interval = 1000;
unsigned long currentMillis;

void setup() {
  Serial.begin(115200);
  delay(5000);
  
  GPS.begin(9600);
  
  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
  GPS.sendCommand(PGCMD_ANTENNA);

    
  if (!ina260.begin(0x40)) {
    Serial.println(F("Couldn't find INA260 chip"));
    while (1);
  }
  if (!ina260B.begin(0x41)) {
    Serial.println(F("Couldn't find INA260B chip"));
    while (1);
  }
  if (!SD.begin(chipSelect)){
    Serial.println(F("Couldn't find SD chip"));
    while (1);
  }
  if (!rf95.init()){
    Serial.println(F("Couldn't find LoRa chip"));
    while(1);
  }
  rf95.setTxPower(20, false);
  rf95.setFrequency(434.0);


  
  Serial.println(F("Found INA260-INA260B-SD-LoRa chips"));

  File DataFile = SD.open("datalog.txt",FILE_WRITE);
  if (DataFile){
    DataFile.println(F("Found INA260-INA260B-SD-LoRa chips")); //1 
    DataFile.print(F("CurrentA_mA;"));                    //2
    DataFile.print(F("CurrentB_mA;"));                    //3
    DataFile.print(F("busVoltageA_mV;"));                 //4
    DataFile.print(F("busVoltageB_mV;"));                 //5
    DataFile.print(F("PowerA_mW;"));                      //6
    DataFile.print(F("PowerB_mW;"));                      //7
    DataFile.print(F("EnergyA_mWH;"));                    //8
    DataFile.print(F("EnergyB_mWH;"));                    //9
    DataFile.print(F("Temps_mS;"));                       //10
    DataFile.print(F("Heure;"));                          //11
    DataFile.print(F("Date;"));                           //12
    DataFile.print(F("FIX;"));                            //13
    DataFile.print(F("Latitude;"));                       //14
    DataFile.print(F("Longitude;"));                      //15
    DataFile.print(F("Altitude;"));                       //16
    DataFile.println(F("XXX;"));                          //17
    DataFile.close();
  }
}

and the LOOP part :

void loop() {
  
  char c = GPS.read();
  // if you want to debug, this is a good time to do it!
  if ((c) && (GPSECHO))
  Serial.write(c);  

  currentMillis = millis();
  if (currentMillis - previousMillis >=interval){
    
    previousMillis = currentMillis;
    
    if (GPS.newNMEAreceived()) {
      if (!GPS.parse(GPS.lastNMEA()))   // this also sets the newNMEAreceived() flag to false
      return;  // we can fail to parse a sentence in which case we should just wait for another
      }
    Serial.print(F("\nTime: "));
    if (GPS.hour < 10) { Serial.print('0'); }
    Serial.print(GPS.hour, DEC); Serial.print(':');
    if (GPS.minute < 10) { Serial.print('0'); }
    Serial.print(GPS.minute, DEC); Serial.print(':');
    if (GPS.seconds < 10) { Serial.print('0'); }
    Serial.print(GPS.seconds, DEC); Serial.print('.');
    if (GPS.milliseconds < 10) {
      Serial.print(F("00"));
    } 
    else if (GPS.milliseconds > 9 && GPS.milliseconds < 100) {
      Serial.print("0");
    }
    Serial.println(GPS.milliseconds);
    Serial.print(F("Date: "));
    Serial.print(GPS.day, DEC); Serial.print('/');
    Serial.print(GPS.month, DEC); Serial.print(F("/20"));
    Serial.println(GPS.year, DEC);
    Serial.print(F("Fix: ")); Serial.print((int)GPS.fix);
    Serial.print(F(" quality: ")); Serial.println((int)GPS.fixquality);
    if (GPS.fix) {
      Serial.print(F("Location: "));
      Serial.print(GPS.latitude, 4); Serial.print(GPS.lat);
      Serial.print(F(", "));
      Serial.print(GPS.longitude, 4); Serial.println(GPS.lon);
  
      Serial.print(F("Speed (knots): ")); Serial.println(GPS.speed);
      Serial.print(F("Angle: ")); Serial.println(GPS.angle);
      Serial.print(F("Altitude: ")); Serial.println(GPS.altitude);
      Serial.print(F("Satellites: ")); Serial.println((int)GPS.satellites);
      
    }
    Serial.println();

    cur_A = ina260.readCurrent();
    powe_A = ina260.readPower();
    volt_A = ina260.readBusVoltage();
    energy_A = powe_A/3600.0 + energy_A;

    cur_B = ina260B.readCurrent();
    powe_B = ina260B.readPower();
    volt_B = ina260B.readBusVoltage();
    energy_B = powe_B/3600.0 + energy_B;

    datasend.ms = currentMillis;
    datasend.cur_A = cur_A;
    datasend.power_A = powe_A;
    datasend.voltage_A = volt_A;
    datasend.energy_A = energy_A;
    datasend.cur_B = cur_B;
    datasend.power_B = powe_B;
    datasend.voltage_B = volt_B;
    datasend.energy_B = energy_B;
    datasend.annee = (GPS.year);
    datasend.mois = (GPS.month);
    datasend.jours = (GPS.day);
    datasend.heure = (GPS.hour);
    datasend.minuts = (GPS.minute);
    datasend.sec = (GPS.seconds);
    datasend.latitude = (GPS.latitude, 4);
    datasend.lat = (GPS.lat);
    datasend.longitude = (GPS.longitude, 4);
    datasend.longe = (GPS.lon);
    datasend.altitudz = (GPS.altitude);
    //datasend.windspeed = windSpeed;

    rf95.send((uint8_t*)&datasend,sizeof(datasend));
    rf95.waitPacketSent();
  
    Serial.print(F("Current: "));
    Serial.print(cur_A);
    Serial.print(F("   "));
    Serial.print(cur_B);
    Serial.println(F(" mA"));
  
    Serial.print(F("Bus Voltage: "));
    Serial.print(volt_A);
    Serial.print(F("   "));
    Serial.print(volt_B);
    Serial.println(F(" mV"));
  
    Serial.print(F("Power: "));
    Serial.print(powe_A);
    Serial.print(F("   "));
    Serial.print(powe_B);
    Serial.println(F(" mW"));

    Serial.print(F("Energy: "));
    Serial.print(energy_A);
    Serial.print(F("   "));
    Serial.print(energy_B);
    Serial.println(F(" mW"));

    File DataFile = SD.open("datalog.txt",FILE_WRITE);
    if (DataFile){
      DataFile.print(cur_A);              //2
      DataFile.print(F(";"));
      DataFile.print(cur_B);              //3
      DataFile.print(F(";"));    
      DataFile.print(volt_A);             //4
      DataFile.print(F(";"));
      DataFile.print(volt_B);             //5
      DataFile.print(F(";"));
      DataFile.print(powe_A);             //6
      DataFile.print(F(";")); 
      DataFile.print(powe_B);             //7
      DataFile.print(F(";"));
      DataFile.print(energy_A);           //8
      DataFile.print(F(";")); 
      DataFile.print(energy_B);           //9
      DataFile.print(F(";"));
      DataFile.print(currentMillis);                  //10
      DataFile.print(F(";"));
      DataFile.print(GPS.hour, DEC);                  //11
      DataFile.print(F(":"));
      DataFile.print(GPS.minute, DEC);                //11
      DataFile.print(F(":"));
      DataFile.print(GPS.seconds, DEC);               //11
      DataFile.print(F(";"));
      DataFile.print(GPS.day, DEC);                   //12
      DataFile.print(F("/"));
      DataFile.print(GPS.month, DEC);                 //12
      DataFile.print(F("/"));
      DataFile.print(GPS.year, DEC);                  //12
      DataFile.print(F(";"));
      DataFile.print((int)GPS.fix);                   //13
      DataFile.print(F(";"));
      DataFile.print(GPS.latitude, 4); DataFile.print(GPS.lat);  //14
      DataFile.print(F(";"));
      DataFile.print(GPS.longitude, 4); DataFile.print(GPS.lon); //15
      DataFile.print(F(";"));
      DataFile.print(GPS.altitude);                   //16
      DataFile.println(F(";"));   
      DataFile.close();
    }
  }
}

The fact is that these 2 modules communicate with my microcontroller (Mega2560 PRO (embed) CH-340G / ATmega2560-16AU from RobotDyn) on serial ports.

A Mega has 4 hardware serial ports. Unless you have a reason that is better than "because I don't know how", you should NOT be using SoftwareSerial when you have unused hardware serial ports.

So you're suggesting that I should use the hardwareserial tx rx of my arduino instead of using the softwareserial?

Quentin78:
So you're suggesting that I should use the hardwareserial tx rx of my arduino instead of using the softwareserial?

Yes. One of them for each device.

Did it, it works. THANKS.

But, I'm interested, why and how serial hardware is better than softwareserial. And why use one over the other?
For me serial software will use resources, more resources compared to hardware.

But, I'm interested, why and how serial hardware is better than softwareserial.

It is better, for some definitions of better, because the hardware handles the incoming/outgoing serial data without the need for any software to monitor the pins that are being used for software serial. Because the software isn't spending most of its time checking for incoming serial data, or outputting serial data, the software can do other things.

And why use one over the other?

Any time you have hardware that can do something, let it.

For me serial software will use resources, more resources compared to hardware.

Lots more.

Thank you for explanations, and your time!

Qh