# Help with trip computer

Hi, i’m trying to make a trip computer for my boat, I want to show the Speed ​​as well as fuel consumption per Nautical mile.
I’m getting in the speed and showing consumption per hour, but not getting into the calculation where the consumption per hour is to
be divided with the speed to get the consumption per Nautical mile (Nm)

The speed (knots) comes from Gps via Nmea message RMC

A flow meter measures fuel consumption and gives 2500 pulses per liter

The pulses per second should be multiplied by 3600 (to get it per hour) divided by 2500 (to get it
in liters) so far, it works … Now I want to divide it with the speed to get the consumption per Nautical mile…
I needed help!!!

I basically do not know about programming, only copy / paste …
Any ideas, anyone ??

/* Parts of code borrowed from http://www.lawicel.se/kod/arduino/GpsLcd1.ino

Example on RMC from GPS “\$ GPRMC, 094510.000, A, 5609.6095, N, 01335.7731, E, 0.03.88.49.120913 , A * 57”

The flowmeter gives 2500 pulses per liter */
#include <FreqMeasure.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

char buffer[120];

byte CommaPos[20];
byte bufferPos = 0;
byte bufferStat = 0;

char datavalid[2];
char knots[8];
byte CountCommas(void){

byte tmp;
byte NoOfCommas = 0;

for (tmp = 0; tmp < bufferPos; tmp++) {

if (buffer[tmp] == ‘,’) {
CommaPos[NoOfCommas++] =tmp;
}
}
return NoOfCommas;
}

void extract(char *buf1, char *buf2, byte item) {
byte tmp;

for (tmp = 1; tmp < (CommaPos[item+1] - CommaPos[item]); tmp++) {
buf1[tmp - 1] = buf2[CommaPos[item] + tmp];
}

buf1[tmp] = 0;
}

byte parseNMEA(void){
byte comma = 0;
byte tmp = 0;
byte NoOfCommas;

NoOfCommas = CountCommas();

if (buffer[0] == ‘G’ && buffer[1] == ‘P’) {
if (buffer[2] == ‘R’ && buffer[3] == ‘M’ && buffer[4] == ‘C’ ) {
// \$GPRMC

if (NoOfCommas == 13) {
extract(datavalid, buffer, 1);
if (datavalid[0] == ‘A’) {
extract(knots, buffer, 6); }
else
{
return 0;
}
}
else {
return 0;
}
}
}
return 1; }
void setup()
{
Serial.begin(9600);
lcd.begin(16, 2);
lcd.setCursor(7, 1);
lcd.print(“L/Nm”);
FreqMeasure.begin();
}
double sum=0;
int count=0;

void loop() {
char c;
byte result;

if (bufferStat < 2) {
if (Serial.available()) {
if (c == ‘\$’) {
bufferStat = 1;
bufferPos = 0;
}
else if (bufferStat == 1){
if (c == '’) {
buffer[bufferPos] = 0;
bufferStat = 2;
Serial.println(buffer);
}
else if (bufferPos < 120) {
buffer[bufferPos++] = c;
}
else {
bufferPos = 0;
bufferStat = 0;
}
}
}
}
else {
result = parseNMEA();
lcd.setCursor(0, 1);
lcd.print(“Kn”);
lcd.print(knots);
bufferStat = 0;}
{
delayMicroseconds(50);
if (FreqMeasure.available()) {
sum = sum +
FreqMeasure.read(); //2500 pp/l * 3600 =L/h
count = count + 1;
if (count > 30) {
float LNm= FreqMeasure.countToFrequency(sum / count /3600
2500);
lcd.setCursor(11, 1);
lcd.print(LNm);
Serial.println(LNm);
sum = 0;
count = 0;
}
}
}
}

Any ideas, anyone ??

If you want me to read that code, you will properly indent it, put EVERY { on a line BY ITSELF, put EVERY } on a line BY ITSELF, AND use code tags when you re-post it. That stuff looks like a dog's breakfast.