In order to combine the outputs I moved the sensor read code into a Loop as per a post I read here in the Forum. This works swell as long as my odometer is working at a really low rate. If my odometer rate is fast then the GPS output on the console gets broken into multiple lines like this:
11
12
13
$PGTOP,11,2*6E
$GPRMC14
,195357.600,A,4440.5762,N,12315.5101,W,15
0.00,207.01,280313,,,D*7F
16
17
18
I'm pretty sure that it has to do with how the GPS data is getting read/written to Serial. But I don't have a clue as to what to do about it. Here's my loop code:
Code: Select all
void loop() // run over and over again
{
// read the value from the odometer sensor:
sensorValueA0 = analogRead(sensorPinA0);
//Pullup resister SHOULD cause values to be closer to 1023 but there may be errors. Using 500 allows a wide error margin
if (sensorValueA0 > 500){
//Serial.println("ContactA0");
currValue = 1000;
}
else {
//Serial.println("********");
currValue = 0;
}
//We're looking for the edge from LOW to HIGH
if (currValue != lastValue){
if (currValue == 1000){
Serial.println(pulseCounter);
pulseCounter++; //Increment pulse count by one
if (pulseCounter > 24){
pulseCounter = 0;
}
}
}
lastValue = currValue;
//Read data from GPS
while (Serial1.available()) { //while data available from GPS
Serial.print((char)Serial1.read()); //copy data to console
}
}