OLED Issues with GPS and BME280

I'm working on creating a readout that shows GPS information as well as Temperature and Humidity. For reasons I can't figure out every time I add the BME Libraries into the sketch, it causes the OLED display not to work. Just remains black. Without these libraries, the GPS Code works great.

Any thoughts on why this is would be much appreciated.

/*********************************************************************
SCULLCOM Hobby Electronics
Simple GPS System
Using Arduino Pro Mini + OLED 128x64 display + GPS Module
*********************************************************************/

#include <SPI.h>                      //Serial Peripheral Interface (SPI) library for synchronous serial data protocol
#include <Wire.h>                     //Wire library used for I2C communication: Arduino Pro Mini pins used = A4 (SDA) and A5 (SCL)
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <Adafruit_GFX.h>             //Adafruit graphic display library used for the OLED display
#include <Adafruit_SSD1306.h>         //Adafruit driver for OLED

 
#include <SoftwareSerial.h>           //SoftwareSerial library used to allow serial communication on other digital pins (i.e. Pins 3 & 4 for the this GPS project)
#include <TinyGPS.h>                  //GPS Library used to read the data from GPS Module

#include <Fonts/FreeSansBold9pt7b.h>
#include <Fonts/FreeSans18pt7b.h>

#define SEALEVELPRESSURE_HPA (1013.25)

Adafruit_BME280 bme; // I2C
unsigned long delayTime;

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET    -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define HOUR_OFFSET   -4

#define OLED_RESET 5
Adafruit_SSD1306 display(OLED_RESET);



TinyGPS gps;                          //Create the TinyGPS object, giving it a name of your choice (here we use the name gps)
SoftwareSerial nss(3, 4);             //set sotfware serial communications to arduino ports 3 and 4 (TX = 3 and RX = 4)


#if (SSD1306_LCDHEIGHT !=64)

#endif


void setup()   {                  
   nss.begin(9600);
  
  unsigned long age, date, time, chars = 0;

  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize the OLED and set the I2C address to 0x3C (for the 128x64 OLED) 
  //dht.begin();//Start the dht
   
  display.clearDisplay();             //Clear display buffer.

  display.setTextSize(2);             //set text size to 2 (large)
  display.setTextColor(WHITE);
  display.setCursor(0,0);             //set text start position to column=0 and row=0
  display.print("SCULLCOM");          //print "SCULLCOM" to display
  
  display.setTextSize(1);             //set text size to 1 (small)
  display.setCursor(0,18);            //set text start position to column=0 and row=18
  display.print("GPS SYSTEM");        //print "GPS SYSTEM" to display
  
  display.setCursor(0,30);            //set text start position to column=0 and row=30
  display.setTextColor(BLACK, WHITE); // 'inverted' text
  display.print("INITIALISING .....");//print "INITIALISING ....." to display
  display.setCursor(0,40);            //set text start position to column=0 and row=40
  display.setTextColor(WHITE);        //
  display.print("Trying to locate GPS satellites ...");  //print "Trying to locate GPS satellites ..." to display
  
  display.setCursor(0,57);            //set text start position to column=0 and row=57
  display.print("Please Wait");       //print "Please Wait" to display
  
  display.display();                  //update OLED with new display data
  delay(1000);                        //short delay
  display.clearDisplay();             //clear display
}


