OLED 0.96" strange problem

Hello,
i´ve a strange problem with my code.
My plan was to make a GPS logger with the OLED screen.
The GPS works perfektly with the serial monitor.
But when i want to show the data on the screen, the programm runs one loop and stops.
I have no idea why.

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

#include <GOFi2cOLED.h>
GOFi2cOLED GOFoled;

static const int RXPin = 11, TXPin = 12;
static const uint32_t GPSBaud = 9600;

TinyGPSPlus gps;

SoftwareSerial ss(RXPin, TXPin);

float vmax;
float v;
float hmax;
float h;
int sat;
int led = 13;

int x,y;

void setup()
{
  Serial.begin(115200);
  ss.begin(GPSBaud);
 
  Serial.println(F("Ironman Logger v.0.6.1"));
  
  vmax=0;
  v=0;
  pinMode(led, OUTPUT);   
  
  
  // default slave address is 0x3D
  GOFoled.init(0x3C);  //initialze  OLED display
  
  GOFoled.display(); // show splashscreen
  delay(2000);
  GOFoled.clearDisplay();
  
}


void loop()
{

  
  
  
  
  
  
  v=gps.speed.kmph();
  if(v > vmax) vmax=v;
  
  h=gps.altitude.meters();
  if(h > hmax) hmax=h;
  
  sat = gps.satellites.value();
  
  if (sat > 0) digitalWrite(led, HIGH);   
  
   static const double LONDON_LAT = 51.508131, LONDON_LON = -0.128002;
   //printDateTime(gps.date, gps.time);
   Serial.print("V (km/h): "); Serial.println(gps.speed.kmph()); 
   Serial.print("Vmax (km/h): "); Serial.println(vmax);
   Serial.print("Hoehe (m): "); Serial.println(gps.altitude.meters());
   Serial.print("Max Hoehe (m): "); Serial.println(hmax);
   Serial.print("Satelliten: "); Serial.println(gps.satellites.value());
   Serial.println(" ");


  GOFoled.clearDisplay();
  GOFoled.setTextSize(1);
  GOFoled.setTextColor(WHITE);
  GOFoled.setCursor(0,0);
  GOFoled.println(h);
  GOFoled.display();


  /*printInt(gps.satellites.value(), gps.satellites.isValid(), 5);
  printInt(gps.hdop.value(), gps.hdop.isValid(), 5);
  printFloat(gps.location.lat(), gps.location.isValid(), 11, 6);
  printFloat(gps.location.lng(), gps.location.isValid(), 12, 6);
  printDateTime(gps.date, gps.time);
  printFloat(gps.altitude.meters(), gps.altitude.isValid(), 7, 2);
  printFloat(gps.course.deg(), gps.course.isValid(), 7, 2);
  printFloat(gps.speed.kmph(), gps.speed.isValid(), 6, 2);
  printStr(gps.course.isValid() ? TinyGPSPlus::cardinal(gps.course.value()) : "*** ", 6);

  unsigned long distanceKmToLondon =
    (unsigned long)TinyGPSPlus::distanceBetween(
      gps.location.lat(),
      gps.location.lng(),
      LONDON_LAT, 
      LONDON_LON) / 1000;
  printInt(distanceKmToLondon, gps.location.isValid(), 9);

  double courseToLondon =
    TinyGPSPlus::courseTo(
      gps.location.lat(),
      gps.location.lng(),
      LONDON_LAT, 
      LONDON_LON);

  printFloat(courseToLondon, gps.location.isValid(), 7, 2);

  const char *cardinalToLondon = TinyGPSPlus::cardinal(courseToLondon);

  printStr(gps.location.isValid() ? cardinalToLondon : "*** ", 6);
  
  

  printInt(gps.charsProcessed(), true, 6);
  printInt(gps.sentencesWithFix(), true, 10);
  printInt(gps.failedChecksum(), true, 9);
  Serial.println();
  */
  
  smartDelay(1000);

  if (millis() > 5000 && gps.charsProcessed() < 10)
    Serial.println(F("No GPS data received: check wiring"));
}

// This custom version of delay() ensures that the gps object
// is being "fed".
static void smartDelay(unsigned long ms)
{
  unsigned long start = millis();
  do 
  {
    while (ss.available())
      gps.encode(ss.read());
  } while (millis() - start < ms);
}

static void printFloat(float val, bool valid, int len, int prec)
{
  if (!valid)
  {
    while (len-- > 1)
      Serial.print('*');
    Serial.print(' ');
  }
  else
  {
    Serial.print(val, prec);
    int vi = abs((int)val);
    int flen = prec + (val < 0.0 ? 2 : 1); // . and -
    flen += vi >= 1000 ? 4 : vi >= 100 ? 3 : vi >= 10 ? 2 : 1;
    for (int i=flen; i<len; ++i)
      Serial.print(' ');
  }
  smartDelay(0);
}

static void printInt(unsigned long val, bool valid, int len)
{
  char sz[32] = "*****************";
  if (valid)
    sprintf(sz, "%ld", val);
  sz[len] = 0;
  for (int i=strlen(sz); i<len; ++i)
    sz[i] = ' ';
  if (len > 0) 
    sz[len-1] = ' ';
  Serial.print(sz);
  smartDelay(0);
}

