Sending GPS Data with LORA

I have a GPS on my transmitter and want to send the lat and lon to a receiver. The transmitter and receiver are both "RFM96 LoRa Radio - 433MHz". I have gotten the basic "Hello World" with counter and "Hello back to you" to work with them. I believe the formatting on the packet for my GPS data is incorrect because the Serial Monitor prints my location correctly but when it prints the packet to be sent, it prints a random symbol which is received consistently by my receiver and displayed correctly. It correctly transmits the "N" after the random symbol that is supposed to be my latitude as well. I have changed my actual location but the format is the same. It's printed as 4 digits, one decimal then 4 more digits. I would like to eventually send latitude, longitude, speed and altitude to the receiver but if I can get started with just latitude, I could fail forwards from there. Thank you

Transmitter code

#include <SPI.h>
#include <RH_RF95.h>
#include <Adafruit_GPS.h>
#define GPSSerial Serial1
Adafruit_GPS GPS(&GPSSerial);
#define GPSECHO false

//for feather m0  
#define RFM95_CS 8
#define RFM95_RST 4
#define RFM95_INT 3

#if defined(ESP8266)
  /* for ESP w/featherwing */ 
  #define RFM95_CS  2    // "E"
  #define RFM95_RST 16   // "D"
  #define RFM95_INT 15   // "B"

#elif defined(ESP32)  
  /* ESP32 feather w/wing */
  #define RFM95_RST     27   // "A"
  #define RFM95_CS      33   // "B"
  #define RFM95_INT     12   //  next to A

#elif defined(NRF52)  
  /* nRF52832 feather w/wing */
  #define RFM95_RST     7   // "A"
  #define RFM95_CS      11   // "B"
  #define RFM95_INT     31   // "C"
  
#elif defined(TEENSYDUINO)
  /* Teensy 3.x w/wing */
  #define RFM95_RST     9   // "A"
  #define RFM95_CS      10   // "B"
  #define RFM95_INT     4    // "C"
#endif

#define RF95_FREQ 433.0

// Singleton instance of the radio driver
RH_RF95 rf95(RFM95_CS, RFM95_INT);

void setup() 
{
  pinMode(RFM95_RST, OUTPUT);
  digitalWrite(RFM95_RST, HIGH);

  Serial.begin(115200);
  Serial.println("Adafruit GPS library basic test!");
  GPS.begin(9600);
  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); // 1 Hz update rate
  delay(1000);
  GPSSerial.println(PMTK_Q_RELEASE);

  delay(100);

  Serial.println("Feather LoRa TX Test!");

  // manual reset
  digitalWrite(RFM95_RST, LOW);
  delay(10);
  digitalWrite(RFM95_RST, HIGH);
  delay(10);

  while (!rf95.init()) {
    Serial.println("LoRa radio init failed");
    Serial.println("Uncomment '#define SERIAL_DEBUG' in RH_RF95.cpp for detailed debug info");
    while (1);
  }
  Serial.println("LoRa radio init OK!");

  // Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM
  if (!rf95.setFrequency(RF95_FREQ)) {
    Serial.println("setFrequency failed");
    while (1);
  }
  Serial.print("Set Freq to: "); Serial.println(RF95_FREQ);
  
  // Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on

  // The default transmitter power is 13dBm, using PA_BOOST.
  // If you are using RFM95/96/97/98 modules which uses the PA_BOOST transmitter pin, then 
  // you can set transmitter powers from 5 to 23 dBm:
  rf95.setTxPower(23, false);
}

int16_t packetnum = 0;  // packet counter, we increment per xmission