//MAIN PROGRAMME LOOP
void loop() {

bool newdata = false;
  unsigned long start = millis();
  while(millis() - start < 1000){    // Every 1 seconds we print an update
    if (feedgps())
      newdata = true;
  }
  if (newdata)
  { 
    gpsdump(gps);
  }
}
 
 
//PRINT GPS DATA TO OLED DISPLAY
void gpsdump(TinyGPS &gps)
{  
  print_date(gps);                  //print date and time at top of OLED display
  
  float flat, flon, falt;
 

  display.clearDisplay();
  
  display.setTextSize(1);           //set text size to 1
  display.setTextColor(WHITE);      //
  display.setCursor(0,0);           //set text start position for date and time (row = 0, column =0)
  print_date(gps);                  //prints date and time on top line to OLED
  
  gps.f_get_position(&flat, &flon); //retrieves latitude and longditude data
  display.setCursor(0,20);          //set text start position to column=0 and row=20
  display.print("Altitude : ");     //print "Altitude" : to display
  display.println(gps.f_altitude()*3.28084);//print altitude data to display
  display.setCursor(110,20);        //set text start position to column=100 and row=20
  display.println("F");             //print "m" to display
  
  display.setCursor(0,30);          //set text start position to column=0 and row=30
  display.print("Sats     : ");     //print "Sats    :" to display
  display.println(gps.satellites());//print number of satellites detected to display
  
  display.setCursor(0,40);          //set text start position to column=0 and row=40
  display.print("latitude : ");     //print "latitude :" to display
  display.println(flat,6);          //print latitude data to display up to 6 decimal places
  
  display.setCursor(0,50);          //set text start position to column=0 and row=50
  display.print("longitude: ");     //print "longitude:" to display
  display.println(flon,6);          //print longitude data to display up to 6 decimal places

  display.display();                //update OLED display
}


//TEST FOR NEW DATA FROM THE GPS MODULE
bool feedgps()
{
  while (nss.available())
  {
    if (gps.encode(nss.read()))    //Each byte of NEMA data must be giving to TinyGPS by using encode(). True is returned when new data has been fully decoded and can be used
      return true;
  }
  return false;
} 


//GET DATE AND TIME FOR DISPLAY
static void print_date(TinyGPS &gps)
{
  int year;
  byte month, day, hour, minute, second, hundredths;
  unsigned long age;
  gps.crack_datetime(&year, &month, &day, &hour, &minute, &second);
  {
    char sz[32];
    sprintf(sz, "%02d/%02d/%02d  %02d:%02d:%02d",
        month, day, year, hour, minute, second);    
    display.print(sz);                      //Print date and time to OLED
  }

}

Perhaps you are running out of memory. Take a look at the upload statistics.

Be sure to turn on the "verbose" option for compilation, and post warning or error messages.

It helps to mention which Arduino you are using. Other tips are in "How to use the forum".

You are right it looks like I'm running out of memory here.
"Sketch uses 29478 bytes (95%) of program storage space. Maximum is 30720 bytes."

I'm using an Arduino Nano. Is there anything I can do to work around this?
Do I need a different board? I was hoping to turn this into a gauge for my van so the physical size of the Nano was helpful.
Thanks for your response.

Ambitious use of libraries for a Pro Mini, they will use a lot of memory, were there warnings about program stability ?

Nope didn't see any warnings. I've included the output in case I missed anything.
Also seeing it says 72% now, I'm sorry I got that wrong in the last post.

Sketch uses 22240 bytes (72%) of program storage space. Maximum is 30720 bytes.
Global variables use 1010 bytes (49%) of dynamic memory, leaving 1038 bytes for local variables. Maximum is 2048 bytes.
C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude -CC:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf -v -patmega328p -carduino -PCOM5 -b115200 -D -Uflash:w:C:\Users\paul\AppData\Local\Temp\arduino_build_894854/GPS_Vangon_1.ino.hex:i 

avrdude: Version 6.3-20190619
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf"

         Using Port                    : COM5
         Using Programmer              : arduino
         Overriding Baud Rate          : 115200
         AVR Part                      : ATmega328P
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PC2
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : Arduino
         Description     : Arduino
         Hardware Version: 3
         Firmware Version: 4.4
         Vtarget         : 0.3 V
         Varef           : 0.3 V
         Oscillator      : 28.800 kHz
         SCK period      : 3.3 us

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: reading input file "C:\Users\paul\AppData\Local\Temp\arduino_build_894854/GPS_Vangon_1.ino.hex"
avrdude: writing flash (22240 bytes):

Writing | ################################################## | 100% 3.42s

avrdude: 22240 bytes of flash written
avrdude: verifying flash memory against C:\Users\paul\AppData\Local\Temp\arduino_build_894854/GPS_Vangon_1.ino.hex:
avrdude: load data flash data from input file C:\Users\paul\AppData\Local\Temp\arduino_build_894854/GPS_Vangon_1.ino.hex:
avrdude: input file C:\Users\paul\AppData\Local\Temp\arduino_build_894854/GPS_Vangon_1.ino.hex contains 22240 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 2.63s