static void printDateTime(TinyGPSDate &d, TinyGPSTime &t)
{
  if (!d.isValid())
  {
    Serial.print(F("********** "));
  }
  else
  {
    char sz[32];
    sprintf(sz, "%02d/%02d/%02d ", d.month(), d.day(), d.year());
    Serial.print(sz);
  }
  
  if (!t.isValid())
  {
    Serial.print(F("******** "));
  }
  else
  {
    char sz[32];
    sprintf(sz, "%02d:%02d:%02d ", t.hour(), t.minute(), t.second());
    Serial.print(sz);
  }

  printInt(d.age(), d.isValid(), 5);
  smartDelay(0);
}

static void printStr(const char *str, int len)
{
  int slen = strlen(str);
  for (int i=0; i<len; ++i)
    Serial.print(i<slen ? str[i] : ' ');
  smartDelay(0);
}

Do you use this library : GeekOnfire.com is for sale | HugeDomains
Why ? Is it any good ? Is it maintained ? That library is 2 years old.

i have the same problems with the adafruit libary

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

    #include <SPI.h>
    #include <Adafruit_GFX.h>
    #include <Adafruit_SSD1306.h>
    #define OLED_RESET 4
    Adafruit_SSD1306 display(OLED_RESET);


    static const int RXPin = 11, TXPin = 12;
    static const uint32_t GPSBaud = 9600;

    TinyGPSPlus gps;

    SoftwareSerial ss(RXPin, TXPin);

    float vmax;
    float v;
    float hmax;
    float h;
    int sat;
    int led = 13;


    void setup()
    {
      Serial.begin(115200);
      ss.begin(GPSBaud);
     
      Serial.println(F("Ironman Logger v.0.6.1"));
     
      vmax=0;
      v=0;
      pinMode(led, OUTPUT);   
     
     
      display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
      display.display();
      delay(2000);
      display.clearDisplay();
     
    }


    void loop()
    {

     
     
     
     
     
     
      v=gps.speed.kmph();
      if(v > vmax) vmax=v;
     
      h=gps.altitude.meters();
      if(h > hmax) hmax=h;
     
      sat = gps.satellites.value();
     
      if (sat > 0) digitalWrite(led, HIGH);   
     
       static const double LONDON_LAT = 51.508131, LONDON_LON = -0.128002;
       //printDateTime(gps.date, gps.time);
       Serial.print("V (km/h): "); Serial.println(gps.speed.kmph());
       Serial.print("Vmax (km/h): "); Serial.println(vmax);
       Serial.print("Hoehe (m): "); Serial.println(gps.altitude.meters());
       Serial.print("Max Hoehe (m): "); Serial.println(hmax);
       Serial.print("Satelliten: "); Serial.println(gps.satellites.value());
       Serial.println(" ");
       
       // text display tests
      display.clearDisplay();
      display.setTextSize(1);
      display.setTextColor(WHITE);
      display.setCursor(0,0);
      display.println(gps.speed.kmph());
      display.display();


     

     
     
      smartDelay(1000);

      if (millis() > 5000 && gps.charsProcessed() < 10)
        Serial.println(F("No GPS data received: check wiring"));
    }

    // This custom version of delay() ensures that the gps object
    // is being "fed".
    static void smartDelay(unsigned long ms)
    {
      unsigned long start = millis();
      do
      {
        while (ss.available())
          gps.encode(ss.read());
      } while (millis() - start < ms);
    }

    static void printFloat(float val, bool valid, int len, int prec)
    {
      if (!valid)
      {
        while (len-- > 1)
          Serial.print('*');
        Serial.print(' ');
      }
      else
      {
        Serial.print(val, prec);
        int vi = abs((int)val);
        int flen = prec + (val < 0.0 ? 2 : 1); // . and -
        flen += vi >= 1000 ? 4 : vi >= 100 ? 3 : vi >= 10 ? 2 : 1;
        for (int i=flen; i<len; ++i)
          Serial.print(' ');
      }
      smartDelay(0);
    }

    static void printInt(unsigned long val, bool valid, int len)
    {
      char sz[32] = "*****************";
      if (valid)
        sprintf(sz, "%ld", val);
      sz[len] = 0;
      for (int i=strlen(sz); i<len; ++i)
        sz[i] = ' ';
      if (len > 0)
        sz[len-1] = ' ';
      Serial.print(sz);
      smartDelay(0);
    }

    static void printDateTime(TinyGPSDate &d, TinyGPSTime &t)
    {
      if (!d.isValid())
      {
        Serial.print(F("********** "));
      }
      else
      {
        char sz[32];
        sprintf(sz, "%02d/%02d/%02d ", d.month(), d.day(), d.year());
        Serial.print(sz);
      }
     
      if (!t.isValid())
      {
        Serial.print(F("******** "));
      }
      else
      {
        char sz[32];
        sprintf(sz, "%02d:%02d:%02d ", t.hour(), t.minute(), t.second());
        Serial.print(sz);
      }

      printInt(d.age(), d.isValid(), 5);
      smartDelay(0);
    }

    static void printStr(const char *str, int len)
    {
      int slen = strlen(str);
      for (int i=0; i<len; ++i)
        Serial.print(i<slen ? str[i] : ' ');
      smartDelay(0);
    }

