2

I am getting started with GPS modules, for my project I am using the NEO 6M GPS module with a Ceramic Antenna. So, earlier I tried to connect the GPS module with an Arduino Nano and was able to successfully display the GPS NEMA sentences output on the Arduino IDE Serial Monitor, although the GPS module was not able to connect to any satellites.

Now, I am trying to add an SSD1306 OLED module to this project. So, that the latitude and the longitude values can be fetched from the GPS module and can be displayed on the OLED Screen whenever the GPS updates its position.

The code which I have written so far was compiled properly in the Arduino IDE, but the OLED module failed to display the expected information. I kept on getting the "SSD1306 allocation failed" error on the Serial Monitor.

I have already verified the I2C Address for my OLED display module which is 0x3C instead of 0x3D.

I have also tested the OLED display with a separate code and it is working fine.

Then also I am not able to figure out what's wrong with this code that it is leading to these unexpected results.

The code which I am using for this project is attached below.

So, if a fellow programmer from the community can help me solve this issue then that would be really appreciated.

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

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

#define OLED_WIDTH 128
#define OLED_HEIGHT 64

#define OLED_RESET -1
#define OLED_ADDR 0x3C
Adafruit_SSD1306 oled(OLED_WIDTH, OLED_HEIGHT, &Wire, OLED_RESET);

SoftwareSerial serial_connect(4, 3); //Rx:pin(4) Tx:pin(3) 
TinyGPSPlus gps;

void setup()
{
  Serial.begin(9600);
  serial_connect.begin(9600);
  
  // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  if(!oled.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR)) 
  {
    Serial.println(F("SSD1306 allocation failed"));
    for(;;); // Don't proceed, loop forever
  }

  Serial.println("GPS start");

  oled.clearDisplay();
  
  oled.setTextSize(1);
  oled.setTextColor(SSD1306_WHITE);
  
  oled.setCursor(0, 0);
  oled.print("Detecting GPS");
  
  oled.setCursor(0, 10);
  oled.print("Coordinates");
  
  oled.display();
  delay(5000); //5 seconds delay
}

void loop()
{
  while(serial_connect.available())
  {
    gps.encode(serial_connect.read());
  }
  if(gps.location.isUpdated())
  {
    Serial.println("Satellite Count:");
    Serial.println(gps.satellites.value());
    Serial.println("Latitude:");
    Serial.println(gps.location.lat(),6);
    Serial.println("Longitude:");
    Serial.println(gps.location.lng(),6);
    Serial.println("Speed MPH:");
    Serial.println(gps.speed.mph());
    Serial.println("Altitude Feet:");
    Serial.println(gps.altitude.feet());
    Serial.println(" ");
    
    oled.clearDisplay();
    
    oled.setCursor(0, 0);
    oled.print("Lati=");
    
    oled.setCursor(0, 10);
    oled.print(gps.location.lat(),6);
    
    oled.setCursor(10, 0);
    oled.print("Long=");
    
    oled.setCursor(10, 10);
    oled.print(gps.location.lng(),6);

    oled.display();
    delay(500);
  }
}

1 Answers1

0

It's a bit late now, but letsee... That's an interesting issue.

Your code follows the examples provided by Adafruit, w.r.t. SSD1306. When you define pins 3 and 4 for the GPS's UART, which pins are you using? D3 and D4? Which pins are you using for the I2C OLED display? You have to make sure that your OLED display has the SDA and the SCL connected to A4 and A5, respectively.

Have you done anything different when the display worked, e.g. use a different platform or MCU?

Nick S.
  • 168
  • 1
  • 12
  • First of all, Thank you @Nick S. for replying to my question/query. I am using Pin numbers D3 and D4 as TX and RX for the GPS module (check line number 16 of the code) and also I am using the Pin A4 as SDA and Pin A5 as SCL of Arduino Nano. If you found some solution for the above problem then please share. – atechofficials Jul 27 '22 at 19:10
  • @atechofficials I do not, but I'm willing to help you troubleshoot it. Did you test the screen separately with the same nano? Did you use the same allocation check in the example you've tested and had the OLED connected to the same (A4/A5) pins as now? What happens if you comment out the software serial stuff? – Nick S. Jul 29 '22 at 04:31