Mikiklopsiki
Published © CC BY-NC

Gps bike computer

Nice

IntermediateShowcase (no instructions)975
Gps bike computer

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
Nokia 5110 display
×1
Neo 6m Gps
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE
Tinycad

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Flux, Soldering
Solder Flux, Soldering

Story

Read more

Schematics

Schematic

Code

Code

C/C++
/*

-----------Bike comuter-----------
----by Trybulski Mikolaj----------
*/

//gps libaries
#include <TinyGPS++.h>
#include <SoftwareSerial.h>

//lcd libaries
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>

//variables used for distance calculations
float latold;
float longold;
float wholedistance;

// The TinyGPS++ object
TinyGPSPlus gps;

// The serial connection to the GPS device
SoftwareSerial ss(7, 6); //tx (on gps) - 7, rx (on gps) - 6

//lcd settin

//pinout 9 CLK , 10 DIN , 11 DC , 12 CE , 2 RST , 8  BL 
const int clk = 9;
const int din = 10;
const int dc = 11;
const int ce = 12;
const int rst = 2;
const int bl = 8; //low - on, high - off

Adafruit_PCD8544 display = Adafruit_PCD8544(clk, din, dc, ce, rst);



void setup(){
  wholedistance = 0;
  latold = 0;
  longold = 0;
  
  ss.begin(9600);
  delay(300);
  pinMode(bl, OUTPUT);
 digitalWrite(bl, LOW);
  display.begin();
  display.setContrast(60);
 display.clearDisplay();
 
 display.setTextColor(BLACK);
 display.setCursor(0,0);
  display.setTextSize(1);
  display.print("Bike computer v1.0, made by Trybulski Mikolaj  ");
    display.display();
    delay(2000);
 display.clearDisplay();
 display.setCursor(0,0);
  display.setTextSize(2);
  display.print("waitingfor gps... ");
    display.display();
}

void loop(){
  display.clearDisplay();
   display.setTextColor(BLACK);
  // This sketch displays information every time a new sentence is correctly encoded.
  while (ss.available() > 0){
    gps.encode(ss.read());

    
    if (gps.location.isUpdated()){

    //dist calculations
  if(latold == 0 || longold == 0){//dont calculate using 0 coordinates (which are set for stary value)
  latold = gps.location.lat();//update ealier position
  longold = gps.location.lng();
  delay(300);
    }
    else{
  if(gps.location.lat() == latold || gps.location.lng() == longold){
    delay(1000);
    } 
  else{
  float distLat = abs(gps.location.lat() - latold) * 111194.9;
  float distLong = 111194.9 * abs(gps.location.lng() - longold) * cos(radians((gps.location.lat() + latold) / 2));
  float distance = sqrt(pow(distLat, 2) + pow(distLong, 2));        // equation form https://www.instructables.com/Distance-measuring-and-more-device-using-Arduino-a/
  latold = gps.location.lat();//update ealier position
  longold = gps.location.lng();
  wholedistance = distance + wholedistance; // add newly calculated distance to ealier one for trip distance
    }
    }
    //dist display
  display.setTextSize(1.5);
  display.setCursor(0,25);
  display.print(wholedistance / 1000);
  display.println("km");
  
  int readvalue = gps.course.deg(); //define and round heading
  int speedo = gps.speed.kmph(); // define and round speed
 
  display.setCursor(0,0);
  display.setTextSize(3);
  display.print(speedo);
  display.setTextSize(1);
  display.print("kph ");
  display.setTextSize(2);
  
  if (readvalue >=338 || readvalue < 22){
    display.println("N");
    } 
  else if (readvalue >= 22 && readvalue < 68)
  {
    display.println("NE");
    }
    else if (readvalue >= 68 && readvalue < 113)
  {
    display.println("E");
    }
      else if (readvalue >= 113 && readvalue < 158)
  {
    display.println("SE");
    }
     else if (readvalue >= 158 && readvalue < 203)
  {
    display.println("S");
    }
    else if (readvalue >= 203 && readvalue < 248)
  {
    display.println("SW");
    }
   else if (readvalue >= 248 && readvalue < 293)
  {
   display.println("W");
    }
   else if (readvalue >= 293 && readvalue < 338)
  {
  display.println("NW");
    }

 display.display();
  delay(1000);  //wait. we dont need to update so many times
  
    }
  }
}

Credits

Mikiklopsiki
0 projects • 2 followers
Contact

Comments

Please log in or sign up to comment.