Neo-6M and OLED Not Working!

Hey Guys!

So I have this Neo-6M GPS Module that prints speed and time to an OLED. It worked fine. But then I tried adding altitude and it wouldn’t print anything to the OLED. But when I took altitude out it still wouldn’t work.

#include <Ultrasonic.h>

//temp & humidity and ultrasonic sensor & gps module library
#include <Adafruit_HTU21DF.h>
#include <TinyGPS++.h>
#include <NewPing.h>
#include <Wire.h>
#include "U8glib.h"
#include <SoftwareSerial.h>

//OLED
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE);  // I2C / TWI 

//TEMP & HUM
Adafruit_HTU21DF htu = Adafruit_HTU21DF();

//ULTRASONIC
Ultrasonic left(6, 7);
Ultrasonic right(8, 9);
Ultrasonic rear(3, 2);

int distance1; //LEFT
int distance2; //RIGHT
int distance3; //REAR


// VARiABLES

  //speed
  int speedkm;
  int speedmi;

  
  //time
  int mi;
  int hr;
  int hrPos;
  int miPos;
  String ampm;
  
  //temp & hum
  int tempc;
  int tempf;
  int hum;
  
  //timer
  unsigned long starttime;


// The GPS
TinyGPSPlus gps;
static const int RXPin = 12, TXPin = 11;
SoftwareSerial ss(RXPin, TXPin);
static const uint32_t GPSBaud = 9600;


//get GPS time and temp
void getTimeTemp(){
  tempc = round(htu.readTemperature());
  tempf = round((tempc * 1.8) + 32);
  hum = round(htu.readHumidity());
  Serial.println("pass 1");

while (ss.available() > 0){
    gps.encode(ss.read());
   if (gps.location.isUpdated()){
      Serial.println(gps.location.lng(), 6);
    //  alt = gps.altitude.meters();
      Serial.println("pass 2");
      
      hr = gps.time.hour() - 5;
      mi = gps.time.minute();
      
      
      if(hr==0){
        hr = 12;
        ampm = "AM";
      }
      else if (hr == 12){
        ampm = "PM";
      }
      else if (hr>0 and hr<12){
        ampm = "AM";
      }
      else if (hr>12){
        hr = hr-12;
        ampm = "PM";
      }
      
      else if (hr<0){
        int savehr = hr;
        hr = 12 + savehr;
        ampm = "PM";
      }

//      Serial.print(hr); 
//      Serial.print(":");
//      if (mi>9){
//        Serial.print(mi); 
//        Serial.print(" ");
//      }        
//      else{
//        Serial.print("0");
//        Serial.print(mi);
//        Serial.print(" ");
//      }
//      Serial.println(ampm);

      if (hr<10){
        hrPos = 37;
      }
      else{
        hrPos = 32;
      }
      if (mi<10){
        miPos = 55;
      }
      else{
        miPos = 49;
      }
      
    }
 }
    
}

//DISPLAY TOP BAR
void printTopBar(){
  //LINE
    u8g.drawLine(0, 12, 130, 12);
  
  //TIME
    u8g.setFont(u8g_font_lucasfont_alternate);
    u8g.setPrintPos(hrPos, 10); 
    u8g.print(hr);
    u8g.setPrintPos(45, 10);
    u8g.print(":");
    u8g.setPrintPos(49, 10);
    if (mi<10){
      u8g.print("0");
    }
    u8g.setPrintPos(miPos, 10);
    u8g.print(mi);
    u8g.setPrintPos(63, 10);
    u8g.print(ampm);

  //SPEED
    u8g.setPrintPos(87, 10);
    u8g.print(speedkm);
    u8g.drawStr(100, 10, "km/h");
}

