Neo 6m wont work with 0.96" oled (Adafruit_SSD1306)

Hi, i am trying to get a display to show lat long and more... I am not the best at programming and therefore i cant figure out how to solve it. The problem is that the display wont work without this if statement:

"if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println("SSD1306 allocation failed");"
for(;;); }

and when i add it in the code, the

"if(gps.location.isUpdated()){}"

wont run instead. Both work separately but i would love to have them work together.

#include "TinyGPS++.h"
#include "SoftwareSerial.h"
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

#define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

SoftwareSerial serial_connection(4, 3); //RX=pin 4, TX=pin 3
TinyGPSPlus gps;
void setup()
{
Serial.begin(9600);
serial_connection.begin(9600);
/*
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // <-------------------- this one
Serial.println("SSD1306 allocation failed");
for(;;);
}
*/
display.display();

}

void loop()
{
while(serial_connection.available())
{
gps.encode(serial_connection.read());
}
if(gps.location.isUpdated())// <-------------------- this one
{

delay(1000);

Serial.println(gps.satellites.value());
Serial.println(gps.location.lat(), 6);
Serial.println(gps.location.lng(), 6);
Serial.println(gps.speed.kmph());
Serial.println(gps.altitude.meters());
}
}

GPS_test_3.ino (1.08 KB)

My guess is that you're running out of memory. The SSD1306 library uses 50% of RAM of an UNO.

Please read the sticky on how to use this forum, edit your original post to add [code][/code] tags around your code, tell us what board you're using, if it's a compilation or runtime error, and what you've tried to debug it.

Pieter

#include "TinyGPS++.h"
#include "SoftwareSerial.h"
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

Adafruit_SSD1306 display(128, 64, &Wire, 4);
SoftwareSerial serial_connection(4, 3); //RX=pin 4, TX=pin 3
TinyGPSPlus gps;

void setup()
{
  Serial.begin(9600);
  serial_connection.begin(9600);
  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3D)) {
    Serial.println(F("SSD1306 allocation failed"));
    for (;;);
  }
  display.display();
}

void loop()
{
  if (serial_connection.available()) gps.encode(serial_connection.read());
  if (gps.location.isUpdated()) {
    delay(1000);
    Serial.println(gps.satellites.value());
    Serial.println(gps.location.lat(), 6);
    Serial.println(gps.location.lng(), 6);
    Serial.println(gps.speed.kmph());
    Serial.println(gps.altitude.meters());
  }
}

Could be that your reset pin and software serial pin are both 4?

1 Like