Hello everyone,
Hi I'm making a project using LoRa RFM95 and UBLOX GPS. The project that I'm working on uses a multi-hop system (RH_ROUTER) for sending data.
I am very beginner in using this programming language and i'm still learning. When I compile the code that I made, I get this error message
'SerialUSB' was not declared in this scope'
I really need help in working on this code. Any help is highly appreciated!. Maybe you can help me improve the code that I use this.
Here is the code that I use on my 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");
//add 200
const int8_t toSendlat = latitude;
const int8_t toSendlon = longitude;
const int8_t toSendalt = altitude;
uint8_t sendarr [3] = {0};
sendarr[0] = (uint8_t) toSendlat;
sendarr[1] = (uint8_t) toSendlon;
sendarr[2] = (uint8_t) toSendalt;
rf95.send(sendarr, sizeof(sendarr));
rf95.waitPacketSent();
SerialUSB.println("Sent message");
delay(250);
}
}