in my other project, the code works perfectly

#include <Wire.h>
#include <Adafruit_BMP085.h>

#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

/*************************************************** 
  This is an example for the BMP085 Barometric Pressure & Temp Sensor

  Designed specifically to work with the Adafruit BMP085 Breakout 
  ----> https://www.adafruit.com/products/391

  These displays use I2C to communicate, 2 pins are required to  
  interface
  Adafruit invests time and resources providing this open source code, 
  please support Adafruit and open-source hardware by purchasing 
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.  
  BSD license, all text above must be included in any redistribution
 ****************************************************/

// Connect VCC of the BMP085 sensor to 3.3V (NOT 5.0V!)
// Connect GND to Ground
// Connect SCL to i2c clock - on '168/'328 Arduino Uno/Duemilanove/etc thats Analog 5
// Connect SDA to i2c data - on '168/'328 Arduino Uno/Duemilanove/etc thats Analog 4
// EOC is not used, it signifies an end of conversion
// XCLR is a reset pin, also not used here

Adafruit_BMP085 bmp;
  
void setup() {
  
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C); 
  display.display();
  delay(2000);
  display.clearDisplay();
  
  Serial.begin(9600);
  if (!bmp.begin()) {
	Serial.println("Could not find a valid BMP085 sensor, check wiring!");
	while (1) {}
  }
}
  
void loop() {
    Serial.print("Temperature = ");
    Serial.print(bmp.readTemperature());
    Serial.println(" *C");
    
    Serial.print("Pressure = ");
    Serial.print(bmp.readPressure());
    Serial.println(" Pa");
    
    // Calculate altitude assuming 'standard' barometric
    // pressure of 1013.25 millibar = 101325 Pascal
    Serial.print("Altitude = ");
    Serial.print(bmp.readAltitude());
    Serial.println(" meters");

  // you can get a more precise measurement of altitude
  // if you know the current sea level pressure which will
  // vary with weather and such. If it is 1015 millibars
  // that is equal to 101500 Pascals.
    Serial.print("Real altitude = ");
    Serial.print(bmp.readAltitude(101500));
    Serial.println(" meters");
    
    Serial.println();
    delay(1);
    
    
     // text display tests
  display.clearDisplay();
  display.setTextSize(3);
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  display.println(bmp.readAltitude());
  display.display();
}

Reading your code, I can’t see something popping up that got my attention.

Perhaps you ran out of memory.
You use the TinyGPS++ and the SoftwareSerial, so I’m guessing that is where the problem is.

If you run Arduino IDE 1.5.7 BETA, you also get an estimate of the RAM usage.
Or you can check it in runtime: http://playground.arduino.cc/code/AvailableMemory

Which Arduino board are you using ?

Hello
i use an arduino nano v3

is there any possibility to reduce the ram usage ?

regards

There is not much you can do.
Those libraries create buffers: the Serial library, the Wire library, the TinyGPS++, the SoftwareSerial, and the display libraries.
Perhaps there is an option in those libraries to reduce the buffer size.
Or you can try other libraries for the display (not easy, you have to rewrite your sketch), or use an Arduino Mega 2560.

But I don't know if RAM usage is the problem. Can you try the 1.5.7 version and the AvailableMemory function as I wrote ? It will at least give an indication if RAM could be a problem.

Ok
thanks
I´ll try it this evening with the Arduino IDE 1.5.7 BETA.
The Mega isn´t a option.

thats what the beta say´s:

Sketch uses 15,258 bytes (49%) of program storage space. Maximum is 30,720 bytes.
Global variables use 1,865 bytes (91%) of dynamic memory, leaving 183 bytes for local variables. Maximum is 2,048 bytes.
Low memory available, stability problems may occur

It’s a memory RAM problem.

(91%) of dynamic memory, leaving 183 bytes for local variables
It means you use 91% of RAM and have only 183 bytes for stack and variables on the stack. That is not enough for your sketch with all those libraries.

You have run into a big problem, because this can not be fixed easily.

You use already the F() macro to place strings in flash, but not everywhere.
Can you also use F() with these: Serial.print("V (km/h): ");

You use temporary buffers of 32 byte sometimes. It is possible to use a single global buffer for that, and use that buffer everywhere when you need it. But you have to be very careful that the buffer is not used after a function is called that also uses it.

If you are willing to make a big change, I suggest to keep the TinyGPS and SoftwareSerial and use a different library instead of the Adafruit_GFX with Adafruit_SSD1306. You could try the u8glib. It is a fully graphical library and OLED driver, but it works in a different way.
I guess u8glib uses 40% or RAM, I don’t know how much the Adafruit libraries need.
https://code.google.com/p/u8glib/
It has even been included in the Arduino 1.5.7 BETA (sketch / import library / U8Glib).

oh the u8glib looks very complicated

Yes, you can make a new test sketch and try a few examples of the u8glib. Perhaps you can try adding GPS to that, and see how far you get.