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);
}