Hi, Im trying to make 2 gauges for my car, using a 0-5v pressure transducer, and a ne06 gps.
I have the fuel pressure gauge part working and it was easy, I got it so I can get both displays working independently using 12c.
I can't get the gps to send the speed data to the oled at all.
Im relatively new to arduino and the programming and am trying to piece together existing code to get it working.
im using a arduino uno, neo6 gps module, and 2 x i2c 128x64 oled screens.
heres my code, Im hoping someone can guide me to see what Im doing wrong, and if theres anything I can do to lower my memory usage.
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
#define TWI_FREQ_LCD 500000L
static const int RXPin = 4, TXPin = 3;
static const uint32_t GPSBaud = 9600;
TinyGPSPlus gps;
SoftwareSerial ss(RXPin, TXPin);
Adafruit_SSD1306 Display1(OLED_RESET);
Adafruit_SSD1306 Display2(OLED_RESET);
int fpVolts = 0;
int fpSignal = 0;
int fpOutput = 0;
void setup() {
Serial.begin(9600);
ss.begin(GPSBaud);
Display1.begin(SSD1306_SWITCHCAPVCC, 0x3D);
Display1.clearDisplay();
Display1.display();
Display2.begin(SSD1306_SWITCHCAPVCC, 0x3C);
Display2.clearDisplay();
Display2.display();
}
void DisplayDraw1() {
Display1.setTextColor(WHITE, BLACK);
Display1.setTextSize(1);
Display1.setCursor(20, 2);
Display1.println("Fuel Presssure:");
Display1.setTextSize(2);
Display1.setCursor(91, 48);
Display1.println("PSI");
}
void DisplayDraw2() {
Display2.setTextColor(WHITE, BLACK);
Display2.setTextSize(1);
Display2.setCursor(20, 2);
Display2.println("SPEED");
Display2.setTextSize(2);
Display2.setCursor(91, 48);
Display2.println("KPH");
}
void FuelPress() {
fpSignal = analogRead(fpVolts);
fpOutput = map(fpSignal, 102, 920, 0, 100);
if (fpOutput > 99) {
Display1.setTextColor(WHITE, BLACK);
Display1.setTextSize(5);
Display1.setCursor(0, 25);
Display1.println(fpOutput);
} else if (fpOutput < 0) {
Display1.setTextSize(7);
Display1.setCursor(0, 15);
Display1.println(0);
} else {
Display1.setTextSize(7);
Display1.setCursor(0, 15);
Display1.println(fpOutput);
}
}
void Speed() {
// Dispatch incoming characters
while (ss.available() > 0)
gps.encode(ss.read());
if (gps.speed.isUpdated())
{
Display2.setTextColor(WHITE, BLACK);
Display2.setTextSize(5);
Display2.setCursor(0, 25);
Display2.println(gps.speed.kmph());
Serial.println(gps.speed.kmph());
}
}
void loop()
{
DisplayDraw1();
FuelPress();
Display1.display();
Display1.clearDisplay();
DisplayDraw2();
Speed();
Display2.display();
Display2.clearDisplay();
}