I am trying to interface a Neo-6m GPS module with a NodeMCU 8266 board.
The module is connected to the NodeMCU like below:
VCC - 3.3V
GND - GND
RX - D2
TX - D1
Here's my simple code:
#include <SoftwareSerial.h>
#include <TinyGPS++.h>
#include <ESP8266WiFi.h>
const int RXPin = D2, TXPin = D1;
SoftwareSerial gps_module(RXPin, TXPin);
TinyGPSPlus gps;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
gps_module.begin(9600);
}
void loop() {
if (gps.charsProcessed() < 10) {
Serial.println("GPS Error");
}
else Serial.println("GPS Connected");
delay(2000);
if (gps.location.isValid()) {
float latitude = (gps.location.lat());
float longitude = (gps.location.lng());
Serial.print("LAT: ");
Serial.println(latitude, 6);
Serial.print("LONG: ");
Serial.println(longitude, 6);
}
}
I have tried changing the GPS module (works fine with an Arduino) and tried different GPIO pins.
No matter what I do, it still does not detect the module and always shows "GPS Error".
I am new to the hobby and still learning. Any help understanding the issue or articles that I can read through would be helpful.
Do you mean that you are connecting the Neo-6M's RX port to D2 and then trying to read from it? And the Software Serial TX on D1 to the Neo-6M's TX port?
RX and TX on the Neo-6M board are Input and Output from the module:
They should cross like TX->RX and RX<-TX so the output TX of the module goes to the input of Software Serial on your board, and the output TX of your board's Software Serial goes to the input of the module.
That means that no Software Serial is available on D2:
Is D2 connected to the TX pin of the Neo-6M module that would emit GPS data? From what you've shown, that might not be true.
Please post pictures and schematics as per:
Also, since loop() already loops, you could change the 'while' to an 'if'.