void loop(){

float Lo = GPS.longitude;  
int Al = GPS.altitude;

delay(2000);  

char c = GPS.read();
  if (GPS.newNMEAreceived()) {
    Serial.println(GPS.lastNMEA()); // this also sets the newNMEAreceived() flag to false
    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
  }
    if (GPS.fix) {
      Serial.print(GPS.latitude, 4); Serial.print(GPS.lat);
      Serial.print(", ");
      Serial.print(GPS.longitude, 4); Serial.println(GPS.lon);
      Serial.print(GPS.speed); Serial.println("kn");
      Serial.print(GPS.altitude); Serial.println("m");
      delay(2000); 
  }
  
  delay(1000); // Wait 1 second between transmits, could also 'sleep' here!
  
  char radiopacket[20] = { GPS.latitude , GPS.lat };
  // itoa(packetnum++, radiopacket+6, 10);
  Serial.print("Sending "); Serial.println(radiopacket);
  //radiopacket[19] = 0;
  
  delay(10);
  rf95.send((uint8_t *)radiopacket, 20); //sends packet

  delay(10);
  rf95.waitPacketSent(); //waits for packet to complete sending
  // Now wait for a reply
  uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
  uint8_t len = sizeof(buf);

  Serial.print("RSSI: ");
  Serial.println(rf95.lastRssi(), DEC);    
}

Receiver Code

#include <SPI.h>
#include <RH_RF95.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH110X.h>
#include <Wire.h>

// for feather m0 RFM9x
#define RFM95_CS 8
#define RFM95_RST 4
#define RFM95_INT 3

Adafruit_SH110X display = Adafruit_SH110X(64, 128, &Wire);

// Change to 434.0 or other frequency, must match RX's freq!
#define RF95_FREQ 433.0

// Singleton instance of the radio driver
RH_RF95 rf95(RFM95_CS, RFM95_INT);

// Blinky on receipt
#define LED 13

void setup()
{
  pinMode(LED, OUTPUT);
  pinMode(RFM95_RST, OUTPUT);
  digitalWrite(RFM95_RST, HIGH);
  
  display.println("128x64 OLED FeatherWing test");
  display.begin(0x3C, true); // Address 0x3C default
 
  display.println("OLED begun");

  display.display();
  delay(1000);
 
  // Clear the buffer.
  display.clearDisplay();
  display.display();
 
  display.setRotation(1);
  display.setTextSize(1);
  display.setTextColor(SH110X_WHITE);
  display.setCursor(0,0);

  display.println("Feather LoRa RX Test!");
  display.display();
  delay(1000);

  // manual reset
  digitalWrite(RFM95_RST, LOW);
  delay(10);
  digitalWrite(RFM95_RST, HIGH);
  delay(10);

  while (!rf95.init()) {
    Serial.println("LoRa radio init failed");
    Serial.println("Uncomment '#define SERIAL_DEBUG' in RH_RF95.cpp for detailed debug info");
    while (1);
  }
  Serial.println("LoRa radio init OK!");
  delay(1000);

  // Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM
  if (!rf95.setFrequency(RF95_FREQ)) {
    Serial.println("setFrequency failed");
    while (1);
  }
  Serial.print("Set Freq to: "); Serial.println(RF95_FREQ);

  // Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on

  // The default transmitter power is 13dBm, using PA_BOOST.
  // If you are using RFM95/96/97/98 modules which uses the PA_BOOST transmitter pin, then
  // you can set transmitter powers from 5 to 23 dBm:
  rf95.setTxPower(23, false);
}

void loop()
{

  Serial.begin(115200);
  
  if (rf95.available())
  {
    // Should be a message for us now
    uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
    uint8_t len = sizeof(buf);

    if (rf95.recv(buf, &len))
    {
      display.clearDisplay();
      display.setCursor(0,0);
      digitalWrite(LED, HIGH);
      RH_RF95::printBuffer("Received: ", buf, len);
      display.print("Got: ");
      display.println((char*)buf);
      display.println((char*)buf);
      display.print("RSSI: ");
      display.println(rf95.lastRssi(), DEC);
      display.display();

      // Send a reply
      uint8_t data[] = "And hello back to you";
      rf95.send(data, sizeof(data));
      rf95.waitPacketSent();
      Serial.println("Sent a reply");
      delay(1000);

    }
  }
}

Serial Monitor for transmitter