avrdude: verifying ...
avrdude: 22240 bytes of flash verified

avrdude done.  Thank you.

Since you don't appear to be actually using the BME sensor, there may be a conflict between the libraries.

Get the BME working with the OLED display alone, before adding anything to the working code.

Ok, I had a BMP280 working with the display but I haven't yet tried the BME280.
I did try the DHT11 and had the same issue.

Ok so the issue isn't the BME and the OLED. I have them working together. See the picture attached.
It seems as if the code to run the BME is pretty memory intensive, it is consuming 91%. Is it just not possible to run this much info on a Nano?
Any suggestions are much appreciated.

91% (or more) is fine. RAM is the thing that can cause trouble if you use too much of it. Is it all working?

So the BME and the Display work together. I want to combine the BME-DISPLAY and GPS.
In the picture above I have them running separately on separate Nanos, the goal is to use 1 OLED, 1 Nano the GPS and the BME. That's where I'm running into the issue. (see above)

btw this is the code I'm using for the BME

/* This code is to use with Adafruit BMP280 and OLED screen   (Imperial)
 * It measures both temperature and pressure and it displays them on the OLED display with the altitude
 * It's a modified version of the Adafruit example code
 * Refer to www.surtrtech.com or SurtrTech Youtube channel
 */
 
#include <Adafruit_GFX.h>      //Libraries for the OLED and BMP280
#include <Adafruit_SSD1306.h>
#include <Fonts/FreeSansBold9pt7b.h>
#include <Fonts/FreeSans18pt7b.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>



#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET    -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

#define SEALEVELPRESSURE_HPA (1013.25)

Adafruit_BME280 bme;
unsigned long delayTime;

void setup() {  
  delay(10000);
  bme.begin();                                //Start the bmp                  
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C); //Start the OLED display
  display.clearDisplay();
  display.display();
  display.setTextColor(WHITE);
  display.setTextSize(1); 
  display.print("BME280");     //Show the name, you can remove it or replace it
  display.setCursor(15,20); 
  display.setFont(&FreeSansBold9pt7b);         
  display.println("VANAGON"); 
  display.setCursor(24,50);
  display.println("SENSOR"); 
  display.setFont();
  display.display();
  delay(10000);
}

void loop() {

    display.clearDisplay();
    float T = bme.readTemperature()*9/5 + 32;    //Read temperature in °C and conversion to °F
    float P = bme.readPressure() / 100.0F;        
    float H = bme.readHumidity();

    
    display.setCursor(8,10);                       //Oled display, just playing with text size and cursor to get the display you want
    display.setTextColor(WHITE); 
    display.setFont(&FreeSansBold9pt7b);
    display.print("Temperature");
    display.setFont();
    display.setCursor(45,50);
    display.setFont(&FreeSans18pt7b);
    display.print(T,0);
    display.setCursor(20,60);
    display.setFont();
    display.setTextSize(1);
    display.print("F");

       display.display();
    delay(10000);
    display.clearDisplay();

    
    display.setCursor(25,10);
    display.setFont(&FreeSansBold9pt7b);
    display.print("Pressure");
    display.setFont();
    display.setCursor(35,50);
    display.setFont(&FreeSans18pt7b);
    display.print(P,0);
    display.setFont();
    display.setCursor(5,50);
    display.setTextSize(1);
    display.print("inHg");
   
   display.display();
    delay(10000);
    display.clearDisplay();
    
    display.setCursor(25,10);
    display.setFont(&FreeSansBold9pt7b);
    display.print("Humidity");
    display.setFont();
    display.setCursor(45,50);
    display.setFont(&FreeSans18pt7b);
    display.print(H,0);
    display.setFont();
    display.setCursor(10,55);
    display.setTextSize(1);
    display.print("%");





    display.display();
    delay(10000);
}

I assume that you run out of progmem when you add the last two libraries to support GPS. is that the problem?

display.print(F("BME280")); etc

