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)