21:10:00.914 -> Sending ⸮N
21:10:00.962 -> RSSI: 0
21:10:03.007 -> 1234.5678N, 1234.5678W
21:10:03.007 -> 0.00kn
21:10:03.007 -> 527.70m

LED display on Receiver
Got: ⸮N
⸮N
RSSI: -20

1 Like

This won't work. You need to either fill the buffer byte by byte with binary values, or formatted values, or just send the variables themselves.

  char radiopacket[20] = { GPS.latitude , GPS.lat };

An example of sending a single four byte float variable is:

rf95.send((uint8_t *) &GPS.latitude,4); //sends 4 byte latitude value in binary

Depending on which Arduino you are using, you can fill and transmit a formatted character (text) buffer with floating point values using sprintf() or dtostrf().

My board doesn't support dtostrf() so I would like to send the variables themselves. However when I try, it still comes out as gibberish. I get the same print out on the transmitter serial monitor and the receiver OLED

#include <SPI.h>
#include <RH_RF95.h>
#include <Adafruit_GPS.h>
#include <Adafruit_SHT31.h>
#define GPSSerial Serial1
Adafruit_GPS GPS(&GPSSerial);
#define GPSECHO false

Adafruit_SHT31 sht30;  // humidity

//for feather m0  
#define RFM95_CS 8
#define RFM95_RST 4
#define RFM95_INT 3

#if defined(ESP8266)
  /* for ESP w/featherwing */ 
  #define RFM95_CS  2    // "E"
  #define RFM95_RST 16   // "D"
  #define RFM95_INT 15   // "B"

#elif defined(ESP32)  
  /* ESP32 feather w/wing */
  #define RFM95_RST     27   // "A"
  #define RFM95_CS      33   // "B"
  #define RFM95_INT     12   //  next to A

#elif defined(NRF52)  
  /* nRF52832 feather w/wing */
  #define RFM95_RST     7   // "A"
  #define RFM95_CS      11   // "B"
  #define RFM95_INT     31   // "C"
  
#elif defined(TEENSYDUINO)
  /* Teensy 3.x w/wing */
  #define RFM95_RST     9   // "A"
  #define RFM95_CS      10   // "B"
  #define RFM95_INT     4    // "C"
#endif

#define RF95_FREQ 433.0

// Singleton instance of the radio driver
RH_RF95 rf95(RFM95_CS, RFM95_INT);

void setup() 
{
  sht30.begin();
  pinMode(RFM95_RST, OUTPUT);
  digitalWrite(RFM95_RST, HIGH);

  Serial.begin(115200);
  Serial.println("Adafruit GPS library basic test!");
  GPS.begin(9600);
  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); // 1 Hz update rate
  delay(1000);
  GPSSerial.println(PMTK_Q_RELEASE);

  delay(100);

  Serial.println("Feather LoRa TX Test!");

  // manual reset
  digitalWrite(RFM95_RST, LOW);
  delay(10);
  digitalWrite(RFM95_RST, HIGH);
  delay(10);

  while (!rf95.init()) {
    Serial.println("LoRa radio init failed");
    Serial.println("Uncomment '#define SERIAL_DEBUG' in RH_RF95.cpp for detailed debug info");
    while (1);
  }
  Serial.println("LoRa radio init OK!");

  // Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM
  if (!rf95.setFrequency(RF95_FREQ)) {
    Serial.println("setFrequency failed");
    while (1);
  }
  Serial.print("Set Freq to: "); Serial.println(RF95_FREQ);
  
  // Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on

  // The default transmitter power is 13dBm, using PA_BOOST.
  // If you are using RFM95/96/97/98 modules which uses the PA_BOOST transmitter pin, then 
  // you can set transmitter powers from 5 to 23 dBm:
  rf95.setTxPower(23, false);
}

int16_t packetnum = 0;  // packet counter, we increment per xmission