It's not a lot, but it may just tip things in your favour

wildbill:
I assume that you run out of progmem when you add the last two libraries to support GPS. is that the problem?

Well, I never got an error for that. The OLED just wouldn't display anything.

TheMemberFormerlyKnownAsAWOL:

display.print(F("BME280"));

etc

It's not a lot, but it may just tip things in your favour

Thanks for your help. I'm a Newbie so can you tell me in what part of the sketch that part if code is for? Setup or loop?
Possibly what it does?

Everywhere you print a string literal, you wrap the literal in F(), like I showed you.
It keeps literals in program memory, where they belong.

dport7:
Well, I never got an error for that. The OLED just wouldn't display anything.

What's the compiler message relating to RAM when that happens.

TheMemberFormerlyKnownAsAWOL:
Everywhere you print a string literal, you wrap the literal in F(), like I showed you.
It keeps literals in program memory, where they belong.

Thanks for the tip. That certainly helped get the BME Library to flash and the display to work.
I've been formatting the data for the display and now I have run out of memory on the NANO. Any other suggestions for how to optimize things?

Error when flashing:
Sketch uses 30866 bytes (100%) of program storage space. Maximum is 30720 bytes.text section exceeds available space in board

Global variables use 850 bytes (41%) of dynamic memory, leaving 1198 bytes for local variables. Maximum is 2048 bytes.
Sketch too big; see http://www.arduino.cc/en/Guide/Troubleshooting#size for tips on reducing it.
Error compiling for board Arduino Nano.

See the updated code below.

/*********************************************************************
SCULLCOM Hobby Electronics
Simple GPS System
Using Arduino Pro Mini + OLED 128x64 display + GPS Module
*********************************************************************/

#include <SPI.h>                      //Serial Peripheral Interface (SPI) library for synchronous serial data protocol
#include <Wire.h>                     //Wire library used for I2C communication: Arduino Pro Mini pins used = A4 (SDA) and A5 (SCL)

#include <Adafruit_GFX.h>             //Adafruit graphic display library used for the OLED display
#include <Adafruit_SSD1306.h>         //Adafruit driver for OLED
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
 
#include <SoftwareSerial.h>           //SoftwareSerial library used to allow serial communication on other digital pins (i.e. Pins 3 & 4 for the this GPS project)
#include <TinyGPS.h>                  //GPS Library used to read the data from GPS Module

#include <Fonts/FreeSansBold9pt7b.h>
#include <Fonts/FreeSans18pt7b.h>
#include <Fonts/FreeSans9pt7b.h>    
                                    
//#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME280 bme; // I2C
unsigned long delayTime;


#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET    -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define HOUR_OFFSET   -4

#define OLED_RESET 5
Adafruit_SSD1306 display(OLED_RESET);



TinyGPS gps;                          //Create the TinyGPS object, giving it a name of your choice (here we use the name gps)
SoftwareSerial nss(3, 4);             //set sotfware serial communications to arduino ports 3 and 4 (TX = 3 and RX = 4)


#if (SSD1306_LCDHEIGHT !=64)

#endif



void setup()   {                  
   nss.begin(9600);
   bme.begin();
  
  unsigned long age, date, time, chars = 0;

  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize the OLED and set the I2C address to 0x3C (for the 128x64 OLED) 

   
  display.clearDisplay();             //Clear display buffer.

  display.setTextSize(2);             //set text size to 2 (large)
  display.setTextColor(WHITE);
  display.setCursor(0,0);             //set text start position to column=0 and row=0
  display.print("SCULLCOM");          //print "SCULLCOM" to display
  
  display.setTextSize(1);             //set text size to 1 (small)
  display.setCursor(0,18);            //set text start position to column=0 and row=18
  display.print(F("GPS SYSTEM"));        //print "GPS SYSTEM" to display
  
  display.setCursor(0,30);            //set text start position to column=0 and row=30
  display.setTextColor(BLACK, WHITE); // 'inverted' text
  display.print(F("INITIALISING ....."));//print "INITIALISING ....." to display
  display.setCursor(0,40);            //set text start position to column=0 and row=40
  display.setTextColor(WHITE);        //
  display.print(F("Trying to locate GPS satellites ..."));  //print "Trying to locate GPS satellites ..." to display
  
  display.setCursor(0,57);            //set text start position to column=0 and row=57
  display.print(F("Please Wait"));       //print "Please Wait" to display
  
  display.display();                  //update OLED with new display data
  delay(1000);                        //short delay
  display.clearDisplay();             //clear display
}


