LoRa getting stuck on LoRa.endPacket(); Does not transmit

Hi! I have recently gotten into an issue where I have attempted to add LoRa communication to my project. When on its own, the LoRa works, but when combined with an SD, BMP280, and Adafruit ultimate breakout GPS, it seems to stop working. I am using a LoRa SX1278 with the LoRa library. I am using an Arduino Uno, and the wiring of the LoRa is shared with the SD card(except for the chip select). What can I do?

Full sketch(I currently don't have the Arduino setup on hand so I can't remember the exact wiring):

//BME
#include <avr/pgmspace.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>
//GPS
#include <TinyGPS.h>
#include <SoftwareSerial.h>
//SD
#include <SdFat.h>
//LoRa
#include <LoRa.h>






//LoRa
unsigned long dF = 433E6;






 


//SD
SdFat sd;


SdFile file;






const int LoRachipSelect = 4;
const int SDchipSelect = 10;




//BME
Adafruit_BMP280 bmp;


//BMP
SoftwareSerial ss(8,7); //MAYBE IT CANT GET THE PINS CAUSE OF IT BEING PROGMEM(CHECK THAT)
TinyGPS gps;




uint32_t timer = millis();
int temperature, pressure, altitude;






void setup()
{
   Serial.begin(115200);
   ss.begin(9600);  
   
  //BMP
  if (!bmp.begin(0x76)) {
   
    Serial.println(F("Could not find a valid BMP280 sensor, check wiring!"));
    //while (1);
  }
  Serial.println(F("BMP280 started"));
  //SD
  if (!sd.begin(SDchipSelect)) sd.initErrorHalt();


   //LoRa
 
Serial.println(F("Before LoRa initialization"));
  //Start Lora
  LoRa.setPins(LoRachipSelect);
  delay(10);
    if (!LoRa.begin(dF)) {
    Serial.println(F("Starting LoRa failed!"));
    while (1);
   }
   
 


 
  LoRa.setTxPower(14); // Set the transmit power (from 2 to 17)
//GPS




}
void loop()
{
  //GPS variables
  bool newData = false; //Checks for new data
  unsigned long chars; //Find chars
  unsigned short sentences, failed;


 
 


  Serial.print(F("Temp:"));
  Serial.print(bmp.readTemperature(), 2);
  Serial.print(F(" Press:"));
  Serial.print(bmp.readPressure() / 100, 2);
  Serial.print(F(" Alt:"));
  Serial.println(bmp.readAltitude(1013.25), 2);
  if (!file.open("PMData.txt")) {
    sd.errorHalt(F("opening PMData.txt for write failed"));
   
  } else
  {
    //Chekcs time
    for (unsigned long start = millis(); millis() - start < 1000;)
    {
      while (ss.available()) // Hopefully this is not an endless loop
      {
       
       
        char c = ss.read();
       
        if (gps.encode(c))
        {
          newData = true;
        }
         
      }
    }
    //If there is a fix/new data coming in.
    if (newData)
    {
     
      float flat, flon;
      unsigned long age;
       
      gps.f_get_position(&flat, &flon, &age);
      Serial.print(F("LAT="));
      Serial.print(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flat, 6);
      Serial.print(F(" LON="));
      Serial.print(flon == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flon, 6);
      Serial.print(F(" SAT="));
      Serial.print(gps.satellites() == TinyGPS::GPS_INVALID_SATELLITES ? 0 : gps.satellites());
      Serial.print(F(" PREC="));
      Serial.println(gps.hdop() == TinyGPS::GPS_INVALID_HDOP ? 0 : gps.hdop());


      //File
      file.print(F("Temp:"));
      file.print(bmp.readTemperature(), 2);
      file.print(F(" Press:"));
      file.print(bmp.readPressure() / 100, 2);
      file.print(F(" Alt:"));
      file.println(bmp.readAltitude(1013.25), 2);
      file.print(F("LAT="));
      file.print(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flat, 6);
      file.print(F("LON="));
      file.println(flon == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flon, 6);
      //LORA
     
      Serial.println("Saved to file");
      LoRa.beginPacket();
      LoRa.print(F("Temp"));
      LoRa.print(bmp.readTemperature(), 2);
      LoRa.print(F(" Press:"));
      LoRa.print(bmp.readPressure() / 100, 2);
      LoRa.print(F(" Alt:"));
      LoRa.println(bmp.readAltitude(1013.25), 2);
      LoRa.print(F("LAT="));
      LoRa.print(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flat, 6);
      LoRa.print(F("LON="));
      LoRa.println(flon == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flon, 6);
      Serial.println("Lora should end");
      LoRa.endPacket();
     
     
     
    }
    else
    {
      file.print(F("Temp:"));
      file.print(bmp.readTemperature(), 2);
      file.print(F(" Press:"));
      file.print(bmp.readPressure() / 100, 2);
      file.print(F(" Alt:"));
      file.println(bmp.readAltitude(1013.25), 2);
    LoRa.beginPacket();
      LoRa.print(F("Temp"));
      LoRa.print(bmp.readTemperature(), 2);
      LoRa.print(F(" Press:"));
      LoRa.print(bmp.readPressure() / 100, 2);
      LoRa.print(F(" Alt:"));
      LoRa.println(bmp.readAltitude(1013.25), 2);
      LoRa.write("Hi");
      delay(100);
    LoRa.endPacket();




      Serial.println(F("NoGPSData-NoFix"));
      file.println(F("NoGPSData-NoFix"));
    }


   


    file.close();


  }
  tone(9, 1000, 250);
 
 
  delay(1000);
 




}