void loop(){

float Lo = GPS.longitude;  
int Al = GPS.altitude;
float humidity = sht30.readHumidity();

delay(2000);  

char c = GPS.read();
  if (GPS.newNMEAreceived()) {
    Serial.println(GPS.lastNMEA()); // this also sets the newNMEAreceived() flag to false
    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
  }
    if (GPS.fix) {
      Serial.print(GPS.latitude, 4); Serial.print(GPS.lat);
      Serial.print(", ");
      Serial.print(GPS.longitude, 4); Serial.println(GPS.lon);
      Serial.print(GPS.speed); Serial.println("kn");
      Serial.print(GPS.altitude); Serial.println("m");
      delay(2000); //I think 2 second delay is important, but maybe not because adafruit said it could do 10/second
  }
  
  delay(1000); // Wait 1 second between transmits, could also 'sleep' here!
  char radiopacket[20] = { GPS.latitude , GPS.lat };
  // itoa(packetnum++, radiopacket+6, 10);
  Serial.print("Sending "); Serial.println(radiopacket);
  //radiopacket[19] = 0;
  
  delay(10);
  
  rf95.send((uint8_t *) &GPS.latitude,4); //sends 4 byte latitude value in binary
  delay(10);
  
  rf95.waitPacketSent(); //waits for packet to complete sending
  // Now wait for a reply
  uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
  uint8_t len = sizeof(buf);

  Serial.print("RSSI: ");
  Serial.println(rf95.lastRssi(), DEC);    
}

I could point you at a fully working example of a GPS tracker transmitter\receiver for LoRa but it does not use that library.

One observation, and the end of the TX code you appear to be printing the RSSI register, when there has been nothing received .............

Binary values have to be interpreted properly, which depends on which Arduino you have.

Is it too much trouble to say what that is?

srnet that would be helpful, thank you. The RSSI was just in the original code I've been modifying, I just haven't cut it out.

jremington I am using Adafruit Feather M0 RFM96 LoRa Radio - 433MHz - RadioFruit

With the Feather M0 you can use either sprintf() or dtostrf() to format the data, but you have to enable the functions. See this thread.

Or just send and receive binary. To receive use something like

float msg=0.0;
uint8_t len=4;
    if (rf95.recv((uint8_t *) &msg, &len)) Serial.println(msg, 5);

See here, in the \examples\SX12xx_examples\tracker folders.

https://github.com/StuartsProjects/SX12XX-LoRa

Working examples for SX126x, SX127x and SX128x LoRa families.

What do you see on the serial console if you add:
Serial.print((uint8_t *) &GPS.latitude,4);

jremington thank you for that thread, it lead to a code that works.

SteveMann the code doesn't compile with

It gives the error
no matching function for call to 'print(uint8_t*, int)'

However! With this code I am able to see temperature and humidity values on my receiver. I switched to humidity and temperature because the GPS wouldn't send anything until it got a fix and it took minutes to get a fix each time because I'm indoors. These sensors just give me data faster.

#include <SPI.h>
#include <Wire.h>
#include <RH_RF95.h>
#include <Adafruit_GPS.h>
#include <Adafruit_SHT31.h>
#include <Adafruit_BMP280.h>
#include "avr/dtostrf.h"
#define GPSSerial Serial1
Adafruit_GPS GPS(&GPSSerial);
#define GPSECHO false

Adafruit_SHT31 sht30;  // humidity
Adafruit_BMP280 bmp280; // use I2C interface
Adafruit_Sensor *bmp280_temp = bmp280.getTemperatureSensor();
Adafruit_Sensor *bmp280_pressure = bmp280.getPressureSensor();

//for feather m0  
#define RFM95_CS 8
#define RFM95_RST 4
#define RFM95_INT 3

#define RF95_FREQ 433.0

// Singleton instance of the radio driver
RH_RF95 rf95(RFM95_CS, RFM95_INT);

