The arduino is reponsible for reading the frequency from crankshaft position sensor, calculating the frequency using FreqMeasure Library from Paul Stoffregen and sending to Android app.
The Android app receives the data from bluetooth and draw the elements.
Earlier version:
Arduino code:
#include <FreqMeasure.h>
void setup() {
Serial.begin(9600);
FreqMeasure.begin();
}
void loop() {
if (FreqMeasure.available()) {
int frequency = FreqMeasure.countToFrequency(FreqMeasure.read());
char s[5];
sprintf(s,"%d;\0", frequency);
Serial.write(s);
}
}
I can't tell from the video, because it's accelerating/decelerating the whole time, but I'm guessing you found that the RPM gauge you built is inconsistent at steady-state.
All the engines I know of use the crank sensor for engine position as well as engine speed, so they always have a synchronization pulse built into the crank trigger wheel so the engine controller knows where in the rotation the engine is, and can control such things as spark and fuel timing, which depend on engine position.
To do this, the most common strategy is to use a missing tooth to represent a specific position on the wheel. The two most common styles I've seen are 36-1 and 60-2 tooth wheels. (That's thirty-six minus one or sixty minus two, where the minus refers to how many teeth in the normal pattern are missing to create the synchronization pulse).
If your engine is running at 650 RPM at idle and hits a synchronization pulse, it may suddenly report 325 or 217 RPM due to the synchronization pulse.
Based on the code you posted, I'm going to guess you have a 60-2 tooth wheel, because one of the nice things about that wheel is that the signal converts from pulses per second to revolutions per minute without any conversion (650 pulses per second / 60 teeth * 60 seconds/minute = 650 RPM). Since you had no such conversion in your code, this is a good guess.
There are a couple methods you could use to deal with the synchronization pulse:
1) Ignore it, you'll only see it occasionally (I'm guessing this is what you did originally)
2) Filter it. I find an exponential filter works nicely for automotive use, and it's easy to implement., You may need to play with the filter constant a bit, and it will likely leave your result a little bit low, but there are existing libraries for it (here's one: https://www.megunolink.com/documentation/arduino-libraries/exponential-filter/ )
3) Do what engine controllers do: expect it, find it, and remove it from the engine speed calculation.
The easiest way to do this is to know what the expected ratio is: for a 60-2 tooth wheel, the missing pulse will be generally 3x as long as the previous pulse. Allowing for normal acceleration and deceleration, look for a pulse that is 2x to 4x as long as the previous, and don't include it in your speed calculations.
Hope this helps!