//MAIN PROGRAMME LOOP
void loop() {

bool newdata = false;
  unsigned long start = millis();
  while(millis() - start < 1000){    // Every 1 seconds we print an update
    if (feedgps())
      newdata = true;
  }
  if (newdata)
  { 
    gpsdump(gps);
  }
}
 
 
//PRINT GPS DATA TO OLED DISPLAY
void gpsdump(TinyGPS &gps)
{  
  //print_date(gps);                  //print date and time at top of OLED display
  
  float flat, flon, falt;
  float T = bme.readTemperature()*9/5 + 32;    //Read temperature in °C and conversion to °F
  float P = bme.readPressure() / 100.0F;        
  float H = bme.readHumidity();
 

  display.clearDisplay();
  
  display.setTextSize(1);           //set text size to 1
  display.setTextColor(WHITE);      //
  display.setCursor(0,0);           //set text start position for date and time (row = 0, column =0)
  //print_date(gps);                  //prints date and time on top line to OLED

 gps.f_get_position(&flat, &flon); //retrieves latitude and longditude data

  //ALTITUDE LATOUT
  display.setCursor(27,12);          //set text start position to column=0 and row=20
  display.setFont(&FreeSansBold9pt7b);
  display.print(F("Altitude"));     //print "Altitude" : to display
  display.setCursor(38,26);          //set text start position to column=0 and row=30
  display.setFont();
  display.setTextSize(1);
  display.print(F("Sats: "));     //print "Sats    :" to display
  display.println(gps.satellites());//print number of satellites detected to display
  display.setCursor(15,52);
  display.setFont(&FreeSans18pt7b); 
  display.println(gps.f_altitude()*3.28084);//print altitude data to display
  
  display.setCursor(20,60);
 
  display.display();
    delay(10000);
    display.clearDisplay();

 //LONG AND LATT LATOUT
  display.setCursor(8,12);          //set text start position to column=0 and row=20
  display.setFont(&FreeSansBold9pt7b);
  display.print(F("Coordinates"));     //print "Altitude" : to display
  
  display.setCursor(2,37);  //LAT POS
  display.setFont();
  display.setTextSize(1);
  display.print(F("LAT:"));
  display.setFont(&FreeSans9pt7b);
  display.setCursor(35,37);
  display.println(flat,5);


  display.setCursor(2,60);  //LON POS
  display.setFont();
  display.setTextSize(1);
  display.print(F("LON:"));
  display.setFont(&FreeSans9pt7b);
  display.setCursor(35,60);
  display.println(flon,5);

    

 display.display();
    delay(10000);
    display.clearDisplay();

    

    display.setCursor(8,10);                       //Oled display, just playing with text size and cursor to get the display you want
    display.setTextColor(WHITE); 
    display.setFont(&FreeSansBold9pt7b);
    display.print(F("Temperature"));
    display.setFont();
    display.setCursor(45,50);
    display.setFont(&FreeSans18pt7b);
    display.print(T,0);
    display.setCursor(20,60);
    display.setFont();
    display.setTextSize(1);
    display.print(F("F"));

       display.display();
    delay(10000);
    display.clearDisplay();












  display.display();                //update OLED display
}


//TEST FOR NEW DATA FROM THE GPS MODULE
bool feedgps()
{
  while (nss.available())
  {
    if (gps.encode(nss.read()))    //Each byte of NEMA data must be giving to TinyGPS by using encode(). True is returned when new data has been fully decoded and can be used
      return true;
  }
  return false;
} 