void setup() 
{
  sht30.begin();
  bmp280.begin();
  pinMode(RFM95_RST, OUTPUT);
  digitalWrite(RFM95_RST, HIGH);

  Serial.begin(115200);
  Serial.println("Adafruit GPS library basic test!");
  GPS.begin(9600);
  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); // 1 Hz update rate
  delay(1000);
  GPSSerial.println(PMTK_Q_RELEASE);

  delay(100);

  Serial.println("Feather LoRa TX Test!");

  // manual reset
  digitalWrite(RFM95_RST, LOW);
  delay(10);
  digitalWrite(RFM95_RST, HIGH);
  delay(10);

  while (!rf95.init()) {
    Serial.println("LoRa radio init failed");
    Serial.println("Uncomment '#define SERIAL_DEBUG' in RH_RF95.cpp for detailed debug info");
    while (1);
  }
  Serial.println("LoRa radio init OK!");

  // Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM
  if (!rf95.setFrequency(RF95_FREQ)) {
    Serial.println("setFrequency failed");
    while (1);
  }
  Serial.print("Set Freq to: "); Serial.println(RF95_FREQ);
  
  bmp280.setSampling(Adafruit_BMP280::MODE_NORMAL,     /* Operating Mode. */
                  Adafruit_BMP280::SAMPLING_X2,     /* Temp. oversampling */
                  Adafruit_BMP280::SAMPLING_X16,    /* Pressure oversampling */
                  Adafruit_BMP280::FILTER_X16,      /* Filtering. */
                  Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */

  bmp280_temp->printSensorDetails();
  
  rf95.setTxPower(23, false);
}

void loop(){

sensors_event_t temp_event, pressure_event;
bmp280_temp->getEvent(&temp_event);
bmp280_pressure->getEvent(&pressure_event);  

float Lo = GPS.longitude;
float La = GPS.latitude;
float Al = GPS.altitude;
float humidity = sht30.readHumidity();
float temp = temp_event.temperature;

delay(2000);  

char c = GPS.read();
  if (GPS.newNMEAreceived()) {
    Serial.println(GPS.lastNMEA()); // this also sets the newNMEAreceived() flag to false
    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
  }
    if (GPS.fix) {
      Serial.print(GPS.latitude, 4); Serial.print(GPS.lat);
      Serial.print(", ");
      Serial.print(GPS.longitude, 4); Serial.println(GPS.lon);
      Serial.print(GPS.speed); Serial.println("kn");
      Serial.print(GPS.altitude); Serial.println("m");
      delay(2000);
  }
  
  char Hum[1] = {};
  dtostrf(humidity, 5, 2, Hum);
  Serial.print("Sending "); Serial.println(Hum);
  rf95.send((uint8_t *) &Hum,5); //sends 4 byte latitude value in binary
  delay(10);
  rf95.waitPacketSent(); //waits for packet to complete sending 

  delay(2000);
  char Tem[1] = {};
  dtostrf(temp, 5, 2, Tem);
  Serial.print("Sending "); Serial.println(Tem);
  rf95.send((uint8_t *) &Tem,5); //sends 4 byte latitude value in binary
  delay(10);
  rf95.waitPacketSent(); //waits for packet to complete sending     
}

I'm doing the whole "dtostrf" and array stuff for each sensor. If I see a way to refine it, I will but for now I can work with this and get on with my project.

Because there's no overload of the print() function that takes a pointer to a uint8_t and an int.

I should have added that I am very novice to LoRa. Still working on my first LoRa project. And you are using a different LoRa library than I am..

Instead of dtostrf(), try using sprintf().

(Blind leading the blind here).

I'm able to transmit and receive Latitude, Longitude, Altitude and Speed with this code. However the values print out funny on my receiver's OLED. The last 4 digits of my longitude are being tacked on to the speed and the altitude.

My OLED shows (from top to bottom, Lat, Lon, Speed, Altitude, RSSI)

1234.9287^
1234.4355^
0.414355^
415.14355^
RSSI: -23

I changed the "1234" of the lat and lon because I dont need some random internet lunatic to know where I live. BUT the lat is correct on OLED, the lon is correct, but then it adds the last 4 lon digits to my other data. It also shows the same random character at the end of each data. I want those 4 trailing digits to not be on the speed or altitude and it would also be nice to get rid of that random character at the end of all of them.

The Serial Monitor on the transmitter side shows this

