Trouble Getting Speed To Display on GPS Speedometer

Hello all! I am new to Arduino and am having trouble with my first project. It may be too ambitious, but I'm building this speedometer for a specific project. I followed a "how to" and bought all the hardware listed in the "Instructable."

I having trouble getting my GPS Speedometer to display a speed. The sketch boots up on the nano, but I do not get a speed output, nor any of the errors coded in to the sketch. The screen is also very "glitchy," it cuts in and out. Sometimes it doesn't come on at all when I boot the nano. I'm guessing this could be a memory issue?

Any help is greatly appreciated.

Pinout diagram attached.

Hardware: Arduino Nano, SH1106 OLED, and NEO-6M GPS

Code:
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include <Wire.h>
#include <Adafruit_SH1106.h>
#define OLED_ADDRESS 0x3C
#define OLED_RESET -1
Adafruit_SH1106 display(OLED_RESET);
int RXin = 2, TXin = 3;
TinyGPSPlus gps;
SoftwareSerial ss(RXin, TXin);
void setup()
{
Serial.begin(9600);
ss.begin(9600);
display.begin(SH1106_SWITCHCAPVCC, OLED_ADDRESS);
display.clearDisplay();
display.display();
}
void loop()
{
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(27, 2);
display.print("CIRCUIT DIGEST");
display.setTextSize(1);
display.setCursor(35, 20);
display.print("SPEED(KMPH)");
display.display();
while (ss.available() > 0)
if (gps.encode(ss.read()))
displayspeed();
if (millis() > 5000 && gps.charsProcessed() < 10)
{
display.setTextSize(1);
display.setCursor(35, 40);
display.print("Error!!!");
display.display();
while (true);
}
}
void displayspeed()
{
if (gps.speed.isValid())
{
display.setTextSize(2);
display.setCursor(40, 40);
display.print(gps.speed.mph());
display.display();
}
else
{
display.setTextSize(1);
display.setCursor(35, 40);
display.print("No Data!!!");
display.display();
}
delay(100);
}

What does the compiler tell you about how much memory your sketch uses?

Can you try making a simpler version that just emits the speed on the serial port?

That Adafruit_SH1106 library uses a heap of memory, I would have expected that you were getting a low memory warning.

A GPS can put out around 10 sentences a second and only one of them contains the speed the library is reading, the GPRMC sentence.

Yet each time every sentence is received you assume the speed has been updated and go off and update the display;

if (gps.encode(ss.read()))
      displayspeed();

Which is pointless, since about 9 times out of ten the speed has not updated, so no need to update the display.

Use the ‘gps.speed.isUpdated()’ method to tell you when the speed has actually been updated and then go and display it.

And use this library for the display, its text only and will cut memory use from about 90% to 45% on the nano.

#include <U8x8lib.h>                                      //get library here >  https://github.com/olikraus/u8g2 
U8X8_SH1106_128X64_NONAME_HW_I2C disp(U8X8_PIN_NONE);   //use this line for 1.3" OLED often sold as 1.3" SSD1306

There is a complete working example attached, its too big to post. It displays Latitude, Longitude, Altitude, Speed, Satellites, HDOP, Time and date.

29_GPS_Checker_With_Display.ino (8.93 KB)

Wildbill- The compiler says I am at 92%. But I believe srnet has solved that for me. Thank you for the reply.

srnet- Thank you so much, that looks like it will work great for me. I will play around with it when I am done work.

So I am still having trouble with the display “glitching out.” I only am using 42% memory now. I believe I have the code sorted out right.

here is the updated code:

#include <TinyGPS++.h>
TinyGPSPlus gps;

#define RXpin A3 //pin number for GPS RX input into Arduino - TX from GPS
#define TXpin A2 //pin number for GPS TX output from Arduino- RX into GPS

#include <SoftwareSerial.h>
SoftwareSerial GPSserial(RXpin, TXpin);

#include <U8x8lib.h>
U8X8_SH1106_128X64_NONAME_HW_I2C disp(U8X8_PIN_NONE);

void setup()
{
Serial.begin(115200);
GPSserial.begin(9600);
disp.begin();
disp.clearDisplay();
disp.display();
}
void loop()
{
disp.clearDisplay();
disp.setFont(u8x8_font_chroma48medium8_r);
disp.setCursor(27, 2);
disp.print(“TMC v1.1”);
disp.setFont(u8x8_font_chroma48medium8_r);
disp.setCursor(35, 20);
disp.print(“SPEEDMPH”);
disp.display();
while (GPSserial.available() > 0)
if (gps.speed.isUpdated())
displayspeed();
if (millis() > 5000 && gps.charsProcessed() < 10)
{
disp.setFont(u8x8_font_chroma48medium8_r);
disp.setCursor(35, 40);
disp.print(“Error!!!”);
disp.display();
while (true);
}
}
void displayspeed()
{
if (gps.speed.isValid())
{
disp.setFont(u8x8_font_chroma48medium8_r);
disp.setCursor(40, 40);
disp.print(gps.speed.mph());
disp.display();
}
else
{
disp.setFont(u8x8_font_chroma48medium8_r);
disp.setCursor(35, 40);
disp.print(“No Data!!!”);
disp.display();
}
delay(100);
}

