Hello everybody
i'm currently building a GPS speedometer for my motorcycle. and for that i'm using a NEO-6m GPS module and a SSD1306 i2c display.
The problem i'm having is that, when i'm implementing the GPS in the final, and otherwise functional code, it stops working.
the display writes everything on the display, but all the places it's suppost to write some sort of GPS data, it just display zeros.
Can you please help me?
#include <SPI.h>
#include <Wire.h>
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 Display(OLED_RESET);
static const int RXPin = 4, TXPin = 3;
// The TinyGPS++ object
TinyGPSPlus gps;
// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);
int r = 0; //variable for fuel gauge
int G1 = 0; //gear 1
int G2 = 1; //gear 2
int G3 = 2; //gear 3
int G4 = 5; //gear 4
int G5 = 6; //gear 5
void setup() {
ss.begin(9600);
pinMode(G1, INPUT); // set G1 to input
pinMode(G2, INPUT); // set G2 to input
pinMode(G3, INPUT); // set G3 to input
pinMode(G4, INPUT); // set G4 to input
pinMode(G5, INPUT); // set G5 to input
digitalWrite(G1, HIGH); // activate pullup risistor
digitalWrite(G2, HIGH); // activate pullup risistor
digitalWrite(G3, HIGH); // activate pullup risistor
digitalWrite(G4, HIGH); // activate pullup risistor
digitalWrite(G5, HIGH); // activate pullup risistor
Display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x32)
Display.clearDisplay();
Display.display();
DrawConstants();
}
void loop() {
if (ss.available() > 0){ //following code display the GPS part
if (gps.encode(ss.read()))
{
int SPEED = gps.speed.kmph(); //convert the speed to zero decimal
Display.setTextSize(1);
Display.setTextColor(WHITE);
Display.setCursor(0, 9);
Display.println("Clock");
Display.setCursor(34, 9);
Display.println(gps.time.hour()+2);
Display.setCursor(44, 9);
Display.println(":");
Display.setCursor(48, 9);
Display.println(gps.time.minute());
Display.setTextSize(5);
Display.setTextColor(WHITE);
Display.setCursor(0, 28);
Display.println(SPEED);
Display.setTextSize(1);
Display.setCursor(0, 18);
Display.println("Sat");
Display.setCursor(34, 18);
Display.println(gps.satellites.value());
Display.display();
}
}
r = analogRead(A0); //the following code display the fuel gauge
r = r / 7.98;
//draw the bar graph
Display.fillRect(r + 30, 0, 97 - r, 4, BLACK); // (r, 50, 128 - r, 10, BLACK)
Display.fillRect(30, 0, r, 4, WHITE); //(3, 50, r, 10, WHITE)
Display.drawPixel(54, 4, 1);
Display.drawPixel(78, 4, 1);
Display.drawPixel(79 , 4, 1);
Display.drawPixel(103, 4, 1);
if (digitalRead (G1) == 0) //the last bit of code display the gear i'm in
{
Display.fillRect(100,25,20,30,BLACK);
Display.setTextSize(3);
Display.setTextColor(WHITE);
Display.setCursor(100, 25);
Display.println("1");
}
else if (digitalRead (G2) == 0)
{
Display.fillRect(100,25,20,30,BLACK);
Display.setTextSize(3);
Display.setTextColor(WHITE);
Display.setCursor(100, 25);
Display.println("2");
}
else if (digitalRead (G3) == 0)
{
Display.fillRect(100,25,20,30,BLACK);
Display.setTextSize(3);
Display.setTextColor(WHITE);
Display.setCursor(100, 25);
Display.println("3");
}
else if (digitalRead (G4) == 0)
{
Display.fillRect(100,25,20,30,BLACK);
Display.setTextSize(3);
Display.setTextColor(WHITE);
Display.setCursor(100, 25);
Display.println("4");
}
else if (digitalRead (G5) == 0)
{
Display.fillRect(100,25,20,30,BLACK);
Display.setTextSize(3);
Display.setTextColor(WHITE);
Display.setCursor(100, 25);
Display.println("5");
}
else
{
Display.fillRect(100,25,20,30,BLACK);
Display.setTextSize(3);
Display.setTextColor(WHITE);
Display.setCursor(100, 25);
Display.println("N");
}
// now that the display is build, display it...
Display.display();
}
void DrawConstants(void) { // this void display the constants on the display
Display.setTextSize(1);
Display.setTextColor(WHITE);
Display.setCursor(90, 57);
Display.println("Km/h");
Display.setTextSize(1);
Display.setTextColor(WHITE);
Display.setCursor(96, 10);
Display.println("Gear");
Display.drawRect(29,0,99,6,1);
Display.setTextSize(1);
Display.setTextColor(WHITE);
Display.setCursor(0, 0); //19
Display.println("Fuel");
Display.display();
}