23:02:50.972 -> N
23:02:52.011 -> Sending 1234.9287
23:02:53.047 -> Sending 1234.4355
23:02:54.124 -> Sending 0.41
23:02:55.156 -> Sending 415.10
23:02:56.182 -> 1234.9287N, 1234.4355W
23:02:56.182 -> 0.41kn
23:02:56.182 -> 415.10m

The Serial Monitor on the receiver side shows this

23:04:11.883 -> Got: N
23:04:12.913 -> Received:
23:04:12.913 -> 31 32 33 34 2E 39 32 38 37
23:04:13.946 -> Received:
23:04:13.946 -> 31 32 33 34 2E 34 33 35 35
23:04:15.022 -> Received:
23:04:15.022 -> 20 30 2E 34 31
23:04:16.053 -> Received:
23:04:16.053 -> 34 31 35 2E 31
23:04:18.109 -> Received:
23:04:18.109 -> 4E 0

The transmitter code is

#include <SPI.h>
#include <Wire.h>
#include <RH_RF95.h>
#include <Adafruit_GPS.h>
#include <Adafruit_SHT31.h>
#include <Adafruit_BMP280.h>
#include "avr/dtostrf.h"
#define GPSSerial Serial1
Adafruit_GPS GPS(&GPSSerial);
#define GPSECHO false

Adafruit_SHT31 sht30;  // humidity
Adafruit_BMP280 bmp280; // use I2C interface
Adafruit_Sensor *bmp280_temp = bmp280.getTemperatureSensor();
Adafruit_Sensor *bmp280_pressure = bmp280.getPressureSensor();

//for feather m0  
#define RFM95_CS 8
#define RFM95_RST 4
#define RFM95_INT 3

#define RF95_FREQ 433.0

// Singleton instance of the radio driver
RH_RF95 rf95(RFM95_CS, RFM95_INT);

void setup() 
{
  sht30.begin();
  bmp280.begin();
  pinMode(RFM95_RST, OUTPUT);
  digitalWrite(RFM95_RST, HIGH);

  Serial.begin(115200);
  Serial.println("Adafruit GPS library basic test!");
  GPS.begin(9600);
  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); // 1 Hz update rate
  delay(1000);
  GPSSerial.println(PMTK_Q_RELEASE);

  delay(100);

  Serial.println("Feather LoRa TX Test!");

  // manual reset
  digitalWrite(RFM95_RST, LOW);
  delay(10);
  digitalWrite(RFM95_RST, HIGH);
  delay(10);

  while (!rf95.init()) {
    Serial.println("LoRa radio init failed");
    Serial.println("Uncomment '#define SERIAL_DEBUG' in RH_RF95.cpp for detailed debug info");
    while (1);
  }
  Serial.println("LoRa radio init OK!");

  // Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM
  if (!rf95.setFrequency(RF95_FREQ)) {
    Serial.println("setFrequency failed");
    while (1);
  }
  Serial.print("Set Freq to: "); Serial.println(RF95_FREQ);
  
  bmp280.setSampling(Adafruit_BMP280::MODE_NORMAL,     /* Operating Mode. */
                  Adafruit_BMP280::SAMPLING_X2,     /* Temp. oversampling */
                  Adafruit_BMP280::SAMPLING_X16,    /* Pressure oversampling */
                  Adafruit_BMP280::FILTER_X16,      /* Filtering. */
                  Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */

  bmp280_temp->printSensorDetails();
  
  rf95.setTxPower(23, false);
}