Why do you keep setting the font?

I was just plugging it in where I saw it in the old code. I'm guessing I only have to define it once?

tmc_2020:
So I am still having trouble with the display "glitching out."

Maybe explain what that means ?

And ror the code you posted to work, you do have to feed TinyGPS++ with the GPS characters via gps.encode().

The screen sometimes won't even come on when I boot the nano. When it does come on the image shows up upside down, way to the left or right, or only shows parts of the text in the wrong places.

When I try

if (gps.speed.isUpdated()) && (gps.encode(ss.read()))
displayspeed()

I get an error.

So an update. srnet, I was able to get your program to work. The problem now is that I am not getting a gps fix.

Here is the odd part. When i plug the the gps module directly into my computer via usb and use VisualGPS view I am able to get a fix and data just fine.

The TX from GPS is going to A3 and the RX from GPS is going to A2

Note the instructions at the top of the program, it shows you what the serial terminal output should be at startup, what do you see ?

The programs says "no gps fix wait 5s"

Then spits out the NMEA sentences

Then says "no gps fix 10s"

Then keeps going.

Can you show us what the NMEA sentences look like, it might help ?

These are the NMEA sentences I am receiving
:
Timeout - No GPS Fix 20s
Wait GPS Fix 5 seconds
$GPRMC,205020.00,V,,,,,,,011020,,,N7A
$GPVTG,,,,,,,,,N
30
$GPGGA,205020.00,,,,,0,00,99.99,,,,,,63
$GPGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99
30
$GPGSV,2,1,05,10,,,30,11,,,19,15,,,19,18,,,2577
$GPGSV,2,2,05,23,,,31
7F
$GPGLL,,,,,205020.00,V,N4F
$GPRMC,205021.00,V,,,,,,,011020,,,N
7B
$GPVTG,,,,,,,,,N30
$GPGGA,205021.00,,,,,0,00,99.99,,,,,,62
$GPGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99
30
$GPGSV,1,1,04,10,,,30,11,,,22,18,,,26,23,,,31
71
$GPGLL,,,,,205021.00,V,N4E
$GPRMC,205022.00,V,,,,,,,011020,,,N
78
$GPVTG,,,,,,,,,N30
$GPGGA,205022.00,,,,,0,00,99.99,,,,,,61
$GPGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99
30
$GPGSV,1,1,04,10,,,29,11,,,24,18,,,27,23,,,32
7D
$GPGLL,,,,,205022.00,V,N4D
$GPRMC,205023.00,V,,,,,,,011020,,,N
79
$GPVTG,,,,,,,,,N30
$GPGGA,205023.00,,,,,0,00,99.99,,,,,,60
$GPGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99
30
$GPGSV,2,1,05,10,,,31,11,,,25,18,,,27,23,,,32
77
$GPGSV,2,2,05,25,,,267F
$GPGLL,,,,,205023.00,V,N
4C
$GPRMC,205024.00,V,,,,,,,011020,,,N7E
$GPVTG,,,,,,,,,N
30
$GPGGA,205024.00,,,,,0,00,99.99,,,,,,67
$GPGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99
30
$GPGSV,2,1,05,10,,,29,11,,,24,18,,,26,23,,,307C
$GPGSV,2,2,05,25,,,25
7C
$GPGLL,,,,,205024.00,V,N*4B

Update:

I booted the nano and left it on for an hour or so. I noticed it had gotten a fix at one or two times but immediately lost it. This does not happen when I use the module directly via USB with VisualGPSview.

tmc_2020:
These are the NMEA sentences I am receiving
:
Timeout - No GPS Fix 20s
Wait GPS Fix 5 seconds
$GPRMC,205020.00,V,,,,,,,011020,,,N7A
$GPVTG,,,,,,,,,N
30
$GPGGA,205020.00,,,,,0,00,99.99,,,,,,63
$GPGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99
30
$GPGSV,2,1,05,10,,,30,11,,,19,15,,,19,18,,,2577
$GPGSV,2,2,05,23,,,31
7F
$GPGLL,,,,,205020.00,V,N4F
$GPRMC,205021.00,V,,,,,,,011020,,,N
7B
$GPVTG,,,,,,,,,N30
$GPGGA,205021.00,,,,,0,00,99.99,,,,,,62
$GPGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99
30
$GPGSV,1,1,04,10,,,30,11,,,22,18,,,26,23,,,31
71
$GPGLL,,,,,205021.00,V,N4E
$GPRMC,205022.00,V,,,,,,,011020,,,N
78

The program is working correctly then, indeed your GPS does not have a fix.

You do have it outdoors with a good view of the sky ?

Just did and got a fix after about a minute or so. Why does it connect right away with VisualGPSview? Weird.

Is length of time to get a fix related.to the quality of the chip or some other hardware limitation?

Thanks for all of your help.

tmc_2020:
Is length of time to get a fix related.to the quality of the chip or some other hardware limitation?

Length of time for a fix from cold is mainly related to the type of antenna in use. Some GPSs are better at first fix times than others, but most all GPS should get a fix in 45-60seconds from cold, assuming a reasonable view of the sky and good working antenna.

There is comparisons of fix times for a range of GPSs and antenna types here;

Awesome, thank you.