//GET DATE AND TIME FOR DISPLAY
static void print_date(TinyGPS &gps)
{
  int year;
  byte month, day, hour, minute, second, hundredths;
  unsigned long age;
  gps.crack_datetime(&year, &month, &day, &hour, &minute, &second);
  {
    char sz[32];
    sprintf(sz, "%02d/%02d/%02d  %02d:%02d:%02d",
        month, day, year, hour, minute, second);    
    display.print(sz);                      //Print date and time to OLED
  }

}

You will have to trim down the libraries to fit it all in, or use a Mega. Get rid of the extra font packages, etc.

jremington:
You will have to trim down the libraries to fit it all in, or use a Mega. Get rid of the extra font packages, etc.

You are very right. I took out all the font libraries and got a lot closer.
I'm able to get the GPS data along with Temperature and Pressure from the BME. Still unable to get Humidity though.
I'm also getting noise or artifacts on each segment readout.
If there are any thoughts on how to trim the fat further and get the artifacts (see picture)cleaned up I'd appreciate the help.

I've posted the most current version of the Code:

/*********************************************************************
SCULLCOM Hobby Electronics
Simple GPS System
Using Arduino Pro Mini + OLED 128x64 display + GPS Module
*********************************************************************/

#include <SPI.h>                      //Serial Peripheral Interface (SPI) library for synchronous serial data protocol
#include <Wire.h>                     //Wire library used for I2C communication: Arduino Pro Mini pins used = A4 (SDA) and A5 (SCL)

#include <Adafruit_GFX.h>             //Adafruit graphic display library used for the OLED display
#include <Adafruit_SSD1306.h>         //Adafruit driver for OLED
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
 
#include <SoftwareSerial.h>           //SoftwareSerial library used to allow serial communication on other digital pins (i.e. Pins 3 & 4 for the this GPS project)
#include <TinyGPS.h>                  //GPS Library used to read the data from GPS Module
   
                                    

Adafruit_BME280 bme; // I2C
unsigned long delayTime;


#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET    -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define HOUR_OFFSET   -4

#define OLED_RESET 5
Adafruit_SSD1306 display(OLED_RESET);



TinyGPS gps;                          //Create the TinyGPS object, giving it a name of your choice (here we use the name gps)
SoftwareSerial nss(3, 4);             //set sotfware serial communications to arduino ports 3 and 4 (TX = 3 and RX = 4)


#if (SSD1306_LCDHEIGHT !=64)

#endif



void setup()   {                  
   nss.begin(9600);
   bme.begin();
  
  unsigned long age, date, time, chars = 0;

  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize the OLED and set the I2C address to 0x3C (for the 128x64 OLED) 

   
  display.clearDisplay();             //Clear display buffer.

  display.setTextSize(2);             //set text size to 2 (large)
  display.setTextColor(WHITE);
  display.setCursor(0,0);             //set text start position to column=0 and row=0
  display.print("VANAGON");          //print "SCULLCOM" to display
  
  display.setTextSize(1);             //set text size to 1 (small)
  display.setCursor(0,18);            //set text start position to column=0 and row=18
  display.print(F("GPS SYSTEM"));        //print "GPS SYSTEM" to display
  
  display.setCursor(0,30);            //set text start position to column=0 and row=30
  display.setTextColor(BLACK, WHITE); // 'inverted' text
  display.print(F("INITIALISING ....."));//print "INITIALISING ....." to display
  display.setCursor(0,40);            //set text start position to column=0 and row=40
  display.setTextColor(WHITE);        //
  display.print(F("Trying to locate GPS satellites ..."));  //print "Trying to locate GPS satellites ..." to display
  
  display.setCursor(0,57);            //set text start position to column=0 and row=57
  display.print(F("Please Wait"));       //print "Please Wait" to display
  
  display.display();                  //update OLED with new display data
  delay(1000);                        //short delay
  display.clearDisplay();             //clear display
}


