ESP8266 tachometer/alternator tach

285 views
Skip to first unread message

Zim

unread,
Apr 15, 2019, 11:39:16 AM4/15/19
to annex_w...@googlegroups.com

Firefox.jpg





This can be used to view engine rpm by alternator/charging/ignition system frequency.
I will use it to test small engines / boats / gen sets / automotives / Diesel engines.
The variation in applications will require a variation in interface characteristics.
Stator voltages can vary from 6v to 40v, so a clean pulse signal of 3.3v must be achieved
through additional electronics. (work in progress).
The 1P - 6P is determined by stator "poles/2" or number of ignition instances per revolution if used on ignition primary.
I tested this with a signal generator and it works fine in lab conditions.










Schematic.jpg












CODE: xxxx.bas

'Zim's Tach with last used mode recall
onHtmlreload initial_page
gosub initial_page
timer0 1000, refresh_vars   
wait

initial_page:
'file.save "/plset.txt", str$(5)   'XXXXXXXXXXXXXXXXXXXX   uncheck this for the first run so it creates a memory txt file 
cls
PIN.MODE 5, input
COUNTER.SETUP 1, 5, 1
uS = 0
rpm = 0
pulses = val(file.read$("/plset.txt")) 'sets to last setting used
dropd$ = "background-color:lightblue;text-align:center;width:55px;height:55px;box-shadow: 0px 0px black;font-size:24;font-weight:bold"
exitb$ = "background-color:red;text-align:center;width:165px;height:55px;box-shadow: 0px 0px black;font-size:24;font-weight:bold;"
txtb$ = "background-color:black;text-align:center;width:55px;height:55px;font-size:40; color:white; border-radius:8px; font-weight:bold"
jsexternal "/gauge.min.js" ' load javascript library for gauges
pause 500 ' gives time to the browser to import the library

A$ = ""
A$ = A$ + |<style> body { background-color: black; }</style>| ' this defines the back color of the page (body)
A$ = A$ + |<div align="center" style="background-color:black;">| ' this permit to define the back color and the alignment (<div>)
A$ = A$ + |<canvas data-type="radial-gauge"|
A$ = A$ + |    data-width="335"|
A$ = A$ + |    data-height="335"|
A$ = A$ + |    data-title="RPM"|
A$ = A$ + |    data-units="X100"|
A$ = A$ + |    data-min-value="0"|
A$ = A$ + |    data-max-value="70"|
A$ = A$ + |    data-major-ticks="0,,10,,20,,30,,40,,50,,60,,70"|
A$ = A$ + |    data-minor-ticks="5"|
A$ = A$ + |    data-stroke-ticks="true"|
A$ = A$ + |    data-highlights='[|
A$ = A$ + |    {"from": 0, "to": 70, "color": "rgba(192,192,192,.2)"}|
A$ = A$ + |    ]'|
A$ = A$ + |    data-color-plate="#fff"|
A$ = A$ + |    data-color-numbers="#000000"|
A$ = A$ + |    data-border-shadow-width="8"|
A$ = A$ + |    data-borders="true"|
A$ = A$ + |    data-needle-type="arrow"|
A$ = A$ + |    data-needle-width="4"|
A$ = A$ + |    data-needle-circle-size="8"|
A$ = A$ + |    data-needle-circle-outer="true"|
A$ = A$ + |    data-needle-circle-inner="false"|
A$ = A$ + |    data-animation-duration="500"|
A$ = A$ + |    data-animation-rule="linear"|
A$ = A$ + |    data-color-border-outer="#333"|
A$ = A$ + |    data-color-border-outer-end="#111"|
A$ = A$ + |    data-color-border-middle="#FF0000"|
A$ = A$ + |    data-color-border-middle-end="#111"|
A$ = A$ + |    data-color-border-inner="#222"|
A$ = A$ + |    data-color-border-inner-end="#333"|
A$ = A$ + |    data-color-needle-circle-outer="#333"|
A$ = A$ + |    data-color-needle-circle-outer-end="#111"|
A$ = A$ + |    data-color-needle-circle-inner="#111"|
A$ = A$ + |    data-color-needle-circle-inner-end="#222"|
A$ = A$ + |    data-animation-duration="100"|
A$ = A$ + |    data-font-numbers-size="32"|
A$ = A$ + |    data-value-box="y"|   'gives a text box
A$ = A$ + |    data-var="rpm"|   ' this is where the variable is defined
A$ = A$ + |    ></canvas></div>|
A$ = A$ + |<table align='center' width='340'>|
A$ = A$ + |<center><th>|
A$ = A$ + textbox$(pulses, "txt2")
A$ = A$ + cssid$("txt2", txtb$)
A$ = A$ + |</th></center><center><th>|
A$ = A$ + |<p><font color = 'white', font size = '5'>Pulses Per  Revolution</font></p>|
A$ = A$ + |</th></center></table>|
A$ = A$ + |<center>|
A$ = A$ + button$("1P",pulse1,"but0")
A$ = A$ + cssid$("but0" , dropd$)
A$ = A$ + button$("2P",pulse2,"but1")
A$ = A$ + cssid$("but1" , dropd$)
A$ = A$ + button$("3P",pulse3,"but2")
A$ = A$ + cssid$("but2" , dropd$)
A$ = A$ + button$("4P",pulse4,"but3")
A$ = A$ + cssid$("but3" , dropd$)
A$ = A$ + button$("5P",pulse5,"but4")
A$ = A$ + cssid$("but4" , dropd$)
A$ = A$ + button$("6P",pulse6,"but5")
A$ = A$ + cssid$("but5" , dropd$)
A$ = A$ + |</center><center><br><br>|
A$ = A$ + button$("Refresh",initial_page,"but7")
A$ = A$ + cssid$("but7" ,exitb$ & "background-color:lightblue")
A$ = A$ + button$("Exit",exitt,"but6")
A$ = A$ + cssid$("but6" , exitb$)
A$ = A$ + |</center>|
html A$
jscall "initGauges();"  'force the initialisation of all the gauges
return