You are likely to be running out of dynamic memory, in which case the fix is to move to an MCU with more memory, or lower the project requirements.

There may also be a conflict with the SD card module and other devices on the SPI bus. A hardware fix has been discussed on this forum. See this post for an example SPI MISO pin conflict

1 Like

Would reassigning the pins for either the SD card or the LoRa solve the possible conflict? Also, the SD card does not record any data either.

Also, if I let the LoRa endpacket() run asynchronously, it doesn't freeze the code, and has only once transmitted a message.

Depends on the SD card adapter you are using.

The standard one that people use on UNOs only allows one device to work on the SPI bus as suggested by @jremington.

Show us a picture\link of your SD card holder.

And what LoRa module are you using and how is it wired ?

The sd card holder is: https://grobotronics.com/adafruit-microsd-card-breakout-board.html?sl=en
The LoRa is the SX1278, LoRa Ra-02. The wiring is
SCK - 13 (shared with SD)
MISO - 12 (shared with SD)
MOSI - 11 (shared with SD)
NSS/CS - 4
DIO0 - 2
(for the LoRa)

Dont have any experience of that SD card module.

However LoRa and SD cards, properly designed, should work together. I have a handheld LoRa packet logger with OLED display and SD card, running and working on a Pro Mini on my desk.

And which LoRa module are you using !

It's the one I mentioned above. Here is the link I got it from: https://grobotronics.com/lora-module-433mhz-sx1278.html

Apologies I missed that.

That is a 3.3V logic level LoRa module, and needs logic level conversion circuits to connect it to a 5V logic level Arduino UNO.

Connect that module direct to a UNO and it could be damadged.

The LoRa module has been working on its own with an Uno before, and I have been using the 3.3V port on the Arduino. How would I convert to 3.3V?

Maybe it has worked before, but that does not mean its OK to connect it direct. Besides you now have a problem, so something is wrong ?

A google search on;

Arduino logic level conversion

Should find you lots of examples.

Myself, I would not use a LoRa module on a 5V Arduino, far less bother to just update to 3.3V logic Arduinos.

1 Like

Thanks! I found a few tutorials on the logic conversion. I really appreciate the help!

Oh, and another thing.

A UNO probably canoot provide enough current on its 3.3V pin to power a LoRa transmitter. Another good reason to use 3.3V logic Arduinos.

How come? In the future this logic will all be taken to a nano every, which still uses 5v.

What do you mean how come ?

As I recall some of the 5V logic Arduinos can only provide circa 50mA on the 3.3V pin, which is not really enough for a LoRa transmitter.

The Nano Every is also specified as only providing 50mA on the 3.3V pin, read the docs.

Switch to a 3.3V Arduino, much easier.

I searched through google a little bit and I saw that the uno can provide 100 to 150mA of current on the 3.3v pin, but you are right about the every.

Arduino UNO R3 specs says 3.3V pin is limited to 50mA.

But maybe its wrong.

My bad. I dont see why it would be wrong lol. The LoRa needs more than that though? How come it used to work?

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