void loop(){

sensors_event_t temp_event, pressure_event;
bmp280_temp->getEvent(&temp_event);
bmp280_pressure->getEvent(&pressure_event);  

float Lo = GPS.longitude;
float La = GPS.latitude;
float Al = GPS.altitude;
float Sp = GPS.speed;
float temp = temp_event.temperature;

delay(1000);  

char c = GPS.read();
  if (GPS.newNMEAreceived()) {
    Serial.println(GPS.lastNMEA()); // this also sets the newNMEAreceived() flag to false
    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
  }
    if (GPS.fix) {
      Serial.print(GPS.latitude, 4); Serial.print(GPS.lat);
      Serial.print(", ");
      Serial.print(GPS.longitude, 4); Serial.println(GPS.lon);
      Serial.print(GPS.speed); Serial.println("kn");
      Serial.print(GPS.altitude); Serial.println("m");
  }

  delay(1000);
  char radiopacket[2] = "N";
  Serial.println(radiopacket);
  radiopacket[1] = 0;
  rf95.send((uint8_t *)radiopacket, 2);
  rf95.waitPacketSent();  

  delay(1000);
  char Lat[1] = {};
  dtostrf(La, 9, 4, Lat);
  Serial.print("Sending "); Serial.println(Lat);
  rf95.send((uint8_t *) &Lat,9);
  delay(10);
  rf95.waitPacketSent();

  delay(1000);
  char Lon[1] = {};
  dtostrf(Lo, 9, 4, Lon);
  Serial.print("Sending "); Serial.println(Lon);
  rf95.send((uint8_t *) &Lon,9);
  delay(10);
  rf95.waitPacketSent();

  delay(1000);  
  char Spd[1] = {};
  dtostrf(Sp, 5, 2, Spd);
  Serial.print("Sending "); Serial.println(Spd);
  rf95.send((uint8_t *) &Spd,5);
  delay(10);
  rf95.waitPacketSent();

  delay(1000);
  char Alt[1] = {};
  dtostrf(Al, 6, 2, Alt);
  Serial.print("Sending "); Serial.println(Alt);
  rf95.send((uint8_t *) &Alt,5);
  delay(10);
  rf95.waitPacketSent(); 
}

The receiver code is

#include <SPI.h>
#include <RH_RF95.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH110X.h>
#include <Wire.h>

// for feather m0 RFM9x
#define RFM95_CS 8
#define RFM95_RST 4
#define RFM95_INT 3

Adafruit_SH110X display = Adafruit_SH110X(64, 128, &Wire);

// Change to 434.0 or other frequency, must match RX's freq!
#define RF95_FREQ 433.0

// Singleton instance of the radio driver
RH_RF95 rf95(RFM95_CS, RFM95_INT);

// Blinky on receipt
#define LED 13

void setup()
{
  pinMode(LED, OUTPUT);
  pinMode(RFM95_RST, OUTPUT);
  digitalWrite(RFM95_RST, HIGH);
  display.begin(0x3C, true); // Address 0x3C default
  display.setRotation(1);
  display.setTextSize(1);
  display.setTextColor(SH110X_WHITE);
  display.setCursor(0,0);

  display.println("Feather LoRa RX Test!");
  display.display();
  delay(1000);

  // manual reset
  digitalWrite(RFM95_RST, LOW);
  delay(10);
  digitalWrite(RFM95_RST, HIGH);
  delay(10);

  while (!rf95.init()) {
    Serial.println("LoRa radio init failed");
    Serial.println("Uncomment '#define SERIAL_DEBUG' in RH_RF95.cpp for detailed debug info");
    while (1);
  }
  Serial.println("LoRa radio init OK!");
  delay(1000);

  // Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM
  if (!rf95.setFrequency(RF95_FREQ)) {
    Serial.println("setFrequency failed");
    while (1);
  }
  Serial.print("Set Freq to: "); Serial.println(RF95_FREQ);

  // Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on

  // The default transmitter power is 13dBm, using PA_BOOST.
  // If you are using RFM95/96/97/98 modules which uses the PA_BOOST transmitter pin, then
  // you can set transmitter powers from 5 to 23 dBm:
  rf95.setTxPower(23, false);
}

