So the code is now this, but all i get now is corrupted symbols after the satellites string. What is happening?
#include <MCUFRIEND_kbv.h>
#include <SoftwareSerial.h>
#include <TinyGPS.h>
#include "Adafruit_GFX.h"
#include <TouchScreen.h>
uint8_t YP = A1; // must be an analog pin, use "An" notation!
uint8_t XM = A2; // must be an analog pin, use "An" notation!
uint8_t YM = 7; // can be a digital pin
uint8_t XP = 6; // can be a digital pin
uint16_t TS_LEFT = 970;
uint16_t TS_RT = 217;
uint16_t TS_TOP = 936;
uint16_t TS_BOT = 189;
MCUFRIEND_kbv tft;
TinyGPS gps;
SoftwareSerial ss(52, 50);
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
TSPoint tp;
void setup() {
// put your setup code here, to run once:
ss.begin(9600);
Serial.begin(9600);
tft.begin(0x9325);
tft.setRotation(1);
tft.fillScreen(0x0000);
tft.setTextColor(0xFFFF);
tft.setTextSize(2);
tft.setCursor(80, 90);
tft.print("GPS Speedometer");
tft.setTextSize(1);
tft.setCursor(100, 110);
tft.print("Created by Sander");
delay(5000);
}
void loop() {
// put your main code here, to run repeatedly:
tft.fillScreen(0x0000);
char tmp[10];
float flat, flon;
unsigned long fix_age; // returns +- latitude/longitude in degrees
gps.f_get_position(&flat, &flon, &fix_age);
short fsat = gps.satellites();
float falt = gps.f_altitude(); // +/- altitude in meters
float fc = gps.f_course(); // course in degrees
float fkmph = gps.f_speed_kmph(); // speed in km/hr
if (fix_age == TinyGPS::GPS_INVALID_AGE)
{
tft.setTextColor(0xF800);
tft.setTextSize(2);
tft.setCursor(1, 1);
tft.print("No GPS Fix!");
}
else if (fix_age > 5000)
{
tft.setTextColor(0xFC00);
tft.setTextSize(2);
tft.setCursor(1, 1);
tft.print("GPS possible stale data!");
}
else
{
tft.setTextColor(0x07E0);
tft.setTextSize(2);
tft.setCursor(1, 1);
tft.print("GPS Fix!");
}
if (fsat == TinyGPS::GPS_INVALID_SATELLITES)
{
tft.setTextColor(0xFFFF);
tft.setTextSize(2);
tft.setCursor(1, 20);
tft.print("Satellites: -");
}
else
{
tft.setTextColor(0xFFFF);
tft.setTextSize(2);
tft.setCursor(1, 20);
tft.print("Satellites: ");
tft.setCursor(142, 20);
tft.print(tmp);
}
print_date(gps);
smartdelay(1000);
}
static void print_date(TinyGPS &gps)
{
int year;
byte month, day, hour, minute, second, hundredths;
unsigned long age;
gps.crack_datetime(&year, &month, &day, &hour, &minute, &second, &hundredths, &age);
if (age == TinyGPS::GPS_INVALID_AGE)
{
tft.setTextColor(0xFFFF);
tft.setTextSize(2);
tft.setCursor(1, 40);
tft.print("UTC: -");
}
else
{
char sz[32];
sprintf(sz, "%02d/%02d/%02d %02d:%02d:%02d ",
day, month, year, hour, minute, second);
String strTemp1 = "UTC: ";
String strTemp2 = strTemp1 + sz;
tft.setTextColor(0xFFFF);
tft.setTextSize(2);
tft.setCursor(1, 40);
tft.print(strTemp2);
}
smartdelay(0);
}
static void smartdelay(unsigned long ms)
{
unsigned long start = millis();
do
{
while (ss.available())
gps.encode(ss.read());
} while (millis() - start < ms);
}