0

I'm trying to read the GPS data on an Arduino Uno from a Neo-6M module and print it on a LCD display. However, no variable is being changed by the read function. This could either be because of an incorrect reading of the gps variable or a wrong use of the SoftwareSerial library.

Here's the code:

#include <TinyGPS++.h>

#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <splash.h>

#include <SoftwareSerial.h>

Adafruit_SSD1306 display;  // Create display
SoftwareSerial gpsSerial(4,3);//rx,tx
float lati=0,longi=0;
float sat=0;
TinyGPSPlus gps; // create gps object 



void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  gpsSerial.begin(9600); // connect gps sensor 
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // Initialize display with the I2C address of 0x3C
  display.clearDisplay();
  display.setTextColor(WHITE);
}

void loop() {
  // put your main code here, to run repeatedly:
  display.clearDisplay();


    gps.encode(gpsSerial.read());
    display.setCursor(80,3);
    display.print("R");


  //if(gps.location.isUpdated())
  {
    lati = gps.location.lat();
    longi = gps.location.lng();
    sat = gps.satellites.value();
    display.setCursor(100,3);
    display.print("U");
  }

  display.setCursor(20,20);
  display.print(lati);
  display.setCursor(20,40);
  display.print(longi);
  display.setCursor(100,40);
  display.print(sat);
  display.drawRect(0,0,127,63,WHITE);
  display.display();
}

EDIT: The data coming from gpsSerial is a series of -1 EDIT 2: Swapping SoftwareSerial gpsSerial(4,3); to SoftwareSerial gpsSerial(4,3); makes it output a series of ints. However, encoding it with gps.encode(gpsSerial.read()) still doesn't update the data.

migrated from stackoverflow.com Nov 26 '18 at 17:22

This question came from our site for professional and enthusiast programmers.

  • no prints to Serial? why not use it for debug prints or connect the gps to it? – Juraj Nov 20 '18 at 19:27
  • I'm powering the arduino with a battery to be able to go outside to test the reception, so I'm printing the information on the screen to read it as it's collected – Marco Giacomin Nov 20 '18 at 19:39
  • then connect the module to Serial and don't use SoftwareSerial – Juraj Nov 20 '18 at 19:39
  • I don't have a serial to miniUSB cable – Marco Giacomin Nov 20 '18 at 19:41
  • pins RX and TX. 0 and 1. – Juraj Nov 20 '18 at 19:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.