//MAIN PROGRAMME LOOP
void loop() {

bool newdata = false;
  unsigned long start = millis();
  while(millis() - start < 1000){    // Every 1 seconds we print an update
    if (feedgps())
      newdata = true;
  }
  if (newdata)
  { 
    gpsdump(gps);
  }
}
 
 
//PRINT GPS DATA TO OLED DISPLAY
void gpsdump(TinyGPS &gps)
{  
  //print_date(gps);                  //print date and time at top of OLED display
  
  float flat, flon, falt;
  float T = bme.readTemperature()*9/5 + 32;    //Read temperature in °C and conversion to °F
  float P = bme.readPressure() / 100.0F;        
  //float H = bme.readHumidity();
 

  display.clearDisplay();
  
  display.setTextSize(1);           //set text size to 1
  display.setTextColor(WHITE);      //
  display.setCursor(0,0);           //set text start position for date and time (row = 0, column =0)
  //print_date(gps);                  //prints date and time on top line to OLED

 gps.f_get_position(&flat, &flon); //retrieves latitude and longditude data

  //ALTITUDE LATOUT
  display.setCursor(40,1);          //set text start position to column=0 and row=20
 display.setTextSize(2); 
  display.print(F("ELEV"));     //print "Altitude" : to display
  display.setCursor(40,20);          //set text start position to column=0 and row=30
  display.setFont();
  display.setTextSize(1);
  display.print(F("Sats: "));     //print "Sats    :" to display
  display.println(gps.satellites());//print number of satellites detected to display
  display.setCursor(30,37);
  display.setTextSize(3);  
  display.println(gps.f_altitude()*3.28084);//print altitude data to display
  
  display.setCursor(20,60);
 
  display.display();
    delay(10000);
    display.clearDisplay();

 //LONG AND LATT LATOUT
  display.setCursor(27,2);          //set text start position to column=0 and row=20
  display.setTextSize(2);
  display.print(F("COORD"));     //print "Altitude" : to display
  
  display.setCursor(10,30);  //LAT POS
  display.setFont();
  display.setTextSize(1);
  display.print(F("LAT:"));
  display.setTextSize(1);
  display.setCursor(37,30);
  display.println(flat,5);


  display.setCursor(10,45);  //LON POS
  display.setFont();
  display.setTextSize(1);
  display.print(F("LON:"));
  display.setTextSize(1);
  display.setCursor(37,45);
  display.println(flon,5);

     
 display.display();
    delay(10000);
    display.clearDisplay();


//Temperature Layout
    display.setCursor(40,2);                        
    display.setTextSize(2);
    display.print(F("TEMP"));
    display.setCursor(45,30);
    display.setTextSize(3);
    display.print(T,0);
    display.setCursor(10,40);
    display.setTextSize(1);
    display.print(F("F"));

       display.display();
    delay(10000);
    display.clearDisplay();

//Pressure Layout
  display.setCursor(50,2);
    display.setTextSize(2);
    display.print(F("PR"));
    display.setCursor(30,30);
    display.setTextSize(3);
    display.print(P,0);
    display.setCursor(0,40);
    display.setTextSize(1);
    display.print(F("inHg"));
   


     display.display();
    delay(10000);
    display.clearDisplay();

/*
*/


  display.display();                //update OLED display
}


//TEST FOR NEW DATA FROM THE GPS MODULE
bool feedgps()
{
  while (nss.available())
  {
    if (gps.encode(nss.read()))    //Each byte of NEMA data must be giving to TinyGPS by using encode(). True is returned when new data has been fully decoded and can be used
      return true;
  }
  return false;
} 


//GET DATE AND TIME FOR DISPLAY
static void print_date(TinyGPS &gps)
{
  int year;
  byte month, day, hour, minute, second, hundredths;
  unsigned long age;
  gps.crack_datetime(&year, &month, &day, &hour, &minute, &second);
  {
    char sz[32];
    sprintf(sz, "%02d/%02d/%02d  %02d:%02d:%02d",
        month, day, year, hour, minute, second);    
    display.print(sz);                      //Print date and time to OLED
  }

}

In my experience, display artifacts are usually caused by array bound violations, thereby attempting to display nonsensical values.

You have commented out the "read humidity" call.

  //float H = bme.readHumidity();

The sprintf() function takes up a lot of code space. All this can be done with Serial.print statements, which usually take up considerably less.

    char sz[32];
    sprintf(sz, "%02d/%02d/%02d  %02d:%02d:%02d",
        month, day, year, hour, minute, second);