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