Hello everyone,
I am working on a project at the moment that requires GPS coordinates to be sent to a base station. I am not worried about sending correction data at the moment, I just want to get the first step up and running first.
The problem I have is that I am new to LoRa and cannot figure out what I need to add to get the signal sent and received correctly. The two boards I am trying to use are the SAMD21 Pro RF and the Ublox ZED-F9P.
I can get the LoRa's to communicate until i try adding in the sensor data. Any help is highly appreciated!
Here is the code I have tried for the GPS and the transmitter
#include <RH_RF95.h>
#include <SPI.h> //RadioHead Library
#include <Wire.h> //Needed for I2C to GPS
#include "SparkFun_Ublox_Arduino_Library.h" //http://librarymanager/All#SparkFun_Ublox_GPS
SFE_UBLOX_GPS myGPS;
RH_RF95 rf95(12, 6);
//int LED = 13; //Lora Status LED
long lastTime = 0; //Simple local timer. Limits amount if I2C traffic to Ublox module.
float frequency = 921.2;
void setup()
{
SerialUSB.begin(115200);
//while (!Serial); //Wait for user to open terminal
Wire.begin();
SerialUSB.println("RFM Server");
if (rf95.init() == false){ //Initialize the radio
SerialUSB.println("Radio Init Failed - Freezing");
while (1);
}
else{
// An LED indicator to let us know radio initialization has completed.
SerialUSB.println("Receiver up!");
//digitalWrite(LED, HIGH);
delay(500);
//digitalWrite(LED, LOW);
delay(500);
}
if (myGPS.begin() == false) //Connect to the Ublox module using Wire port
{
SerialUSB.println(F("Ublox GPS not detected at default I2C address. Please check wiring. Freezing."));
while (1);
}
rf95.setFrequency(frequency);
//rf95.setTxPower(14, false); //This will be used to set the power of the radio, set it between 5 to 23 dBm
//myGPS.enableDebugging(Serial);
myGPS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise)
myGPS.setNavigationFrequency(20); //Set output to 20 times a second
byte rate = myGPS.getNavigationFrequency(); //Get the update rate of this module
SerialUSB.print("Current update rate:");
SerialUSB.println(rate);
myGPS.saveConfiguration(); //Save the current settings to flash and BBR
}
void loop()
{
//Query module only every second. Doing it more often will just cause I2C traffic.
//The module only responds when a new position is available
if (millis() - lastTime > 0)
{
lastTime = millis(); //Update the timer
SerialUSB.print("HP Lat: ");
int32_t latitude = myGPS.getHighResLatitude();
SerialUSB.print(latitude);
delay(250);
SerialUSB.print(", HP Lon: ");
int32_t longitude = myGPS.getHighResLongitude();
SerialUSB.print(longitude);
delay(250);
SerialUSB.print(", HP Alt: ");
int32_t altitude = myGPS.getAltitude();
SerialUSB.print(altitude/1000);
delay(250);
//SerialUSB.print(", Accuracy: ");
//uint32_t accuracy = myGPS.getHorizontalAccuracy();
//SerialUSB.println(accuracy);
//SerialUSB.print(", 3D Accuracy: ");
//uint32_t DAccuracy = myGPS.getPositionAccuracy();
//SerialUSB.print(DAccuracy);
//SerialUSB.print(" mm");
//delay(500);
SerialUSB.println("Sending message");
int32_t toSend = latitude;
int32_t lat[2] = {toSend, (toSend >> 32)};
rf95.waitPacketSent();
SerialUSB.println("Sent message");
delay(250);
}
}
And here is the code for the receiver.
#include <SPI.h> //Radio Head Library:
#include <RH_RF95.h>
RH_RF95 rf95(12, 6);
int LED = 13; //Status LED is on pin 13
int packetCounter = 0; //Counts the number of packets sent
long timeSinceLastPacket = 0; //Tracks the time stamp of last packet received
float frequency = 921.2; //Broadcast frequency
void setup()
{
pinMode(LED, OUTPUT);
SerialUSB.begin(9600);
// while(!SerialUSB);
SerialUSB.println("RFM Client!");
//Initialize the Radio.
if (rf95.init() == false){
SerialUSB.println("Radio Init Failed - Freezing");
while (1);
}
else{
//An LED inidicator to let us know radio initialization has completed.
SerialUSB.println("Transmitter up!");
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED, LOW);
delay(500);
}
// Set frequency
rf95.setFrequency(frequency);
rf95.setTxPower(14, false);
}
void loop()
{
//SerialUSB.println("Sending message");
//Send a message to the other radio
//uint8_t toSend[] = "Hello there!";
//sprintf(toSend, "Hi, my counter is: %d", packetCounter++);
//rf95.send(toSend, sizeof(toSend));
//rf95.waitPacketSent();
// Now wait for a reply
byte buf[RH_RF95_MAX_MESSAGE_LEN];
byte len = sizeof(buf);
if (rf95.waitAvailableTimeout(2000)) {
// Should be a reply message for us now
if (rf95.recv(buf, &len)) {
SerialUSB.print("Got reply: ");
SerialUSB.println((char*)buf);
//SerialUSB.print(" RSSI: ");
//SerialUSB.print(rf95.lastRssi(), DEC);
}
else {
SerialUSB.println("Receive failed");
}
}
else {
SerialUSB.println("No reply, is the receiver running?");
}
delay(500);
}