refresh_vars:
'wlog uS              ' alive check
uS = COUNTER.PERIOD(1)
if uS = 0 then uS = 1          'stops a math error
rpm = 10000 / uS / pulses * 60       '10000 instead of 1000000 cause its X100 tach
if rpm > 50000 then rpm = 0        'stops a error
COUNTER.RESET 1               'allows needle to zero with no signal
refresh
return

pulse1:
pulses = 1
file.save "/plset.txt", str$(1)
refresh
return

pulse2:
pulses = 2
file.save "/plset.txt", str$(2)
refresh
return

pulse3:
pulses = 3
file.save "/plset.txt", str$(3)
refresh
return

pulse4:
pulses = 4
file.save "/plset.txt", str$(4)
refresh
return

pulse5:
pulses = 5
file.save "/plset.txt", str$(5)
refresh
return

pulse6:
pulses = 6
file.save "/plset.txt", str$(6)
refresh
return

exitt:
cls
wait

Zim

unread,
Apr 22, 2019, 9:51:23 PM4/22/19
to Annex WiFi RDS
 A working interface has been added...

Dwight

unread,
Apr 24, 2019, 11:53:32 PM4/24/19
to Annex WiFi RDS
Hi Zim,

Thanks for sharing your code!

I loaded it up on a Lolin D1 mini Pro and gave it a test run.

I was getting a "file not found"  line 14
So I added this at the start of the program
file.save "/plset.txt", str$(1)

and now it runs!

You may want to consider what happens on a first time run since the file "plset.txt" will not exist till it is saved/created the first time through.

I just love how easy it is to demo other's code for a quick look.
I hooked up a square wave pulse to gpio5 and now I can see the tach move as I adjust the frequency.

dwight

Zim

unread,
Apr 25, 2019, 12:57:22 AM4/25/19
to Annex WiFi RDS
Hi Dwight
Read line 8. It will generate the file if you uncomment it on the first run.
Zim

cicciocb

unread,
Apr 25, 2019, 5:28:40 AM4/25/19
to Annex WiFi RDS
You could use the file.exists function to check if the file already exists

Dwight

unread,
Apr 25, 2019, 10:15:41 AM4/25/19
to Annex WiFi RDS
sheesh, I actually have to move my eyes back and forth and read? :-)  Now you expecting a lot from me!

Missed that Zim, It was late and just wanted to do a quick run.
Possibly Cicciocb's suggestion would be good to try.

Anyways thanks for sharing.
Havent had much time to play with Annex.  Hopefully this weekend.

cheers
dwight

Zim

unread,
Apr 25, 2019, 11:36:15 AM4/25/19
to Annex WiFi RDS
sheesh, I actually have to move my eyes back and forth and read? :-)  Now you expecting a lot from me!


LOL, I think we all suffer from that from time to time!

Zim

Dwight

unread,
Apr 25, 2019, 1:25:35 PM4/25/19
to Annex WiFi RDS
Alternative Input Clamping circuit...

Hi Zim,
Here is a circuit we used on another project to insure that the input signal would not damage or stress the micro it was connected to.

In this case the diode is a 5 volt Zener which would serve to clamp any inputs to 5V max.
You might want to consider using a 3.3V Zener instead.  Although some say the esp8266 is 5 volt tolerant.


Zim

unread,
Apr 25, 2019, 4:49:31 PM4/25/19
to Annex WiFi RDS
Hi Dwight
I have tried the Zener approach.
The 5 1n4148 does a better job than a zener cause its much faster switching. In series, they also provide voltage control as a slower zener does. I've also tried several different caps in parallel, but still get random short uS triggers.

Dwight

unread,
Apr 25, 2019, 10:15:34 PM4/25/19
to Annex WiFi RDS
Hi Zim,

Are you seeing the "random short uS signals"  when connected to a real engine or while on the bench with a test signal?
Have you confirmed that they are really not there via an Oscope?
You might consider some math in your code to do some averaging to throw out the random short time pulse.

just a quick couple of thoughts
dwight

PrecisionClays

unread,
May 11, 2020, 3:58:33 PM5/11/20
to annex_w...@googlegroups.com
I saw this project and decided to add a shift light to my race car dash using a Neopixel string and the code Zim wrote.  Here's a video of it working.  I haven't hooked up to my car yet, probably next weekend.  I need to do a bit of clean up on the code to make it more easily configurable, pulse storage as Zim has done but also the shift light points.  I'll make a web page that lets someone, with a password, make changes.  Thanks Zim.
Reply all
Reply to author
Forward
0 new messages