void loop(){

  Serial.begin(115200);
  uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
  uint8_t len = sizeof(buf);  

  while (!rf95.available()){
  ;
  }

  display.clearDisplay();
  display.setCursor(0,0);

  if (rf95.recv(buf, &len))
  {
    RH_RF95::printBuffer("Received: ", buf, len);
    Serial.print("Got: ");
    Serial.println((char*)buf);

  if(strcmp((char *)buf, "N") == 0){
  
  for (int x = 0; x < 4; x++) {

  while (!rf95.available()){
    ;
  }
  
  if (rf95.available()){
    uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
    uint8_t len = sizeof(buf);

    if (rf95.recv(buf, &len)){
      RH_RF95::printBuffer("Received: ", buf, len);
      display.println((char*)buf);  
      display.display();
    }
   }
  } 
  display.print("RSSI: ");
  display.println(rf95.lastRssi(), DEC);
  display.display();  
  }
 }
}

The issue was in my receiver code I was not clearing out the buffer after each transmission. I had it before my for loop and it was messing everything up. I now have it first thing during my for loop. It's declaring the buffer as blank at the beginning of each transmission so each data has a fresh blank buffer to write all over.

I'm mostly documenting this for someone with similar issues in the future. Here is the new receiver code. The transmission code is the same.

#include <SPI.h>
#include <RH_RF95.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH110X.h>
#include <Wire.h>

// for feather m0 RFM9x
#define RFM95_CS 8
#define RFM95_RST 4
#define RFM95_INT 3

Adafruit_SH110X display = Adafruit_SH110X(64, 128, &Wire);

// Change to 434.0 or other frequency, must match RX's freq!
#define RF95_FREQ 433.0

// Singleton instance of the radio driver
RH_RF95 rf95(RFM95_CS, RFM95_INT);

void setup()
{
  pinMode(RFM95_RST, OUTPUT);
  digitalWrite(RFM95_RST, HIGH);
  display.begin(0x3C, true); // Address 0x3C default
  display.setRotation(1);
  display.setTextSize(1);
  display.setTextColor(SH110X_WHITE);
  display.setCursor(0,0);

  display.println("Feather LoRa RX Test!");
  display.display();
  delay(1000);

  // manual reset
  digitalWrite(RFM95_RST, LOW);
  delay(10);
  digitalWrite(RFM95_RST, HIGH);
  delay(10);

  while (!rf95.init()) {
    Serial.println("LoRa radio init failed");
    Serial.println("Uncomment '#define SERIAL_DEBUG' in RH_RF95.cpp for detailed debug info");
    while (1);
  }
  Serial.println("LoRa radio init OK!");
  delay(1000);

  // Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM
  if (!rf95.setFrequency(RF95_FREQ)) {
    Serial.println("setFrequency failed");
    while (1);
  }
  Serial.print("Set Freq to: "); Serial.println(RF95_FREQ);

  // Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on

  // The default transmitter power is 13dBm, using PA_BOOST.
  // If you are using RFM95/96/97/98 modules which uses the PA_BOOST transmitter pin, then
  // you can set transmitter powers from 5 to 23 dBm:
  rf95.setTxPower(23, false);
}

void loop(){

  Serial.begin(115200);
  uint8_t buf[RH_RF95_MAX_MESSAGE_LEN] = {};
  uint8_t len = sizeof(buf);  

  while (!rf95.available()){
  ;
  }

  display.clearDisplay();
  display.setCursor(0,0);

  if (rf95.recv(buf, &len))
  {
    RH_RF95::printBuffer("Received: ", buf, len);
    Serial.print("Got: ");
    Serial.println((char*)buf);

  if(strcmp((char *)buf, "N") == 0){
  
  for (int x = 0; x < 4; x++) {

  while (!rf95.available()){
    ;
  }
  
  if (rf95.available()){
    uint8_t buf[RH_RF95_MAX_MESSAGE_LEN] = {};
    uint8_t len = sizeof(buf);

    if (rf95.recv(buf, &len)){
      RH_RF95::printBuffer("Received: ", buf, len);
      display.println((char*)buf);  
    }
   }
  } 
  display.print("RSSI: ");
  display.println(rf95.lastRssi(), DEC);
  display.display();

  if (rf95.available()){
    uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
    uint8_t len = sizeof(buf);

    if (rf95.recv(buf, &len)){
      RH_RF95::printBuffer("Received: ", buf, len);
    }
   }
  }
 }
}

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