//temp display function
void printTemp(void) {

  //temp
    u8g.setFont(u8g_font_profont22);
    u8g.setPrintPos(70, 35);
    u8g.print(tempf);
    u8g.setPrintPos(16, 35);
    u8g.print(tempc);

  //celcius / fahrenheit 
    u8g.drawStr(103, 35, "F");
    u8g.drawStr(49, 35, "C");

  //humidity
    u8g.setPrintPos(50, 60);
    u8g.print(hum);
    u8g.drawStr(73, 60, "%"); 

  //degree
    u8g.setFont(u8g_font_profont12);
    u8g.drawStr(94, 25, "o");
    u8g.drawStr(40, 25, "o");

  //seperating lines
    u8g.drawLine(17, 40, 111, 40);
    u8g.drawLine(64, 40, 64, 20);
}


//check distance
void checkDis(){

//  delay(50);
  distance1 = left.read();
//  Serial.print("Distance 1: ");
//  Serial.println(distance1);

  distance2 = right.read();
//  Serial.print("Distance 2: ");
//  Serial.println(distance2);

  distance3 = rear.read();
//  Serial.print("Distance 3: ");
//  Serial.println(distance3);

  if (distance3 <= 80 || distance3 == 0){
    digitalWrite(12, HIGH);
    delay(10);
    digitalWrite(13, HIGH);
  }
  else{
    digitalWrite(12, LOW);
    digitalWrite(13, LOW);

    if (distance1 <= 25 || distance1 == 0){
      digitalWrite(12, HIGH);
    }

    if (distance2 <= 25 || distance2 == 0){
     digitalWrite(13, HIGH);
    }
  }
  
}


void getSpeed(){
  
  while (ss.available() > 0){
    gps.encode(ss.read());
    if (gps.location.isUpdated()){
      Serial.println(gps.location.lng(), 6);
      Serial.print("Speed in km/h = "); 
      Serial.println(gps.speed.kmph());
      Serial.print("Speed in mi/h = "); 
      Serial.println(gps.speed.mph());
      speedkm = round(gps.speed.kmph());
      speedmi = round(gps.speed.mph());
      if (speedkm <= 1){
        speedkm = 0;
      }
      if (speedkm == 0){
        speedmi = 0;
      }
      Serial.println(speedkm);
      Serial.println(speedmi);
    }
  }
  
}


void printSpeed(){
  u8g.setFont(u8g_font_profont22);
  u8g.setPrintPos(23, 58);
  u8g.print(speedmi);
  u8g.setPrintPos(23, 35);
  u8g.print(speedkm);
  u8g.drawStr(56, 58, "mi/h");
  u8g.drawStr(56, 35, "km/h");
}


void printAlt(){
  u8g.setPrintPos(38, 58);
  u8g.setFont(u8g_font_profont22);
//  u8g.print(alt);
  u8g.drawStr(76, 58, "m");
  u8g.setFont(u8g_font_profont12);
  u8g.drawStr(40, 30, "ALTITUDE");
}


void setup(){
  Serial.begin(9600);
  ss.begin(GPSBaud);
  
  // rotate lcd
  u8g.setRot180();

  //define pins
//  pinMode(trigPin, OUTPUT); 
//  pinMode(echoPin, INPUT);

  //led pin
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);

  //find sensor
  Serial.println("HTU21D-F test");
  if (!htu.begin()) {
    Serial.println("Couldn't find sensor!");
    while (1);
  }
}


void loop(){

  //check distance
  //checkDis();

  
  //TEMP DISPLAY
    u8g.firstPage();  
    do {  
      printTopBar();
      printTemp();
    } while( u8g.nextPage() );
  
    //DELAY - CHECK DIS - TIME AND TEMP
      starttime = millis();
      while (millis() - starttime < 10000){
        checkDis();
        getTimeTemp();
      }

  //SPEED DISPLAY - REFRESH FREQUENTLY
  starttime = millis();
  while (millis() - starttime < 10000){
    getSpeed();
    checkDis();
    u8g.firstPage();  
    do {  
      printTopBar();
      printSpeed();
      delay(50);
    } while( u8g.nextPage() );

  }


    
}

It’s running the temperature and humidity part of the getTimeTemp function but not the GPS parrt. If you could find the issue it would be very much appreciated!

Thanks!

I just found the problem. My LED was the same pin as my GPS pin. Srry!

Wellcome to the club! Telling "somebody" of a problem often makes one find the solution!
Thanks for telling.