-1

I'm trying to connect a GPS unit (GY-GPS6MV2) and an OLED screen as in the diagram below (green connector is GPS; VCC, RX, TX, GND left to right):

enter image description here

Here's the code I've come up with:

#include <Wire.h>
#include <Adafruit_SH1106.h>
#include <TinyGPS++.h>
#include <SoftwareSerial.h>

#define OLED_RESET 4
Adafruit_SH1106 display(OLED_RESET);
static const int RXPin = 5, TXPin = 3;
static const uint32_t GPSBaud = 9600;
float vkph;
float vmps;

TinyGPSPlus gps;
SoftwareSerial ss(RXPin, TXPin);

void setup(){
  Serial.begin(9600);
  ss.begin(GPSBaud);
  display.begin(SH1106_SWITCHCAPVCC, 0x3C);
  display.display();
  delay(2000);
  display.clearDisplay();
}

void loop(){
  while (ss.available() > 0){
    gps.encode(ss.read());
    vkph = gps.speed.kmph();
    vmps = gps.speed.mps();
    if (gps.location.isUpdated()){
      Serial.print("Position: "); 
      Serial.print(gps.location.lat(), 6);
      Serial.print(" : "); 
      Serial.println(gps.location.lng(), 6);
      Serial.print("Speed: ");
      Serial.print(vmps); 
      Serial.print(" m/s");
      Serial.print(", ");
      Serial.print(vkph);
      Serial.println( " km/hr"); 

      display.clearDisplay();
      display.setTextSize(2);
      display.setTextColor(WHITE);
      display.setCursor(0,0);
      display.println("Hello"); // Changing this to display.println(vmps);
      display.setTextSize(2);
      display.setTextColor(WHITE);
      display.println("World"); // Changing this to display.println(vkph);
      display.display();
      delay(1000); 

    }
  }
}

The GPS outputs to the serial monitor fine, and the screen displays "Hello \n World" as expected. But when I make the changes indicated in the comments to the display part of the code, the display just shows its splash screen, flashing when the GPS updates.

How can I get the display to show the speeds in m/s and km/hr?

-2

Maybe you need to add delay() in your code,I am not sure.

display.clearDisplay();
      display.setTextSize(2);
      display.setTextColor(WHITE);
      display.setCursor(0,0);
      display.println("Hello"); // Changing this to display.println(vmps);
      display.setTextSize(2);
      display.setTextColor(WHITE);
      display.println("World"); // Changing this to display.println(vkph);
      display.display();
      delay(1000);
  • Why, and where? – Jim421616 Aug 31 at 2:00
  • Because OLED doesn't have a time to keep showing. – Memba Aug 31 at 2:06
  • Is this an answer or a question? Also please elaborate more, so that the answer is really helpful – chrisl Aug 31 at 16:11
  • I tried this, even before you posted the edit. Same problem, only now it takes 1000 milliseconds to flash the splash screen. – Jim421616 Sep 1 at 7:11
  • Have you also added the delay after the GPS display code? – chrisl Sep 1 at 9:53

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.