Close

Code Overview

A project log for Honda OBD1 Digital Tachometer

In this project I'm building a digital tachometer for 90's Hondas.

nigelNigel 08/21/2014 at 04:130 Comments

I'll go over the code in chunks. Instead of pasting it here, please open up the bitbucket repo or the .ino file in an IDE and follow along with the line numbers.

Lines 1-30: Basic declarations and includes nothing special here.

Lines 32-89: This is our initialization step. We start up software serial (using this because of how often I'm updating the firmware. I want to keep the HW serial free for now. It then runs through the little start up routine so you can check for any issues with the display. After than it latches the interrupt to wait for the first pulse of the car to begin measurements.

Lines 91-98: Main loop. Super simple, just keep looping and if more than .1 seconds have passed since the last screen update, update the screen.

Lines 100-106: Fresh start routine. Pretty much resets the timing so that the very first measurement is accurate and doesn't take in a ridiculously long value.

Lines 108-121: Stores the time between pulses in an array. It rolls through the 5 locations in the array to gives us our values that we then average.

Lines 121-173: This is the anti-jitter code. I found this on the Arduino forums years ago and haven't been able to find the original thread to give credit to. It takes in the to be displayed value and a threshold and determines if the value is ok to display. It looks for either two consecutive values trending in the same direction or the gap between two values is larger than the specified threshold.

Lines 174-187: The code that does the actual writing. Since the display expects 4 digits per send we must send a null character if the number is less than 1000.

Lines 189-233: This is the function that actually calculates the RPM to update. First it checks to see if it is in the correct state for display dim. Then it calculates the RPM from the stored pulse times. Following this is it checks to see if it needs to turn on any of the LED's , as well as if it needs to display the car is off. Finally it sends the RPM value to be printed on screen and the process starts over again.

Discussions