Hello Arduino world :o .
As the title suggests, I cannot seem get the OLED and GPS working at the same time. I can get the GPS to output coordinates to serial monitor in a separate sketch, and i can create a sketch that makes the OLED display text on screen.
What i can not do is get the OLED to display the GPS speed, or anything at all when i "combine" the sketches.
This is my first project so it is very likely that i am overlooking something basic in my sketch through total ignorance of the process. I have spent weeks googling, you-tubing, foruming in search of options and ideas, the script below is roughly the 30th such sketch I've tried.
GPS- UBlox 6m is TX is connected to D4, RX to D3.
OLED- is to SDA-A4 and CLK-A5
In this sketch the OLED screen displays 0, but the serial monitor is indicating the GPS isn't functioning as i'm getting rolling zeros (snip included)
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
static const int RXPin = 4, TXPin = 3;
static const uint32_t GPSBaud = 9600; //was 4800
// The TinyGPS++ object
TinyGPSPlus gps;
// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
String speedinkm;
int f=0;
void setup()
{
display.begin(SSD1306_SWITCHCAPVCC, 0x3c);
display.clearDisplay();
Serial.begin(9600);
ss.begin(GPSBaud);
}
void loop()
{
f = round( gps.speed.kmph());
speedinkm = String(f);
Serial.print(speedinkm);
// This sketch displays information every time a new sentence is correctly encoded.
while (ss.available() > 0)
if (gps.encode(ss.read()))
// displayInfo();
if (millis() > 5000 && gps.charsProcessed() < 10)
Serial.println(F("Speed"));
Serial.println(gps.speed.kmph(), 6);
Serial.print(F(","));
Serial.println(F("Number of sats"));
Serial.println(gps.satellites.value(), 6);
Serial.println(F("GPS Lat"));
Serial.println(gps.location.lat(), 6);
{
display.setTextSize(3);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.println(speedinkm);
display.display();
}
}
Any assistance in the right direction would be very much appreciated.