I am currently trying to write a code that outputs the latitude and longitude to the serial monitor in order to test if my GPS module and NODEMCU module are working together correctly.
Here is my code:
#include <ESP8266WiFi.h>
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
TinyGPSPlus gps;
static const int RXPin = 4;
static const int TXPin = 5;
SoftwareSerial ss (RXPin,TXPin);
const char* ssid = "Ryan's iPhone";
const char* password = "ryanwifi";
int i;
float latitude = gps.location.lat();
float longitude = gps.location.lng();
unsigned long age = 0;
WiFiServer server(80);
void setup() {
Serial.begin(115200);
delay(10);
ss.begin(9600);
// Connect to WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print("\nAttempting to Connect..");
}
Serial.println("");
Serial.println("WiFi connected");
// Start the server
server.begin();
Serial.println("Server started");
// Print the IP address
Serial.print("Use this URL to connect: ");
Serial.print("http://");
Serial.print(WiFi.localIP());
Serial.println("/");
}
void checkGPS(){
if(gps.charsProcessed() < 10)
{
Serial.println(F("No GPS detected: check wiring."));
}
}
void loop() {
latitude = gps.location.lat();
longitude = gps.location.lng();
Serial.println("\n\n\nTest: ");
Serial.println(i);
Serial.println("\nNumber of satellies: ");
Serial.println(gps.satellites.value());
Serial.println("\nLatitude: ");
Serial.println(latitude);
Serial.println("\nLongitude: ");
Serial.println(longitude);
i++;
delay(1000);
}
But something isnt working correctly; the output for satellites, long and lat are all 0.
Where am I going wrong here?
Sidenote; When connecting to the nodemcu - for clarity - which pins should the TX of the GPS module go to? and the RX of the GPS module go to - on the nodemcu?
Thanks!