I have two working codes for both which the hc05 receives data of latitude and longitude from an app i made, it prints to the serial monitor. The same with gps i have a code works which prints the current latitude and longitude of the gps module. NOw when combining them on one code either the bluetooth data shows and the gps data doesnt or the other way arounf. Ia there a specific reason why this happens??
//GPS CODE
#include <SoftwareSerial.h>
#include <TinyGPS++.h>
SoftwareSerial gpsSerial(8,9);
TinyGPSPlus gps;
void setup() {
gpsSerial.begin(9600);
Serial.begin(9600);
}
void loop()
{
while (gpsSerial.available())
{
gps.encode(gpsSerial.read());
if (gps.location.isUpdated())
{
double latitude = (gps.location.lat());
double longitude = (gps.location.lng());
Serial.print ("latitude: ");
Serial.println (latitude, 6);
Serial.print ("longitude: ");
Serial.println (longitude, 6);
}
}
}
//Bluetooth CODE
#include <SoftwareSerial.h>
// Define pins for HC-05 communication
#define BT_RX 2 //TX
#define BT_TX 3 //RX
// Create software serial object
SoftwareSerial BTSerial(BT_RX, BT_TX);
void setup() {
// Initialize serial communications
Serial.begin(9600); // For Serial Monitor
BTSerial.begin(38400); // Change if not reading
Serial.println("Arduino ready to receive Bluetooth data");
}
void loop() {
// Read from HC-05 and send to Serial Monitor
if (BTSerial.available()) {
String message = BTSerial.readString();
Serial.print("Received: ");
Serial.println(message);
}
// You can also read from Serial Monitor and send to HC-05
if (Serial.available()) {
String message = Serial.readString();
BTSerial.print(message);
}
}