diy mpg gauge [ Archive] - GasSavers.org - Helping You Save at the Pump


PDA

View Full Version : diy mpg gauge


skewbe
07-08-2007, 11:16 AM
Update, skip ahead to a working model:
http://www.gassavers.org/showthread.php?p=64732#post6473232


It seems a simple enough task, take a vehicle speed sensor "reading" and divide it by the injector duty cycle and put it on a meter. In fact my el-cheapo tach/dwell meter has both circuits in it (and a meter) and could be made to reflect vehicle speed (perhaps with an op amp on the vss) or injector duty cycle (which probably isn't much more than an inductor). Throw in some pots for calibration and an op amp to combine the signals and...

So has anyone come up with a simple mpg gauge circuit for the masses? I suppose digital would be better (i.e. keep track of every duty cycle for every vss pulse and add a "trip" type function to it), but I kind of like the "gomi"-ness of dissecting my old tach/dwell meter and making an mpg gauge out of it ;)

Thoughts?

P.S. Scangauge is in my wifes hands and I don't have another $160, that's why I'm considering this :o , though something for the DIY sector would be useful.

MnFocus
07-08-2007, 12:06 PM
Came across a link (http://www.circuitcellar.com/avr2004/wabstracts/A3805abstract.pdf) on pg 4 & 5 has the circuit diagrams(originally posted by retrorocket) . It appears to use a sunpro tach . Add a vaccum gauge along with some fabbing skill you *might* save a few dollars .

skewbe
07-08-2007, 12:32 PM
Yah, that would be an obd approach, I was thinking analog stuff (and about $5 in parts added to my extremely simplistic sunpro dwell/tach). Mebbe those days are gone?

MnFocus
07-08-2007, 12:43 PM
Didn't SVOboy(I think it was anyway) do a fuel gauge with a dwell tach ? I'd be willing to bet that the same thing *can* be done the way you described . You just need to take the time to get the calibrations down .

landspeed
07-08-2007, 02:22 PM
The cheapest way to do it would be to...

(1) Get an Atmel processor, and programming kit from ebay. Get the flash-reprogrammable processor, so you can experiment.
(2) Find some code + circuit diagram for wiring it to a calculator screen (8-digit LCD)
(3) Connect it to the Auto power supply (using the info in that PDF). Use code to simply read the injector pulse duration, and the vehicle speed sensor reading.
(4) Have one or two buttons on it. You could make a simple user interface, so you can 'reset' the 'TANK' when you refill, and reset the 'journey' each time you make a journey. Display instant MPG on the left of the calc display, and tank/journey MPG on the right hand side!

This is the basic idea behind the SuperMID, except that a lot more work has gone into it, in particular in interfacing it to a much more complicated display.

thisisntjared
07-08-2007, 08:43 PM
The cheapest way to do it would be to...

(1) Get an Atmel processor, and programming kit from ebay. Get the flash-reprogrammable processor, so you can experiment.
(2) Find some code + circuit diagram for wiring it to a calculator screen (8-digit LCD)
(3) Connect it to the Auto power supply (using the info in that PDF). Use code to simply read the injector pulse duration, and the vehicle speed sensor reading.
(4) Have one or two buttons on it. You could make a simple user interface, so you can 'reset' the 'TANK' when you refill, and reset the 'journey' each time you make a journey. Display instant MPG on the left of the calc display, and tank/journey MPG on the right hand side!

This is the basic idea behind the SuperMID, except that a lot more work has gone into it, in particular in interfacing it to a much more complicated display.
so how much do you think that will run??? if its less than $50 i might just have to try it...

sonyhome
07-09-2007, 12:17 AM
Looking at the Mnfocus linky, I'd say the design could be simplified for a laptop:

There's 1 signal line from the ODB-2 picked up. Just pass it on to a laptop's serial port and have a program scan that serial port and do the computation, logging, and display.

That way it's ALL SOFTWARE, with $2 worth of parts. May need a pull down 12V->5V resistor bridge, or at worst an op-amp to decouple it all.

Just need a guy who knows how to code with visual basic or visual C a serial port reader...

If you wanna do it digital, replace their analog display with a cheap LCD bar display.

skewbe
07-09-2007, 01:24 AM
Yah, the laptop->obd route is a well traveled path. Problem is obdii is a hodgepodge of protocols, and laptops aren't exactly cheap.

Also, I'm not ready to sort out PICs and deal with programmer compatabilities,specs,etc.


However, there may still be a dirt cheap option for iso, an old blackberry 957 perhaps (or mebbe a serial based palm) and something to convert 5v<->12v. In that way it is relatively easy to program/reprogram and comes with a display,input system, and a serial port based on the windows iso stuff:
http://www.andywhittaker.com/ECU/OBDIISoftware/tabid/69/Default.aspx
BUT, it ony works with iso vehicles.



Here is another laptop idea, tap into the vss and injector pulses via the line-in right and left channels on the sound card and sort it out from there. They are basicaly A/D converters.

sonyhome
07-09-2007, 03:13 AM
Most people have laptops nowadays, and all have serial ports.

If there's an explanation of what to monitor on the ODB-2, then a simple program can be made, which then will be ported etc.

I'll ask a friend when I have a chance if he knows free PC software to monitor ODB2... Maybe we can find a free one that does the trick or can be modded for FE analysis.

Google Examples:

http://www.er-forum.de/obd-diag-dl
But it needs:
http://www.obdpros.com

http://jdash.ludicrous-speed.com/wiki/index.php/Main_Page
http://www.tactrix.com/

http://www.scantool.net/?mode=displaySoftware&category=Third%20Party

A good explanation:

http://www.thinkythings.org/obdii/

landspeed
07-09-2007, 06:21 AM
so how much do you think that will run??? if its less than $50 i might just have to try it...

No idea, but, I know I could get the raw materials for $50 if I look around on ebay + other places. LCD screens seem quite expensive, but, if you find somewhere that sells simple calculator ones, it should be pretty cheap.

landspeed
07-09-2007, 06:25 AM
Yah, the laptop->

Here is another laptop idea, tap into the vss and injector pulses via the line-in right and left channels on the sound card and sort it out from there. They are basicaly A/D converters.

I've thought of this and looked it up - you would need to make circuits to protect the laptop soundcard, especially as injector pulses can hit +50/+100v due to inductive effects when the power supply is cut off (at the end of the injector pulse).

I found somewhere, a USB device that had about 16 A-D convertors and D-A convertors too. It was about $150 though. Shortly after this I found the SuperMID on this site (in fact, it was research into homebrew MPG gauges that led me to this site!)

skewbe
07-09-2007, 08:07 AM
I've thought of this and looked it up - you would need to make circuits to protect the laptop soundcard, especially as injector pulses can hit +50/+100v due to inductive effects when the power supply is cut off (at the end of the injector pulse).


Yah, worth mentioning, don't want people frying their line in ports.

I would think taking the signal from a pair of diodes in parallel, which are in series with a largish value resistor which leads to , oh nevermind, let me draw a picture :) Were talking pennies worth of parts to limit (clamp) the voltage to .7 volts.

http://www.gassavers.org/attachment.php?attachmentid=664&stc=1&d=1183986302

I've got some old assembler routines I wrote for high resolution recording in dos (windows recording always make skips), I can dredge those up, mebbe a linux port would be in order.

I think we have enough info for a laptop based mpg/mph/trip/and rpm program, once you tell it some info about your car like:
1. how many vss pulses per wheel rotation
2. how many injectors
3. how many cylinders (if it is tbi)

but dang if a laptop isn't a lot of luggage for an mpg gauge :(

skewbe
07-09-2007, 08:29 AM
Most people have laptops nowadays, and all have serial ports.

If there's an explanation of what to monitor on the ODB-2, then a simple program can be made, which then will be ported etc.


Yah, it isn't that simple. there are many OBDII protocols, only iso (asian cars)can be handled by the laptops serial uart chip with only the scantiest of circuitry, and less and less laptops have such a serial port available. The other protocols take $100 adapters (and you might as well get a scangauge/supermid at that point).

I'm looking for cheap and simple, that can be adapted to any electronic fi car (regardless of obd status) using surplus parts/etc.

jwxr7
07-09-2007, 10:35 AM
I'm looking for cheap and simple, that can be adapted to any electronic fi car (regardless of obd status) using surplus parts/etc.

I was just talking with the guys at work about doing something similar to that. Goal was As long as the vehicle has a vss and efi the gauge will work. Just have to do some calibrations for fuel use. I just want a DIY route for my 94 metro since it is all DIY so far :) + I'm cheap. The scangauge I bought should offer enough to be worthwhile on my newer gas hogs :o .

skewbe
07-09-2007, 11:10 AM
a vss is easy to fabricate if the car doesn't have one, basically zip-tie a small magnet to a drive shaft or axle and bracket up a coil to pick it up.

Some cars will have one for a cruise control even if it isn't an obd car.

VXrunner
07-10-2007, 03:13 PM
I'd love to see what you come up with, as i would like to make one for my 94 VX...

sonyhome
07-10-2007, 03:37 PM
Let's recap, assuming you don't want to tap the ODB2 codes (would work for all cars!):

For MPG you need actual distance and gas consumption (duh!)

- distance: count wheel axle rotations

Count rotations R with a magnet or an optical reader
Calibration: multiply count by the circumference Ctire of the tire in inches. That's easy to get with a chalk mark on the tire.

D = R * Ctire /63360

- gas consumption: collect duty cycle of injectors

Can we track it by monitoring the duration of the electromagnetic pulse on the injector electric wires somehow? Maybe with a pickup from the speaker of
an old walkman headset taped to an injector wire? Else tap the wire directly to measure voltage shifts.

Calibration: Need the max volume of gas Vmax the injector can feed divided by the max duty cycle DCmax. Those parameters are probably known by the racers.

V = Vmax * DC/DCmax

Bill in Houston
07-10-2007, 04:03 PM
In a way, you're making it too tough. You really just work off a couple of assumptions. 1- injector pulse width is proportional to fuel flow 2- number of pulses from the vehicle speed thingy is proportional to speed. And then, you just lay a constant on top of it.

Instant MPG = A constant * speed / flow

Less elegant than your idea, though. :-)

skewbe
07-10-2007, 04:36 PM
...assuming you don't want to tap the ODB2 codes (would work for all cars!):

that is incorrect, not all cars by a long shot. It won't work on pre-96, didn't even work on my 97 until I swapped ECU's (car worked fine though), it didn't work on my neighbors car. It's ugly too as it is several protocals under one name, some needing more circuitry than others. Check it out.

Having a layer of ECU and whatnot between the mpg gauge and the actual sensors also means a lot more can (and will) go wrong, in my experience.

Note, however, my metro uses ISO (I'm using an OBDII specific term here, so be careful), and you can use a standard serial port (found on older laptops and even old blackberries/palm pilots) with ISO for a few transistors, i.e.: http://prj.perquin.com/obdii/ So there may be an old palm pilot gorilla glued to my dashboard in the not too distant future anyway :)

skewbe
07-10-2007, 10:38 PM
so rethinking the analog stuff and reusing a tach dwell as a mpg gauge, I found this reference about using op amps to divide.
http://www.national.com/an/AN/AN-30.pdf


So we would use the rpm circuit to create a voltage proportional to the speed (like the rpm circuit does already to drive the meter, only it is connected to an amplified vss signal), and take the dwell circuit to create another voltage (like the dwell circuit does to drive the meter, only it is hooked up to an injector instead of a coil) and divide the speed voltage (E1) by the injector duty cycle voltage (E2) using op amps in a logarithmic mode with a fudge multiplier (calibrator) on E3. Easy cheesey, right? :)

http://www.gassavers.org/attachment.php?attachmentid=681&stc=1&d=1184124933

skewbe
07-11-2007, 12:04 AM
and if you are wondering what tach and dwell circuits might look like:

http://www.gassavers.org/attachment.php?attachmentid=682&stc=1&d=1184130175
from: http://www.4qdtec.com/Automob/TachDwell.html

skewbe
07-15-2007, 04:27 PM
I'm realizing that this isn't quite a comprehensive DIY article yet, I'll have to clean it up when I get something working.

Status, instant mpg isn't nearly as good as a short term average, so I'm shying away from the analog/tach dwell approach.

I was going to persue obdII/ISO after assembling a real trivial circuit. BUT the scangauge stopped working on the saturn (AGAIN?!?) so I need a non obd solution for that car as the scangauge is back in the metro.

So currently I'm trying to load up Visual C++ 6.0 on an old win 98 laptop that has a line-in jack and will try and modify some simple windows based oscilloscope source I found to keep track of how long the injectors have been open and how many clicks we've travelled. It may miss a few beats under windows, but it should be close enough (and provide a reasonable platform for keeping other useful apps on, i.e. some maps and whatnot)

thisisntjared
07-15-2007, 06:04 PM
Status, instant mpg isn't nearly as good as a short term average, so I'm shying away from the analog/tach dwell approach.i agree, as long as it is accurate.

keep us updated on the progress :):thumbup:

MetroMPG
07-15-2007, 09:02 PM
Forgive my ignorance, but would a Basic Stamp be a good platform for a DIY FE gauge? Anyone know about these?

skewbe
07-15-2007, 09:27 PM
A more hardcore embedded person would do it with a handful of counters and a PIC (i.e. basic stamp) and have a standalone device. But the problem becomes the fact that they have to put more complicated circuts together and purchase a special programmer to load the BASIC (or C++ or assembler or whatever) program onto the chip and learn how to operate the programmer, or someone has to sell chips to the "Do It yourselfers".

I see a lot of utility in having a full fledged computer handy though, play mp3 files, talk to your lan from your driveway, run maps/whatever. All my portable computers can run on 12 volts directly (no accident). I've even got a ramline 510 touchscreen (used to be in a cop car) that needs to find a second life which would be ideal for this. But the ramline is a PITA to develop on (as are embedded chips), which may be my real motivation for this approach :)

skewbe
07-15-2007, 09:50 PM
Ooh yah, and a with a well positioned display you can plug in a $20 web cam that is pointing backwards and shave off those mirrors :)

sonyhome
07-16-2007, 12:51 AM
LOL!

So back to an OBD solution then, instead of tapping the injector's duty cycle directly?

Too bad for my '93 OBD-1...

This ALDLcable (http://www.aldlcable.com/sc/pages.asp?pageid=24) store sells cables using these schematics except it's voltage adaptation uses a cig. lighter, instead of hacking the DTR line (pin 4 of the serial port):

http://winaldl.joby.se/interface.gif

They sell a $10 OBD2-Serial cable:
OBD2-serial cable (http://www.obd2allinone.com/sc/details.asp?item=obd2cable)

They also list a bunch of freeware (http://www.aldlcable.com/sc/pages.asp?pageid=20) used to monitor OBD data.


Useful links for diagnostic and tuning software:

TTS Datamaster - http://www.ttspowersystems.com/DataMaster_downloads.html
WinALDL - http://winaldl.joby.se/
EFILive - http://store.efilive.com/download.aspx#downloads3
TunerPro - http://www.tunerpro.net/
TunerCat - http://www.tunercat.com/
FreeScan - http://andywhittaker.com/ECU/FreeScan/tabid/70/Default.aspx
CarBytes - http://store.efilive.com/download.aspx#utilties
Moates Free GMECM - http://www.moates.net/gmecm/software.html
ALDL_LOG - http://www.lotus-carlton.fsnet.co.uk/aldl_basics.htm
Pontiac-interface.de - http://www.pontiac-interface.de/
ALDMON for 1227727 and 1227730 - pweb.de.uu.net/pr-meyer.h/aldl.htm
EASE Diagnostics - http://www.easesim.com/
Diacom Plus - http://www.rinda.com/auto/auto.htm
PCMComm 16188051 - www.geocities.com/MotorCity/Shop/1624/95cam2.html
ElanScan - http://members.lycos.co.uk/mcnica01/M100_ALDL.html
LT1-Edit - http://www.carputing.com/
GM 6.5 Turbo Diesel Scan- http://www.enghmotors.com/basic/default.aspx

Driver software for our USB cables:

VCP Drivers - http://www.ftdichip.com/Drivers/VCP.htm

OBDII software for our ELM327 based OBD2 allinone scan tool:

OBD2allinone - http://www.obd2allinone.com/sc/pages.asp?pageid=60


Othe OBD-1 links:

http://cable.invisibill.net (schematics, used on datamaster, freescan, winaldl)

skewbe
07-16-2007, 05:08 AM
LOL!

So back to an OBD solution then, instead of tapping the injector's duty cycle directly?

Too bad for my '93 OBD-1...


I'm NOT currently planning on doing OBD, it won't help me as my saturn is not happy with OBD MPG attempts, for whatever reason, and I'd like to get something out of my efforts.

I'm planning on the audio approach on a laptop for ease of implementation and more universal application. Any any car with electronic FI should work. One just need a laptop with a Line-In to run the mpg program on and a simple circuit to limit the voltage going in.

skewbe
07-21-2007, 02:28 AM
44100/8 bit/mono recording using a diode clamp interface (http://www.gassavers.org/attachment.php?attachmentid=664&stc=1&d=1183986302) and a 10k resistor on a 133mhz laptop with integral sound card via line in left channel . Car in neutral in driveway. Probe connected to yellow wire between fuel injector resistor and fuel injector.

3 samples, 1 low rpm, 1 accalerating to higher rpm, 1 high rpm. Images stretched horizontally for easier duty cycle visualization/comparison.

http://www.gassavers.org/attachment.php?attachmentid=741&stc=1&d=1185002121
steadyish @ ~1200
period 1714 bytes
pulse width 119 bytes
duty cycle 0.0694


http://www.gassavers.org/attachment.php?attachmentid=742&stc=1&d=1185002139
just starting to ramp up on the way to 2000rpm in neutral
period 1273 bytes
pulse width 137 bytes
duty cycle 0.1076


http://www.gassavers.org/attachment.php?attachmentid=743&stc=1&d=1185002153
steadyish @ ~2000rpm
period 833 bytes
pulse width 73 bytes
duty cycle 0.0876
(duty cycle increased for higher rpm and throttle setting.

sanity checks:
(3 pulses/2 revolutions)*2000 rpm=3000 injector pulses/minute = 50 pulses/second
44100/833 = 52.94 pulses/second. Enh, close enough for a single wave analysis.

accelerating had the largest duty cycle (most time spent squirting fuel)

hi rpm has a proportionally larger duty cycle than low rpm.

833 byte sized samples @ 2000 rpm equates to a potential 99.75% accuracy at 4000rpm

Note: this signal doesn't look very clamped to me, maybe 10k is too much or my diodes fried. Agc is having fun with the signal too.

skewbe
07-21-2007, 07:59 AM
for the above images. It was a raw wav, so I could pipe it through a program for development, but it is here converted to mpeg 3 compression for space considerations. Recorded with windows sound recorder and subsequently compressed with sound recorder.

if you run it in windows media player, set the visualizations to "scope" by:
views->visualizations->bars and waves->scope

OOPS, this is the recording of the wrong channel!! The other side records a bit cleaner. :o I sure hope there isn't this much crosstalk when the other channel is plugged into the VSS.

sonyhome
07-21-2007, 03:12 PM
Pretty cool ... but I don't quite understand your diode clamp interface you used.

Could you explain how you make it work?

You connected directly to the injector via a 10K resistor?
And then you grounded the signal via a diode bridge? Is that to avoid having signals above 0.6V? Don't understand...

And what's VSS for?

I though you'd use a coil to detect the pulses so the laptop would be totally independant from the car's electrical circuit...

All you have to do now to compute duty cycle is count the number of samples above a threshold vs all the samples.
You may need to adjust with a constant, or adjusting the threshold since the ramp up slope is not vertical, but seems constant.

skewbe
07-22-2007, 03:40 AM
Tada!!, it's somewhere in the ballpark for a 98'tro!! Now anyone who has a laptop or tablet in their car can monitor MPG

***you need to be logged in to see the pictures,
You can go here to see the pictures without logging in:
http://opengauge.org/diympggauge/
***
http://www.gassavers.org/attachment.php?attachmentid=749&stc=1&d=1185090285
*tank will persist when window is closed


Using this circuit, with right and left switched :rolleyes:
http://www.gassavers.org/attachment.php?attachmentid=664&stc=1&d=1183986302


Zoom in on recording of line in (44100 8 bit stereo) for anylizing the waveform (vss* on top, injector on bottom) and general futzing in response. I don't think the diodes are doing much on the vss side :eek:
http://www.gassavers.org/attachment.php?attachmentid=750&stc=1&d=1185091266
*Yellow line is default threshold for the vss,
*Cyan "..." injector
*I adapted the code to the latest wave form (inj pulse was on other channel and right side up?!?)
*vss is the misnamed Vehicle Speed Sensor. It really only measures distance. The computer watching the vss still has to keep track of time to figure out the velocity.



Speaking of code, here it is in it's entirety, 6 drama filled pages to chew on in one file called Mpg.java :

import java.awt.Color;
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.text.NumberFormat;
import java.util.Properties;

import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.TargetDataLine;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class Mpg extends Thread {
static String propFile = "./mpg.properties"; // place to persist confguration and trips.
//Will be created on first run if it doesnt exist.

static int injThreshold = Integer
.parseInt(getProperty("injThreshold", "-30")); // value above the noise

static int vssThreshold = Integer
.parseInt(getProperty("vssThreshold", "100")); // value above the noise

static double distanceFudge = Double.parseDouble(getProperty("distanceFudge", "3200.0"));

static double fuelFudge = Double.parseDouble(getProperty("fuelFudge", "8000000.00"));

static String dummyFile = getProperty("dummyFile", "");

// low level stats tracked in the "trip" class.
class Trip {
String name;

long sampleCount; // num samples, used to compute elapsed time, good
// for about 58 billion hours @ 44100hz

long injHi; // stores number of samples that were "HI" (injector was
// open)

long vssTot; // how many pulses from the vss, indication of distance
// travelled

public Trip(String _name) {
name = _name;
}

// real lightweight update process, gets called at end of audio chunk
public void Update(long _sampleCount, long _injHi, long _vssTot) {
sampleCount += _sampleCount;
injHi += _injHi;
vssTot += _vssTot;
}

public String toString() {
return "name=" + name + ";sampleCount=" + sampleCount + ";injHi="
+ injHi + ";vssTot=" + vssTot;
}

public void reset() {
sampleCount = 0;
injHi = 0;
vssTot = 0;
}

public Trip load() {
sampleCount = Long
.parseLong(getProperty(name + ".sampleCount", "0"));
injHi = Long.parseLong(getProperty(name + ".injHi", "0"));
vssTot = Long.parseLong(getProperty(name + ".vssTot", "0"));
return this;
}

public void save() {
properties.put(name + ".sampleCount", "" + sampleCount);
properties.put(name + ".injHi", "" + injHi);
properties.put(name + ".vssTot", "" + vssTot);
}

public double miles() {
return (double) vssTot / distanceFudge;
}

public double hours() {
return ((double) sampleCount) / (44100.0D * 3600.0D);
}

public double gallons() {
return (double) injHi / fuelFudge;
}

public double mpg() {
return gallons() > 0.0D ? (miles() / gallons())
: Double.POSITIVE_INFINITY;
}
}

class TripPanel extends JPanel {
Trip trip = null;

JLabel name = new JLabel("name");

JLabel miles = new JLabel("miles");

JLabel gallons = new JLabel("gallons");

JLabel mpg = new JLabel("mpg");

JLabel hours = new JLabel("gallons");

JLabel mph = new JLabel("mph");

JButton reset = new JButton("reset");

/** used for limiting numbers to 4 decimal places*/
NumberFormat fm = NumberFormat.getNumberInstance();

public TripPanel(Trip _trip) {
trip = _trip;
setLayout(new GridLayout(1, 8));
setBorder(BorderFactory.createLineBorder(Color.BLA CK));
add(name);
add(miles);
add(gallons);
add(mpg);
add(hours);
add(mph);
add(reset);
reset.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
trip.reset();
}
});
fm.setMaximumFractionDigits(4);
}

public void upDateLabels() {
name.setText(" " + trip.name);
miles.setText(fm.format(trip.miles()));
gallons.setText(fm.format(trip.gallons()));
mpg.setText(fm.format(trip.mpg()));
hours.setText(fm.format(trip.hours()));
mph.setText(fm.format(trip.miles() / trip.hours()));
}

}

private TargetDataLine m_line;

protected boolean m_bRecording = true;

Trip instant = new Trip("instant");

TripPanel instantPanel = new TripPanel(instant);

Trip current = new Trip("current");

TripPanel currentPanel = new TripPanel(current);

Trip tank = new Trip("tank").load();

TripPanel tankPanel = new TripPanel(tank);

public Mpg(TargetDataLine line, AudioFileFormat.Type targetType) {
m_line = line;

new Thread(new Runnable() {// thread to update the view every second
public void run() {
while (m_bRecording) {
instantPanel.upDateLabels();
instant.reset();// reset the instant trip after
// displaying it
currentPanel.upDateLabels();
tankPanel.upDateLabels();
try {
Thread.sleep(1000);
} catch (Exception e) {
}
}
}
}).start();

}

public void start() {
m_line.start();
super.start();
}

public void stopRecording() {
m_line.stop();
m_line.close();
m_bRecording = false;
System.out.println(" inj sampleCount = " + current.sampleCount
+ " inj hi = " + current.injHi + " inj vssTot = "
+ current.vssTot);
}

boolean ig = true;

boolean vg = true;

void processChunk(byte[] b, int c) {
long ih = 0;
long vt = 0;

for (int x = 0; x < c; x += 2) {
int val = ((int) b[x] & 255) - 127;
if (val > vssThreshold && vg) {
vt++;
System.out.println(" vss going hi "
+ (current.sampleCount + (x / 2)));
vg = false;
}
if (val < 0) {
vg = true;
}

val = ((int) b[x + 1] & 255) - 127;
if (val < injThreshold) {
ig = true;
}
if (val > 0)
ig = false;
if (ig)
ih++;
}
instant.Update(c / 2, ih, vt);
current.Update(c / 2, ih, vt);
tank.Update(c / 2, ih, vt);
}

public void realrun() {
byte[] buffer = new byte[m_line.getBufferSize()];
while (m_bRecording) {
int c = m_line.read(buffer, 0, m_line.available());
if (c != 0) {
processChunk(buffer, c);
}
}
}

public void run() {
if ("".equals(dummyFile))
realrun();
else
dummyrun();
}

public void dummyrun() {
try {
String strFilename = dummyFile;
File soundFile = new File(strFilename);
AudioInputStream audioInputStream = null;
audioInputStream = AudioSystem.getAudioInputStream(soundFile);

int nBytesRead = 0;
byte[] abData = new byte[44100];
while (nBytesRead != -1) {
nBytesRead = audioInputStream.read(abData, 0, abData.length);
if (nBytesRead >= 0) {
processChunk(abData, nBytesRead);
}
try {
Thread.sleep(1000);
} catch (Exception e) {
}
}
} catch (Exception e) {
e.printStackTrace();
}
}

public static void main(String[] args) throws Exception {

AudioFormat audioFormat = new AudioFormat(
AudioFormat.Encoding.PCM_SIGNED, 44100.0F, 8, 2, 2, 44100.0F,
false);
DataLine.Info info = new DataLine.Info(TargetDataLine.class,
audioFormat);
TargetDataLine targetDataLine = null;
targetDataLine = (TargetDataLine) AudioSystem.getLine(info);
targetDataLine.open(audioFormat);
AudioFileFormat.Type targetType = AudioFileFormat.Type.WAVE;

final Mpg recorder = new Mpg(targetDataLine, targetType);
JFrame j = new JFrame("MPG Monitor!!!");
j.setSize(640, 125);
Container c = j.getContentPane();
c.setLayout(new GridLayout(4, 1));

JPanel hd = new JPanel();
hd.setLayout(new GridLayout(1, 8));
hd.add(new JLabel(""));
hd.add(new JLabel("MILES"));
hd.add(new JLabel("GAL"));
hd.add(new JLabel("MPG"));
hd.add(new JLabel("HRS"));
hd.add(new JLabel("MPH"));
hd.add(new JLabel(""));

c.add(hd);
c.add(recorder.instantPanel);
c.add(recorder.currentPanel);
c.add(recorder.tankPanel);

j.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
recorder.stopRecording();
recorder.tank.save();//this just adds the trip fields to the properties object
try {
properties.store(new FileOutputStream(new File(propFile)),"");
} catch (Exception f) {
}
System.exit(0);
}
});

j.setVisible(true);
recorder.start();

}

static Properties properties;

static String getProperty(String tag, String dflt) {
String s = "";

try {
if (properties == null) {
properties = new Properties();
try {
properties.load(new FileInputStream(new File(propFile)));
} catch (Exception e) {
}
;
}
s = properties.getProperty(tag);
if (s == null) {
s = dflt;
properties.put(tag, s);// will propogate default values to the
// file
}
} catch (Exception e) {
}
return s;

}

}


So, believe it or not, it's all there. I think its a solid proof of concept anyway. Every car will be different, and there's plenty else that can be done to it: RPM column, invert signal/swap channel from mpg.properties file. A a collection of presets for different cars... But I, personally, am gonna try and do other stuff for a while :)

skewbe
07-22-2007, 10:26 AM
Pretty cool ... but I don't quite understand your diode clamp interface you used.

Could you explain how you make it work?
You connected directly to the injector via a 10K resistor?
And then you grounded the signal via a diode bridge? Is that to avoid having signals above 0.6V? Don't understand...


the diodes are supposed to limit the max voltage going into the sound card, yes. The resistor is supposed to prevent the diodes from trying to clamp the vss and injector to .6 volts. The VSS side could use some work in my case.




And what's VSS for?

I though you'd use a coil to detect the pulses so the laptop would be totally independant from the car's electrical circuit...

To do Miles per Gallon, you need to know how many miles you have gone. A direct signal is much easier to parse than an induced signal in a coil. The resistor provides enough independance.



All you have to do now to compute duty cycle is count the number of samples above a threshold vs all the samples.
You may need to adjust with a constant, or adjusting the threshold since the ramp up slope is not vertical, but seems constant.

Yah, I just have a fudge number, there probably is a constant component to the injector pulse that could be factored in for greater accuracy.

*Note, if one were to add a "injectorPulseCount" field to the Trip class, and detect it like the vss pulses, then RPM and a constant value adjustment per pulse could be accomplished.

*also note that it is trivial to add more trips, like "trip 1", "trip 2", etc, and have them save to disk when the window is closed.

Here is the sample a mpg.properties file it creates in the current directory, you can tweak the thresholds and fudge factors (and even pipe in a .wav file of a recording of your probes):
#
#Sun Jul 22 11:13:47 CDT 2007
dummyFile=
tank.injHi=3984869
tank.vssTot=1076
fuelFudge=8000000.00
injThreshold=-30
vssThreshold=100
tank.sampleCount=3984876
distanceFudge=3200.0

thisisntjared
07-22-2007, 04:55 PM
thanks for the open source project :)

MetroMPG
07-22-2007, 08:37 PM
I am duly, duly impressed! (And in over my head.) Congratulations are in order!

skewbe
07-23-2007, 08:29 PM
Thanks yall, I wanted to get this idea down somewhere after looking up DWL again.


Ok, so now the computer knows the mpg, big whup. BUT, that old parallel port... It is great for driving, say, a stepper motor, which could, say, be chained up to, say, the throttle to...

Yah, you got it...


Maintain a pre-determined MPG, exactly :)

MetroMPG
07-23-2007, 08:40 PM
Inspired. Creativity is cool.

skewbe
07-23-2007, 10:59 PM
Heh, a couple more goodies that could be added by providing things like car weight:

1. monitor acceleration (based on change to vss pulses) and other dynomometer/ET type stuff.

2. provide indication of acceleration/fuel consumption (find the peak when accelerating?) Might be good to have an audio signal for this so you can watch the road while accelerating. Make small adjustments in the gas pedal till the pitch frequency tops out.

3. Compute CDA, accelerate to 60 on a flat road and coast to a stop, let it figure out the rest.

MetroMPG
07-24-2007, 08:04 AM
Ooo! I like the audio signal idea. Sort of like version 1.0 of the DWL cruise control.

An audio tone to help you stay near your target FE, rather than spending a lot of time glancing at a screen.

psyshack
07-24-2007, 08:18 AM
Boy there are some smart folks in this old world. WOW

skewbe
07-24-2007, 01:05 PM
Actually, I was thinking of a tone that peaks when you are accelerating most efficiently. If you give the computer throttle control it might be able to find the most efficient accelerator setting for you (for a given gear).

cfg83
07-24-2007, 02:06 PM
skewbe -

Actually, I was thinking of a tone that peaks when you are accelerating most efficiently. If you give the computer throttle control it might be able to find the most efficient accelerator setting for you (for a given gear).

Ha ha! I was thinking that this would be a perfect 2600 article, and here you are talking in terms of "tones" for your solution.

Most excellent work!!!!! I think you should publish this in http://www.makezine.com

CarloSW2

skewbe
07-24-2007, 10:01 PM
I got a request to provide a binary, so, just this once. If your signal looks like mine (vss cranked on the left channel, injector upside down and about the same height), it might work out of the box.

you will have to save this Mpg.zip file somewhere then run (trust me?!?)
java -jar Mpg.zip

from a command prompt in that directory, or put a shortcut together, whatever. Google is your friend. If you see error messages, start there, or give yoshi his $170 bucks :)

philmcneal
07-25-2007, 01:06 AM
the power of open source, now you just need a odb/odbII to usb2 for newbies and downloadable exe and your set!

skewbe
07-25-2007, 07:05 AM
Not obd, not for newbies, not exe. It's for folks who can figure out how to compile a "hello world" program in a given language, who can put a simple circuit together and hook it up to the vss and an injector, and can make sense out of what they are seeing.

I'm not even going to try to compete in the support department with paid for products, this is Do It Yourself land (that means you too) :)

sonyhome
07-25-2007, 07:22 PM
Hypermiling User Interface idea:

I think one of the useful things for hypermiling not done by SG2 that this software could do is compute MPG by speeds.

Here's the idea:

Create buckets of speeds, say:
0MPH, 1~5MPH, 5~40MPH, 40~65MPH, 65~100MPH.

For each bucket, compute
- GPH
- average time spent in that bucket
- distance travelled in that bucket
- MPG (when applicable)

Also compute overall MPG.

Now say you're driving in the city, with some highway.

At first you drive normally, and check your buckets, see time spent in each and what part of your driving contributes to your overall MPG.

Now start using hypermiling techniques that apply to specific buckets.

For example, if you see you spend most time on stop lights (the bucket 0MPH will tell you how much gas it costs you), then you know you must turn of your engine at lights to improve MPG.

If the profile shows it costs little gas though it may seem like a long time while you drive, you know you don't need to risk damaging your starter and look for another solution.

Say you spend your gas in the 5~40MPH buchet. Then you can try to focus on gliding.

If it's at highway speeds, then you can try to use drafting instead, and maybe gliding.

The time spent per bucket can also tell you something as you try different techniques, like gliding causes you to hit more red lights, so you need to be more aggressive.

sonyhome
07-25-2007, 07:26 PM
OK a few other things:

- Do you have PICs of the setup, where you wire-in onto your car for collecting Vss and injector signals?

- For OBD-1, you can buy a scan cable, and you could use it to connect a serial cable, with an open source software AND collect the same info I suspect.

- For OBD-2, the scan cable has to hook up to a device ($) that processes and converts the info into data that can be passed to a USB/serial cable.

skewbe
07-25-2007, 08:12 PM
re buckets: Sure, you can do that, have a blast :) You will need to program a tiny bit. If you add trips for each bucket and at the bottom of processChunk, look at instant.mph() and call update on the appropriate trip(bucket), that will get you close.

re: pic, don't have one, mine was just a couple sewing pins soldered to the resistors and stuck into the appropriate wires. I do not have a permanent installation yet though am considering it. There is a number of folks that already have computers running linux or windows in their cars, for whatever reason.

re: obd, yah someone posted a whole bunch of obd stuff earlier in this thread. That road has been pretty well travelled, and I'm not going down it myself. This approach is universal to electronic fuel injection vehicles and operating systems, and that is worth something.

sonyhome
07-25-2007, 08:15 PM
Agreed :)

I was just currious where you tapped the info and routed the wires.

It helps to have photos to actually commit to do it yourself. There is a sense of concretization, and understanding that the solution is complete :)

sonyhome
07-25-2007, 08:35 PM
Looking at your "diode clamp" again, I have this to say:

I think:
- VSS trips the diodes (sharp horizontal cutoff)
- Injectors voltage is too low and does not trigger the clamp (no cutoff).

It seems to be a 0.4V swing, comparing to VSS cutoffs.

- R is only to limit current if the diode passes current (aka voltage from 0.6V to 13V). At 10KOhm, that is max 1.3mA draw. I dunno if that is noticed by the car's Vss/injector circuits. Likely not?

mpmetro
07-26-2007, 01:52 PM
could you take a picture of your setup and circuit, so I can then try to replicate

thaks

txe5502
07-26-2007, 09:07 PM
Is there any way to use this if your computer's only audio input is mono?

skewbe
07-26-2007, 09:24 PM
Are you sure it is only mono? You could only monitor fuel consumption & time OR distance & time with one channel, so it would be worth double checking with a miniscule amount of experimenting (recording) that it is indeed mono.

If I had to choose, I would choose fuel consumption, since I know how long my commute is, and I have reasonably accurate distance instrumentation in the vehicle already.

itjstagame
07-28-2007, 10:18 AM
This is really awesome, finally some paved ground for a meter on my non-obd car. Can you think of a way that you'd use a serial or parralell port to capture the signals instead? Because I'd like to get more signals then just those two. Namely RPM because then I can show instantaneous HP and TQ and well and log and throw into StreetDyno.

Also one other nice thing that I'll add to this when I get it all working is an automatic crr and cid recording. I'm thinking choose a 'stop' MPH (like 20MPH entered through a text box) and then have a start button. I cruise to 70MPH, hit start and slip into neutral and let the vehicle slow to whatever the 'stop' MPH is. BAM, I know now exactly how long it takes me to slow down different thresholds, in fact instead of just 5 numbers at different speeds I have a full curve! Not exactly sure how to automate something to solve the crr cid equation based on this curve, but I'll certainly figure it out.

Do you think you could sample from the microphone jack AND line in at the same time? That might be easier than serial/parallel.

itjstagame
07-28-2007, 10:33 AM
Actually thinking a bit more I'm pretty stupid to need rpm signal. I can easily get that from the injector pulses! I guess the only difference is that as their duty cycle changes the peaks may start or stop at different times causing a very miniscul shift, but the Hz*2 should be rpm.

In fact if you just had your program ask for the gearing ratios of the transmission and final drive, as well as tire diameter and size, as StreetDyno does, then you wouldn't need VSS either, since you could calculate speed based on RPM. Of course you'd contantly have to tell it which gear you were in on the fly....

sonyhome
07-28-2007, 01:43 PM
Now that you mention it, you should be able to automatically find the gear ratio then with the 2 signals you get then, and when you're not in gear.

skewbe
07-28-2007, 10:06 PM
sonyhome, maybe a smaller resistor on the injector would give a larger pulse signal (and thus more resolution)? I think the automatic gain control might be kicking in on the VSS and reducing both channels.

itjstagame, Yah RPM is right there, so is accelleration and deceleration, and if you know the cars weight then power can be deduced.

I don't think we care about the ratios. If you have RPM AND VSS they are the ratio when the clutch isn't slipping.

I also don't know how to get windows to let you record from more than one jack. Other ports are possible but I don't have any firm plans for them.


The coastdown tests could be completely automated, sure. The computer will gather a lot more than just 5 points on the curve, it will gather the whole curve from , say, 60mph to 0mph :)


One last note, trying to determine distance from rpm and gear ratios wouldn't work for me, I spend most of my time coasting with the engine off. I really need that vss signal if I want to know how far I've travelled (the 'M' in 'MPG').

itjstagame
07-29-2007, 09:10 AM
One last note, trying to determine distance from rpm and gear ratios wouldn't work for me, I spend most of my time coasting with the engine off. I really need that vss signal if I want to know how far I've travelled (the 'M' in 'MPG').

Ah, very good point. Yeah, VSS is easier, I was only saying that if you only had a mono jack, just that you could get fairly close with one signal.

For calibration there are a set number of VSS pulses per mile, speed is just the rate of pulses, but I'm calibrating toward the constant number of pulses per mile?

Also how'd you decide how much fuel to attribute to each pulse? Do you have some formula based on the cc of each injector? Becaues obviously 50% pulsewidth isn't an exact amount of fuel, only if you know how much fuel the injector delivers at that 50% pulsewidth. And do most injectors ramp up linearly? ie. 80% pulsewidth used exactly 60% more fuel than 50% pulse width?

Lastly, I can solder and I can follow a diagram, but I'm afraid my electronic skills fail at the basics, so if I'm told I want to output a constant .6V I don't know if that means I need a resistor a transistor a whatever, etc. Can you give me an idea of what kind of diodes you use and what rating (varies based on VSS out signal I'm sure). And it looks like you hook the + audio signal to before the diode bridge but still on the negative (grounded) side of the VSS/injector? Or do you tap in to the + side and use the - only after the diode bridge, also aren't you making the whole ground for that injector pass through that bridge, is that an issue? Can I just use any common ground in the car? This seems it might work for the injector, but the VSS is a stand alone pulse (probably VAC)?

itjstagame
07-29-2007, 01:44 PM
Actually I guess the only other signal that would be nice to have is TPS. Then you can compare throttle position to pulse widths and various loads.

I don't think I like MPG as an indicator, I'd like to see acceleration or maybe energy produced per gallon. I often wonder is accelerating slowly at 12MPG is better than accelerating quickly at 8MPG, etc. Finding the most efficient spot for acceleration coupled with EO P&G should help a lot. I would assume this would be maximum torque rpm, but I wonder how much of an effect throttle position has, especially with today's ecus, even at the max tq rpm, if you're cruising or WOT it's very different, typically different target AFRs and advances. Even building my own ECU I'm not sure 'theoretically' which would be better, lean is for efficiency but more power seems more efficient (unless it's less power/Gal).

Maybe the cruising/leaning is simply to try to help the fact engines aren't as efficient maintaining a steady state load versus accelerating against a load? That's why stuff like dropping out cylinders helps?

Sorry I keep posting, I'm just anxious to get playing with my vehicle and can't at the moment.

caprice
08-04-2007, 06:10 AM
I'm lost here, but excited too... what do you have "do" to use this DIY MPG Monitor?

I know a little bit about programming, and my brother knows Java, so that helps.

In fact I have used "WIN ALDL" and an old computer to track the performance when I upgraded to TBI in my car.

skewbe
08-04-2007, 09:29 AM
There's a couple ways to approach it, but referring to:
http://www.gassavers.org/showthread.php?p=64732

Assuming you can solder/record and view wav files/and understand what the program is doing given the wave forms and thresholds, and how to tweak it to make it work with your car after analyzing the signals:
1. you have to locate a good injector signal and a good vss signal. On my metro it was the yellow injector wire going into the resistor and the yellow and green wire going into the ecu.
2. hook them up to your line-in jack
3. run the program once then exit, locate the mpg.properties file it creates.
4. prepare to record line in in PCM at 44100hz 8 bits 2 channels into wav file
5. drive at a known speed (and rpm), make a guess at what mpg you should be getting, and start recording.
6. park it and save recording.
7. analyze the wave forms, if they look like mine you are done.
7a. If the are on the wrong channel, then you can fix it in the wiring or swap the processing of even and odd bytes in the processChunk method.
7b. If they are the wrong direction, then you will have to change the sign on the threshold in the mpg.properties file and the associated comparisons in processChunk for that channel.
7c. If the signals don't cross the default threshold, or noise is crossing the threshold then adjust the threshold (-128 to 127) in the mpg.properties file and/or fix your signal.

Ok, so if you made it through all that, lets "calibrate" it on the bench using your recording:
1. change defaultFile in mpg.properties to point to your recording.
2. run the program, note the speed and mpg
3. exit the program, adjust fuelfudge and vssfudge in mpg.properties a proportional amount (they are used in the divisor), and save.
4. rerun, note speed and mpg, and go to 3 if more adjusting is necessary, otherwise declare victory :)
5. set defaultFile back to blank and hook the computer back up to your car, enjoy.

Note, I'm considering a more user friendly version of the software, but not a priority for me at the moment. I was going to put this in my metro but the scangauge quit working in the saturn (so it is in the metro) and the saturns driver hasn't warmed up to the idea of having a computer in the car yet. ;)

If a few of you are serious about this and understand what is going on with this cheezy bit of signal processing, PM me and I'll do what I can to help you sort it out.

mpmetro
08-04-2007, 09:48 AM
Here are some pics of my circuit I made. I am not sure if it Is right, but I tried. My wires arent too thin are they? (speaker wires) And I put it in a nice box. I still have to connect it to my laptop and calibrate. (going to connect it to an older computer first, just to make sure, I dont fry my good laptop)

one more question... since my car is a 91 metro 3cyl, similar to your metro skewbe (is it 3cyl ?), I was wondering if I will still have to do all the calibrations etc...

http://i12.tinypic.com/6c7c7pk.jpg

http://img399.imageshack.us/img399/7792/p1010003pz7.th.jpg (http://img399.imageshack.us/my.php?image=p1010003pz7.jpg)

http://img399.imageshack.us/img399/1120/p1010005oi3.th.jpg (http://img399.imageshack.us/my.php?image=p1010005oi3.jpg)

http://img61.imageshack.us/img61/4977/injectormf5.th.jpg (http://img61.imageshack.us/my.php?image=injectormf5.jpg)

skewbe
08-04-2007, 10:16 AM
looks right, you might want to use shielded wire to the probes and ground them near where they tap into the signal for less noise.

You might get lucky and not have to calibrate. I'm a little confused on right vs left so you may need to swap those to get it to work right.

sonyhome
08-05-2007, 12:51 AM
skewbe:

I'd love to code the program to make what I think would be a great hypermiling diagnostic tool, I have quite a few ideas on how to present the data usefully. However I need lo learn Java first :). I did look at the graphic libraries, and it's too bad, it seems one has to code the graphic interfaces (for like 2D graphs, gauges etc.) so there's some overhead work to make a cool tool.

I think the config file you have is pretty well thought, it does allow adjusting the tool.

itjstagame :

With this gizmo you could have what you want. It's just a matter of programming.

Caprice:

I think it boils down to this:
- Find Vss and one injector wire
- Solder wires to needles and stick them in to tap those signals.
- At the other end, follow the diagram, aka solder to a 1/4" (?) headphone plug (each wire to center connectors and the diode bridges between those wires and the outside ground connector), and the ground to the car's chassis. Note that there's a resistor there, and it's to make sure you don't just ground the signals with the diodes. When the diodes pass current, it's via the resistor, which makes the current draw very small.
- Boot your PC or whatever, and run skewbe's Java app. For that I personally made a batch file that just calls the java program, else Windows doesn't launch it (maybe one needs to register the .java extension as a runnable program?).

The program works w/o the car: just with noise on the microphone it'll do some random stuff.

mpmetro:

That's some ugly soldering LOL :)
make sure that glue holds tight.

cfg83
08-05-2007, 12:57 AM
mpmetro -

...

http://img399.imageshack.us/img399/1120/p1010005oi3.th.jpg (http://img399.imageshack.us/my.php?image=p1010005oi3.jpg)

...



Plastic box containter. Righteous!

CarloSW2

mpmetro
08-05-2007, 04:27 PM
skewbe:
That's some ugly soldering LOL :)
make sure that glue holds tight.

i know...:o i cant solder.

itjstagame
08-06-2007, 09:04 AM
itjstagame :

With this gizmo you could have what you want. It's just a matter of programming.


I've already done some of the programming. Java was new to me too but not that hard to pickup. I added a way to 'guess' VSS pulses based on tire size and final gear and a way to calibrate vss pulses over a given number of miles.

I'm also trying to add the cid and crr calculations but stopped at trying to figure out how to use the actual temp, pressure and humidity to get air pressure index. Also I didn't want to release anything until I could get it installed and calibrated (and debugged!) in my truck, but I'm kind of scared to throw a resistor in line with the negative on my injector and can't find my VSS (tons of wires to my trans and transfer case and not sure what I need). For now I'm just using small tankfuls and trying to drive (I have no time to work on most these things anyway).

A graph might be nice but I think I'd rather see a more 'gauge' like interface (with a needle). The only other diagnostic I'd like to add is instantaneous HP/power and keep track of that over trips too.

For instance the same trip done at 45MPH and at 75MPH, the 75MPH will neccisarily have to have generated more energy/hp and most likely used more fuel.

I was also wondering about trying to find a pinout diagram of my ecu and pull signals there. Not the processed signals from an ODB connector, but the actual inputs to the ECU and bridging them.

itjstagame
08-06-2007, 09:09 AM
Here are some pics of my circuit I made. I am not sure if it Is right, but I tried. My wires arent too thin are they? (speaker wires) And I put it in a nice box. I still have to connect it to my laptop and calibrate. (going to connect it to an older computer first, just to make sure, I dont fry my good laptop)


Ok, that's what I understood from diagram posted earlier, but I still can't tell if you're tapping inline to the 'ground' from the injector or if you're bridging off or if you're tapping into the positive side.

I'm also still confused on what the diodes do (which is fine I don't really need to know :p) and I'm confused why VSS signal would be hooked to a common ground, I picture it acting like the pulsing coil on my motorcycle, it's generates a small VAC current due to the magnet going toward and away from the circuit.

Also I was going to swap the 10k res for a 25k pot for calibration (I just need to be unlazy).

skewbe
08-07-2007, 12:35 AM
sonyhome: Yes on all accounts

itjstagame:
I believe my injector has a switched ground, so I'm on the other side of that, counting on the voltage drop across the resistor to give me a signal.

My VCC is a switch, which mysteriously does go positive and negative??? Don't care. The wagon is a magnet, or a hall effect thing, I expect that might take some figuring at slow speed and/or an op amp.


anyone: You can mess around with my wav recording for defaultFile. It's a bit more relevant than mic noise. It's too big to post so PM me your email and I'll forward it,2.5 meg. Tell me if you think the rpm "whine" on it is the alternator if you listen to it.

itjstagame
08-07-2007, 03:00 PM
Ok, so you're on the same leg with the resistor in the middle, sounds good to me. I still worry about changing the ground of my injector (through a resistor) affecting pulsewidth, but I guess it doesn't matter and I can always change it back if there's a problem.

Yeah, I suspect VCC to go positive and negative but I guess that's all good too. Just need to find my VSS and start splicing.

cfg83
08-07-2007, 04:45 PM
skewbe -

Have you thought about porting this to a PDA? I noticed in other "data logging" car programs that they would use PDAs.

CarloSW2

itjstagame
08-12-2007, 04:35 PM
This should work fine on PDAs, he made it in Java for the very reason that it should work on almost all platforms and OSes. I'm pretty sure there's full java support on all PDAs and smart phones and that's what most of their applications are made in. You just need to have a line in port on the PDA... which I'm not sure will exist, it should exist on a smartphone or any cellphone for that matter (they all have full Java I think), well microphone input will anyway.

itjstagame
08-12-2007, 04:37 PM
I believe my injector has a switched ground, so I'm on the other side of that, counting on the voltage drop across the resistor to give me a signal.


Wouldn't you need to pull infront of and behind the resitor in order to read the drop across it? In fact wouldn't doing it that way cut your max voltage off at whatever can pass through whatever weight the resistor is?

Right now you're pulling from infront of and behind the diode array (which I still don't understand as I don't understand diodes). I will give it a try though.

skewbe
08-12-2007, 04:49 PM
I had to make compromises because of the common line-in ground between the two signals. There's a lot of variables so If you point me at a schematic for your injectors and vss I will take a look and make a suggestion.

sonyhome
08-13-2007, 12:05 PM
Think of the diode as an open switch until the voltage drop across it is 0.7Volts.
Then it is a closed switch with a constant 0.7V drop.

So it has 2 modes of operation to consider when you read the diagram. The "bridging" is done to garantee it behaves the same independant of the current direction.

Bill in Houston
08-13-2007, 12:25 PM
A diode is also a "one-way valve" for current, if you don't mind a plumbing analogy...

mpmetro
08-13-2007, 08:25 PM
yay... I just connected mine in my 91 geo metro, 3cyl, and It is working. One thing is not right though. The speed that the program shows is about 5 mph higher than the actual speed on the speedometer. Like if I am going 15mph, the program will show I am going 20 mph. What could be causing this? and how can it be fixed?

skewbe
08-13-2007, 09:11 PM
Way Cool!! Try this:
locate the mpg.properties file , edit it, and change distanceFudge so it is 20/15 (4/3) larger.

It could be caused by 12 inch tires and other model difference from 92-98 I suppose

mpmetro
08-14-2007, 02:27 PM
I have also noticed that now that I have the circuit wired to the car, I have a check engine light on, and the code 24 shows it to be the speed sensor, even though the speedometer works fine. It goes away when I disconnect the vss from the circuit. I migh make a switch when I make this permanent.

Silveredwings
08-14-2007, 02:59 PM
Sounds like input loading by the 10K resistor. Maybe a higher value would fix it? Maybe.

skewbe
08-15-2007, 07:11 AM
or it may need to be isolated with an op-amp/transistor, hmm is your metro vss magnetic?

skewbe
08-16-2007, 12:06 AM
Also, are you auto or stick? I saw a sentance in the haynes that said the vss was in the trans on an auto, and thus it might be magnetic instead of a hard to throw off with a 10k resistor switch.

On a side note, the scangauge started working in the saturn again so I might have cause to work this more actively.

mpmetro
08-19-2007, 12:42 AM
Also, are you auto or stick? I saw a sentance in the haynes that said the vss was in the trans on an auto, and thus it might be magnetic instead of a hard to throw off with a 10k resistor switch.

On a side note, the scangauge started working in the saturn again so I might have cause to work this more actively.

my 91 is a 5spd manual. But I dont worry about the CEL.

sonyhome
08-20-2007, 05:02 AM
Wouldn't a CEL code risk sending your computer in open loop mode, wasting gas?

If you use like a cheapo 741 op-amp, might as well use it in comparator mode then with 2 potentiometers, gives you full insulation, but you'll need to wire a power supply, like a +5V or a +12V to it (or a battery?).

That would send a clean square wave to the headphones and tuning would be at the pots instead of the config file.

I need to find and spend some time to get a setup too to jump on the bandwagon...

Doc
09-12-2007, 07:51 AM
I've got mpg.java to work but have not sure how wire anything to it yet. Trying to work out how to code Java so I can get an Oxygen sensor reading as well. Can this kind of app run off two sound cards so we have 4 channels.
Very Impressive work!!!

skewbe
09-12-2007, 07:12 PM
Thanks Doc, I don't know about two sound cards without trying. It might be operating system dependant (i.e. you could do it under linux but not windows).

FYI, mpmetro did a good metro specific installation writeup: http://teamswift.net/viewtopic.php?p=255816#255816

ami8i
12-10-2007, 02:20 AM
Hello skewbe,
thank you very much for developing and releasing the mpg monitor!
I came across this forum because I have looked for an item like the Super MID. I'd prefer a µC DIY solution - but exploiting soundcard for such a gauge is very cool.

My problem ist my poor Hardware. What is the oldest possible Java release to get the mpg monitor running?
I tried jre-1_5_0_13-windows-i586-p-s.exe and jre-1_5_0_10-windows-i586-p-s.exe , both installations failed because my laptop does not provide the 'recomended' memory. I guess RAM is meant. There is enough free space on HDD.

The laptop is an old Toshiba Tecra, 133MHz, 16MB RAM, Win98SE.
I can't find any space/memory requirements for any Java release. This site seems to show all Java releases http://java.sun.com/products/archive/

I can't download & test all releases. :(

Thanks and Best regards from Austria
»Horst

skewbe
12-18-2007, 08:06 PM
wow, 16mb, I did not anticipate that. It ran under windows 98 on my 133mhz laptop with 32mb and java version "1.5.0_06". I thought that would be pretty much lowest common denominator. I think if you can upgrade your memory you will be in business.

Here is a $25 48meg upgrade, search for NW2041U in your area or better yet a NW2042U (128 meg) if you want to keep that laptop in service,

http://cgi.ebay.com/TOSHIBA-NW2041U-48mb-MEMORY-TECRA-500-PA2041U_W0QQitemZ330029345136QQihZ014QQcategoryZ11 172QQrdZ1QQssPageNameZWD1VQQcmdZViewItem?_trksid=p 1638.m118

FritzR
02-01-2008, 02:29 PM
hey skewbe

if the purpose of the diode it to keep the voltage to the soundcard uner .775 volts so the signal does not clip above 0 DBV, wouldn't it work as well to just make a voltage divider circut?

If the input impedence of the soundcard was 20K then use a 400K resistor to the input not grounded. That would be something like .5 volts to the sound card. You wouldn't need to worry about loading up the injector signal that way.

rsxer63
06-24-2008, 12:10 PM
Does anyone know if this would work with a Nokia 770?

sonyhome
06-24-2008, 01:05 PM
Try to load the applet on it, and just run it. You then also need to connect the car onto the microphone input.

jtiner
07-24-2008, 12:22 AM
Tada!!, it's somewhere in the ballpark for a 98'tro!! Now anyone who has a laptop or tablet in their car can monitor MPG

***you need to be logged in to see the pictures,
You can go here to see the pictures without logging in:
http://opengauge.org/diympggauge/
***
http://www.gassavers.org/attachment.php?attachmentid=749&stc=1&d=1185090285
*tank will persist when window is closed


Using this circuit, with right and left switched :rolleyes:
http://www.gassavers.org/attachment.php?attachmentid=664&stc=1&d=1183986302


Zoom in on recording of line in (44100 8 bit stereo) for anylizing the waveform (vss* on top, injector on bottom) and general futzing in response. I don't think the diodes are doing much on the vss side :eek:
http://www.gassavers.org/attachment.php?attachmentid=750&stc=1&d=1185091266
*Yellow line is default threshold for the vss,
*Cyan "..." injector
*I adapted the code to the latest wave form (inj pulse was on other channel and right side up?!?)
*vss is the misnamed Vehicle Speed Sensor. It really only measures distance. The computer watching the vss still has to keep track of time to figure out the velocity.



Speaking of code, here it is in it's entirety, 6 drama filled pages to chew on in one file called Mpg.java :

import java.awt.Color;
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.text.NumberFormat;
import java.util.Properties;

import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.TargetDataLine;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class Mpg extends Thread {
static String propFile = "./mpg.properties"; // place to persist confguration and trips.
//Will be created on first run if it doesnt exist.

static int injThreshold = Integer
.parseInt(getProperty("injThreshold", "-30")); // value above the noise

static int vssThreshold = Integer
.parseInt(getProperty("vssThreshold", "100")); // value above the noise

static double distanceFudge = Double.parseDouble(getProperty("distanceFudge", "3200.0"));

static double fuelFudge = Double.parseDouble(getProperty("fuelFudge", "8000000.00"));

static String dummyFile = getProperty("dummyFile", "");

// low level stats tracked in the "trip" class.
class Trip {
String name;

long sampleCount; // num samples, used to compute elapsed time, good
// for about 58 billion hours @ 44100hz

long injHi; // stores number of samples that were "HI" (injector was
// open)

long vssTot; // how many pulses from the vss, indication of distance
// travelled

public Trip(String _name) {
name = _name;
}

// real lightweight update process, gets called at end of audio chunk
public void Update(long _sampleCount, long _injHi, long _vssTot) {
sampleCount += _sampleCount;
injHi += _injHi;
vssTot += _vssTot;
}

public String toString() {
return "name=" + name + ";sampleCount=" + sampleCount + ";injHi="
+ injHi + ";vssTot=" + vssTot;
}

public void reset() {
sampleCount = 0;
injHi = 0;
vssTot = 0;
}

public Trip load() {
sampleCount = Long
.parseLong(getProperty(name + ".sampleCount", "0"));
injHi = Long.parseLong(getProperty(name + ".injHi", "0"));
vssTot = Long.parseLong(getProperty(name + ".vssTot", "0"));
return this;
}

public void save() {
properties.put(name + ".sampleCount", "" + sampleCount);
properties.put(name + ".injHi", "" + injHi);
properties.put(name + ".vssTot", "" + vssTot);
}

public double miles() {
return (double) vssTot / distanceFudge;
}

public double hours() {
return ((double) sampleCount) / (44100.0D * 3600.0D);
}

public double gallons() {
return (double) injHi / fuelFudge;
}

public double mpg() {
return gallons() > 0.0D ? (miles() / gallons())
: Double.POSITIVE_INFINITY;
}
}

class TripPanel extends JPanel {
Trip trip = null;

JLabel name = new JLabel("name");

JLabel miles = new JLabel("miles");

JLabel gallons = new JLabel("gallons");

JLabel mpg = new JLabel("mpg");

JLabel hours = new JLabel("gallons");

JLabel mph = new JLabel("mph");

JButton reset = new JButton("reset");

/** used for limiting numbers to 4 decimal places*/
NumberFormat fm = NumberFormat.getNumberInstance();

public TripPanel(Trip _trip) {
trip = _trip;
setLayout(new GridLayout(1, 8));
setBorder(BorderFactory.createLineBorder(Color.BLA CK));
add(name);
add(miles);
add(gallons);
add(mpg);
add(hours);
add(mph);
add(reset);
reset.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
trip.reset();
}
});
fm.setMaximumFractionDigits(4);
}

public void upDateLabels() {
name.setText(" " + trip.name);
miles.setText(fm.format(trip.miles()));
gallons.setText(fm.format(trip.gallons()));
mpg.setText(fm.format(trip.mpg()));
hours.setText(fm.format(trip.hours()));
mph.setText(fm.format(trip.miles() / trip.hours()));
}

}

private TargetDataLine m_line;

protected boolean m_bRecording = true;

Trip instant = new Trip("instant");

TripPanel instantPanel = new TripPanel(instant);

Trip current = new Trip("current");

TripPanel currentPanel = new TripPanel(current);

Trip tank = new Trip("tank").load();

TripPanel tankPanel = new TripPanel(tank);

public Mpg(TargetDataLine line, AudioFileFormat.Type targetType) {
m_line = line;

new Thread(new Runnable() {// thread to update the view every second
public void run() {
while (m_bRecording) {
instantPanel.upDateLabels();
instant.reset();// reset the instant trip after
// displaying it
currentPanel.upDateLabels();
tankPanel.upDateLabels();
try {
Thread.sleep(1000);
} catch (Exception e) {
}
}
}
}).start();

}

public void start() {
m_line.start();
super.start();
}

public void stopRecording() {
m_line.stop();
m_line.close();
m_bRecording = false;
System.out.println(" inj sampleCount = " + current.sampleCount
+ " inj hi = " + current.injHi + " inj vssTot = "
+ current.vssTot);
}

boolean ig = true;

boolean vg = true;

void processChunk(byte[] b, int c) {
long ih = 0;
long vt = 0;

for (int x = 0; x < c; x += 2) {
int val = ((int) b[x] & 255) - 127;
if (val > vssThreshold && vg) {
vt++;
System.out.println(" vss going hi "
+ (current.sampleCount + (x / 2)));
vg = false;
}
if (val < 0) {
vg = true;
}

val = ((int) b[x + 1] & 255) - 127;
if (val < injThreshold) {
ig = true;
}
if (val > 0)
ig = false;
if (ig)
ih++;
}
instant.Update(c / 2, ih, vt);
current.Update(c / 2, ih, vt);
tank.Update(c / 2, ih, vt);
}

public void realrun() {
byte[] buffer = new byte[m_line.getBufferSize()];
while (m_bRecording) {
int c = m_line.read(buffer, 0, m_line.available());
if (c != 0) {
processChunk(buffer, c);
}
}
}

public void run() {
if ("".equals(dummyFile))
realrun();
else
dummyrun();
}

public void dummyrun() {
try {
String strFilename = dummyFile;
File soundFile = new File(strFilename);
AudioInputStream audioInputStream = null;
audioInputStream = AudioSystem.getAudioInputStream(soundFile);

int nBytesRead = 0;
byte[] abData = new byte[44100];
while (nBytesRead != -1) {
nBytesRead = audioInputStream.read(abData, 0, abData.length);
if (nBytesRead >= 0) {
processChunk(abData, nBytesRead);
}
try {
Thread.sleep(1000);
} catch (Exception e) {
}
}
} catch (Exception e) {
e.printStackTrace();
}
}

public static void main(String[] args) throws Exception {

AudioFormat audioFormat = new AudioFormat(
AudioFormat.Encoding.PCM_SIGNED, 44100.0F, 8, 2, 2, 44100.0F,
false);
DataLine.Info info = new DataLine.Info(TargetDataLine.class,
audioFormat);
TargetDataLine targetDataLine = null;
targetDataLine = (TargetDataLine) AudioSystem.getLine(info);
targetDataLine.open(audioFormat);
AudioFileFormat.Type targetType = AudioFileFormat.Type.WAVE;

final Mpg recorder = new Mpg(targetDataLine, targetType);
JFrame j = new JFrame("MPG Monitor!!!");
j.setSize(640, 125);
Container c = j.getContentPane();
c.setLayout(new GridLayout(4, 1));

JPanel hd = new JPanel();
hd.setLayout(new GridLayout(1, 8));
hd.add(new JLabel(""));
hd.add(new JLabel("MILES"));
hd.add(new JLabel("GAL"));
hd.add(new JLabel("MPG"));
hd.add(new JLabel("HRS"));
hd.add(new JLabel("MPH"));
hd.add(new JLabel(""));

c.add(hd);
c.add(recorder.instantPanel);
c.add(recorder.currentPanel);
c.add(recorder.tankPanel);

j.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
recorder.stopRecording();
recorder.tank.save();//this just adds the trip fields to the properties object
try {
properties.store(new FileOutputStream(new File(propFile)),"");
} catch (Exception f) {
}
System.exit(0);
}
});

j.setVisible(true);
recorder.start();

}

static Properties properties;

static String getProperty(String tag, String dflt) {
String s = "";

try {
if (properties == null) {
properties = new Properties();
try {
properties.load(new FileInputStream(new File(propFile)));
} catch (Exception e) {
}
;
}
s = properties.getProperty(tag);
if (s == null) {
s = dflt;
properties.put(tag, s);// will propogate default values to the
// file
}
} catch (Exception e) {
}
return s;

}

}


So, believe it or not, it's all there. I think its a solid proof of concept anyway. Every car will be different, and there's plenty else that can be done to it: RPM column, invert signal/swap channel from mpg.properties file. A a collection of presets for different cars... But I, personally, am gonna try and do other stuff for a while :)
I am new to this forum and I have been reading the thread about diy mpg gauge using a laptop. Quite an ingenious idea! Very clever. I am ready to put this circuit together but I have a few questions: 1. What kind of diodes should be used? 2. The injector wire; is this an injector wire from an individual injector or the wire that controls all of the injectors? 3. Is it possible to hook this up to a palm pilot?

I am planning to set this up on a 1996 Chrysler concorde and if successful I will publish photos and a tutorial for this car.

sonyhome
07-24-2008, 01:15 AM
[QUOTE=jtiner;112351]
1. What kind of diodes should be used? 2. The injector wire; is this an injector wire from an individual injector or the wire that controls all of the injectors? 3. Is it possible to hook this up to a palm pilot?
[QUOTE]
So I'm not the expert but I'll pitch in:
1- any diode, for example some from a power supply.
2- I think it's directly from one of the injectors.
3- Try to run the applet first. Load it on palm & I say save an audio file on an mp3 player, and play it back to the palm via a wire conecting both. If it works you should be OK.

jtiner
07-24-2008, 11:37 AM
Thanks for the advise.

Are there parameters within the software that I need to program to the specifics of my car? In other words, if I am using an injector wire from one injector do I need to program the software for 6 cylinders (x6)? I am thinking of the calculations it needs to make for the entire engine, not just one cylinder.

sonyhome
07-24-2008, 07:23 PM
Don't expect to have it right off the bat: I think there's a small config file to define parameters and tune to your car... Injector size, delay between open and gas flow, # cylinders, tire rotation speed, etc will impact the MPG reading. I think it's all in the original post/thread. You can also contact the guy who wrote this instead of my 2nd hand flaky info.

jim-frank
08-26-2008, 11:01 AM
I've recently gotten this to work just fine. Here's my take on it.

1)Any silicon small signal diode will do. Radio Shack or scavenge. (Actually, a germanium diode will work, but you'll get a maximum signal of about 0.3 volts instead of 0.6 volts.)

2) Yes, use the injector wire from just one cylinder, whichever wire is easiest to get to is fine.

3) If your Palm Pilot has a stereo line level sound card input, you can do it. Otherwise, no deal. You'd also have to get the Java app ported to Palm OS. (I don't know how that would be done).

There are only four variables that need to be calibrated to your vehicle. These are called fuelFudge, distanceFudge, injThreshold, and vssThreshold.

They are found in the mpg.properties file that the program creates the first time you run it. You can open this file with any text editor, (with the program NOT running) and then save your changes before running mpg.java again.

I found some details that are scantily covered in the information above, and these are relevant.

Once you get the interface electronics wired up and connected to a soundcard, it's a good idea to run a recording of the signal. I use CoolEdit or Adobe Audition, but anything that will let you record and then zoom in on the waveform will do.

A peek into the java code reveals that the waveform is decoded for the program as numbers from -127 to +127. This number is the number of samples above or below zero that the waveform goes. This number is also what is referered to as the threshold variables in the program.

In my case, the injector waveform makes a pretty clean vertical line at the opening/closing of the injector, (like a square wave), so a threshold of near zero works OK. I adjusted mine to -8, which prevents false injector readings when the engine is off (noise signals will vary around the zero line by some amount.)

The vehicle speed sensor waveform in my car is a steep sided quasi-sinewave. A look at the waveform shows that it varies from -65 to plus 65 or so, and a threshold of about 10 works for me.

After you have set the threshold factors, you can set the fuelFudge and distanceFudge to correspond to your car.

Set the distanceFudge first by running down the road and having a helper (for safety's sake) monitor the speedometer versus the program's calculated speed. The program counts the number of speeds sensor pulses in a one second interval, then divides this by the distanceFudge to get the speed.

So, if the program shows that you are going faster than the speedometer, INCREASE the fudge factor. If it shows a calculated speed lower than the actual, DECREASE the fudge factor.

You can get pretty close with a little math. If the distance Fudge is 3200, (the beginning default value), you're going 60, and the program shows 70, then you're off by (70/60)*3200, or about 373. So try a fudge factor of 3573. When you get within a few percent, it's easier to just tweak the fudge factor by two to five units at a time, say from 3573 to 3575, then 3580, etc.

Over a long trip the TANK total miles (bottom box in the program) will be more accurate to tweak the fudge factor. So if you have 400 miles on the tank, and the program has calculated 375, you will have to decrease the fudge factor a bit.

Now that you have the speed calibrated, it's time to get the fuel factor set up. It works the same way, the program divides the total number of fuel injector pulses by the fuelFudge to get the actual fuel usage. You can get pretty close by topping off the tank, running the program while driving a quarter to half a tank off, then comparing the total gallons calculated with what it actually takes to fill the tank back up.

Same math will get you close, so if the program says it took 10 gallons, and it actually takes 8, you have to increase the fuelFudge by about 1.25 times. (The default is 8 million, so you'd want to try 10 million) It takes a bit of tweaking to get this one set up, but just a tank or so of fuel should get you pretty close indeed.

I hope this helps you all out.

Jim

curjones
09-02-2008, 07:46 AM
I'm kinda lost here. May never get what you are doing so be gentle. Are you using the sound card already in the computer. Then do you have to enter some data to make this program work on the computer. Im trying to understand the basic concept. I have seen where you can buy programs that read gauges and sensors on the lap top.

theholycow
09-02-2008, 08:12 AM
The idea is pretty cool: You use the existing sound card, since what comes over the injector wire resembles sound enough to be accurately recorded by the sound card. There's a program that analyzes that input, designed for this purpose; you just need to adjust that program.

curjones
09-02-2008, 09:10 AM
So you buy the program, name,where and how much. Do you have to have a specific sound card.

theholycow
09-02-2008, 10:12 AM
That's a good question about the program. I didn't know it existed until jim-frank posted about it above. Before that, I just knew that others have connected to sound cards, as in this thread:
http://www.gassavers.org/showthread.php?t=7608
(that link is in my thread about using the HF multimeter, too)

To do it that way, no specific sound card is necessary. The same is almost certainly true of the program jim-frank uses, which he says runs on Java; Java is somewhat hardware-agnostic, and uses the OS to deal with stuff like sound cards. I hope he comes back and posts the name of the program and tells us where to find it. A few minutes of googling failed to produce it for me.

I'd recommend trying it on a computer you're not afraid to hurt, first, just in case your fuel injection system uses high voltage or current or could otherwise damage the computer...after all, you are making a connection that no engineer ever expected you to make.

curjones
09-02-2008, 10:23 PM
Was the name Audacity. That is what I pulled from the link you gave. Once you load the program are they using java to program to get the wave form. I know nothing about programing. I saw he had a bunch of language on a scroll down. I have seen other devices that you can hook up to the computer but they are expensive.

curjones
09-02-2008, 11:15 PM
This site had some basic inf0. I believe the people here Have found a way to use a sound card and cut some cost.

http://www.aldlcable.com/

I have not got to read every thing but it looks like it has some really great info.. What do yall thiink. Think Ill make it a new thread.

theholycow
09-03-2008, 07:36 AM
Audacity is a great audio editor, and was used in the link I gave you to view the waveforms...but it's not made for hooking up to fuel injection, it's just for audio. It can't do the calculations we need.

Where did you see the computer language? All I saw was a schematic for fuel injectors.

sonyhome
09-03-2008, 11:19 AM
I'm too lazy to search though the forom or even this thread, but the MPG monitor was published on the forum both as a java binary and with the source code in case someone wants to edit it.
The source code is not needed to run the app.
just D/l the binary and run it.

The waev editor is just for kicks to look at the audio file.

The collection is done via the stereo microphone input of a PC/PDA or anything running java. One side collects Vss (speed sensor) and the other collects the fuel injector signal. From both you compute MPG.

Vss is a pulse AFAIK, so from its frequency you compute speed (but gotta calibrate it). FI signal is a on/off signal so ignore frequency, but compute duty cycle (how long on vs total of a cycle).

theholycow
09-03-2008, 12:00 PM
Oh....it's this thread! Hahahah, I didn't even look back at earlier pages in the thread...d'oh!

There's some good stuff on the first couple pages!

This one has the compiled binary program:
http://www.gassavers.org/showpost.php?p=65266&postcount=43

Thanks, sonyhome! :D

Lurch
09-06-2008, 01:30 PM
ummm, is this device you guys are building just for detecting the mpg??
if so its getting very complex. I like the soldered mass of diodes and resistors though. just have to wonder if he burnt himself :(

itjstagame
09-12-2008, 11:11 AM
Wow this brings back memories. I can't believe it was over a year ago I was planning to do this and did nothing. I need to see where I put those diodes I bought or buy more. For some reason this time the circuit doesn't look as confusing or maybe I just want to jump in and test it more.

As for program, it's Java for now. Sony did you or anyone else ever use a graphics library and make anything cool? I saw a different thread in Holy Cow's thread but didn't see what code he was using.

The big thing holding me back was having no idea where my VSS signal is. I looked under the car, by the tranny and have no idea. Holy Cow you have a similar vehicle (fullsize chevy P/U), do you have any idea where VSS is or the lines run up from the tranny?

After that I need to reread the code, I remember making a lot of changes so I could calibrate easier and tell me fuel vs. acceleration and trying to build a way to automate cid calculation (but couldn't figure out how to solve the entire curve so that was a messy cludge).

itjstagame
09-13-2008, 01:52 AM
Man, why did I take a year to do this, it's so easy. I found and tapped the wire and soldered the diodes up easy. I was worried since the only diodes I could find at Rad Shack said 50v, but they clamp it to .7V. I wired up and described and as MPGMetro did and I tested before I hooked to my laptop. We're producing a cycle wave so I just set my multimeter on AC and tested the voltage. Worked great and I definately had just the inside tip giving a reading and nothing hooked to the other side yet (haven't looked for VSS yet).

I made a sample recording though and I have two channels of data. Maybe my laptop just has a mono microphone jack? It doesn't have a line in like my old laptop used to, just mic.

Now I understand the fudge factors, but what are the vssthreshold and injthreshold for? Attached is a shot of my 1st record. It idled for a while (the left side) and this is a shot of right when I hit the accelerator a bit. .7V is pretty low Db, so does this mean I should lower my inj threshold a bit compared to your car?

Also whenever I start the program with no audio hooked up (and configed to not use a test wav) it keeps displaying random numbers for a while. Sometimes the whole time I'm in the program (10+ mins) and other times it'll stop after a couple mins. Does this happen to you too and any ideas?

Also I've been adding to this program like crazy. I still don't have a good way to calculate the Cid, but I have entrants for Cid, air temp, elevation, car weight and frontal area and I've added current acceleration and HP to the displays. My HP isn't quite right though, I found a good calculation for acceleration times car weight (/ by 32ft/sec^2 to get mass), but I want to add this to a drag calculation http://en.wikipedia.org/wiki/Drag_(physics). My thought being, if I'm holding at 45MPH I don't want it to say 0HP, this way it'd show the HP required for that speed due to drag and also show HP as I accelerate. Once I get this down good I want HP/gal. That way I can finally test if slowly accelerating to 45MPH is better than hot footing it to 45MPH, it should show my best efficiency of the engine (most power for gallon of gas).

So if anyone can decipher that drag calc let me know. My accerlation HP is all in ftlb/min which is standard HP measurement. But when I try even simple examples on paper with the drag calc using either ft, lb or metric I always get very large numbers and I'm not sure what the units are, certainly not HP or watts.

I'll post the code update when I'm done, but it's already been over a year and requires more debugging so who knows when :p.

itjstagame
09-13-2008, 01:54 AM
ummm, is this device you guys are building just for detecting the mpg??
if so its getting very complex. I like the soldered mass of diodes and resistors though. just have to wonder if he burnt himself :(

How can you say it's complex? 2 diodes and a resistor hooked to an injector ( I just did this up in 20 mins or so) and the software works fine out of the box, I'm just adding more stuff I'd like to see. It's a simple java program that reads the injector cycles from the audio input and based on this you can approximate fuel (once you tune the fudge factor).

itjstagame
09-14-2008, 05:48 PM
Ha, I was adding RPMs are 2 * injector firings / min, which makes sense because with 1 injector per cylinder each injectors gets fired every camshaft revolution, that is every 2 crank revolutions.

I just found out my TBI actually injects once for each cylinder firing! So 4 times per crankshaft revolution and 8 times per camshaft rev. Cool!

itjstagame
09-15-2008, 08:57 AM
Ok, another question in case Skewbe comes back. I recorded a run today (just fuel, no VSS yet) and looked it over. My previous test idling looked like I needed a -20 threshold or so and I think this is still good, but I wanted to ask about the strange things I'm seeing.

If you look at the attached pictures, I'd say 'bumpy' is pretty much the normal output I see, here you can see where I'm revving up and accelerating a bit after a turn. Strange that not only the pulses get stronger but I get a very high 'noise' wave. That is, are there only 3 fuel pulses in this picture? Why is it so noisy at the end?

More bumpy is at the same zoomlevel and further in the trip. Now the noise is getting sharp points. Very strange. Again would you say there's only 3 injections there? The 'noise' is starting to look more like injections. At this point I measured the low points of the noise and it was -16, so it's getting close to my threshold.

Then in the middle of my trip it went 'flat'. This is the same exact zoom level and noise is very very minimal and the injections look obvious. There's only two here now. My TBI is supposed to inject once for each cylinder (I think both injectors fire once per each cylinder or 4 times each per revolution), but here I calculated at at this rate in the 'flat' picture it's only 1100 injections per min. That can't be 300 rpm and even at double that, 650 rpm still seems too low (I have no tach in my truck). Is this some form of DFCO or something? It's injecting once per rev and skipping a bunch of cylinders or something?

Even stranger is my SoundForge chops out dead air in the middle. I had many points where it said it cut out 2-3 secs here and there. That must mean the recording was completely flat with no noise. DFCO maybe? This run was only at 45MPH max and I just left it in overdrive the whole time, so I doubt my revs would be high enough for DFCO (as I understand it).

Thoughts ?

itjstagame
09-18-2008, 08:52 AM
Well hooked into the VSS and tested without any resistor or diode using AC voltage. I know it's definately increasing frequency and not voltage but I think it's averaging the voltage and more waves means higher average. Anyway 15MPH was about 10volts and 55MPH was 45Volts, that's a lot. Maybe I should use a resistor bigger than 10k? The diode bridge should clamp to .7, right but still worries me.

sonyhome
10-19-2008, 03:20 AM
Aahh... I still have to do this project and spend some time learning Java. i want to use Eclipse to do the R&D, but need time and must make a decision as to which graphic library to use (there's like 3).

Like ItsJstAGame, I've been lazy to find out where that dang Vss wire is, and how to wire the injector wire through the firewall.
Maybe I can get those signals directly from the ECU (?) inside the car.
I have plenty of crappy old laptops to throw at the problem.

Well, first, gotta fix my alternator and change the timing belt and do brakes.

ItsJstAGame:
You're not making much sense in that last post.

i'll just pitch in generalities, maybe it will answer what you ask:
If you have an A/C signal, the longer the duty cycle, the higher the voltage read. If you have a square signal duty 50% and max Vcc 50V, then the voltage you'll read is 25V (1/2 on, 1/2 off).

If your foot is on the gas pedal, you should not DFCO... Idle is 700~1000rpms, so you can use that as a base and play it by ear. Maybe go to what feels like very sluggish in 5th gear... Will be likely 1500rpm 2000rpm, and record when accelerating: no DFCO for sure.
If you like math and know the gear ratios then you can tell what RPMs you do at a given speed, say in 5th gear.

You should be injecting 4x per rotation on a 4 cylinder, right? Then you need to fudge in the injector size (cc/min), and it's trigger delay (it likely has a latency between the start for oozing gas from when the electric signal is on).

Lastly, your pictures have either high amounts of noise making them unusable, or you're soomed out and are seeing 100's of cycles.
Zoom in to 1 "noise" element, and compute it's frequency looking at the time line displayed by soundforge.
Your connection might be crappy: not shielded well enough and drudging noise from random stuff like the alternator, too inductive or capacitive, preventing the injector signal from reaching the sound card.

@#!$ I got to get my *** in gear and try this project... :\

theholycow
10-19-2008, 07:05 AM
Like ItsJstAGame, I've been lazy to find out where that dang Vss wire is, and how to wire the injector wire through the firewall.
Maybe I can get those signals directly from the ECU (?) inside the car.

I think most ECUs are on the far side of the firewall, so you still have to run wires in.

I have difficulty poking wires through existing firewall holes and hate drilling new ones, so I've found a good way to get wires in without penetrating the firewall at all. Just run them to the side of the car, between the sheet metal and the firewall, and close the door on them. Tuck them behind the dash trim and you only see a couple inches of wire when you open the door.

http://lh5.ggpht.com/ronanian/SEiFSAcEp0I/AAAAAAAACVs/de7QyBMLtEc/s800/IMG_0933.JPG

You should be injecting 4x per rotation on a 4 cylinder, right?

One of us is doing math wrong; wouldn't that be 2 injections per rotation? Don't forget the exhaust stroke...

@#!$ I got to get my *** in gear and try this project... :\

I have the same problem all the time, which is why my grilles are still not blocked. :(

sonyhome
10-19-2008, 11:50 PM
What? You don't have your grills yet?

http://www.goldteeth.com/images/invisible-sets2.jpg

On civics, the ECU is under the passeger's feet. Also found the wires to pull from it...

All OBD-1 Honda/Acura cars:

A1 - INJ1 - Brown - Battery Voltage with KOEO
B10 - VSS Vehicle Speed Sensor - Orange - Pulses 0/12V while spinning front-left wheel

http://www.b18c5eg.com/obd1.jpg

itjstagame
10-20-2008, 03:29 PM
Sweet updates! Well I still haven't tested stuff because I don't have stereo line input :(. But now I'm mostly driving the Festy anyway, the Truck has gone <50 miles in 1 month. But I would like to get it tested and then install on the Festy too.

I can't believe it took be over a year to do becasue it's pretty cool.

As for my 'bumpy' pictures. I really have no idea. I'm quite confident that the larger spikes are the events I want. It's certainly possible the noise could be ignition. It seems to increase with throttle and my unshielded 12 gauge (can't recall actual gauge but not too thick) wire goes right over almost all the ignition wires and the distributor. I mean it's at least 3" away all the time, but still...

As for my confusing post, the VSS is usually a magnet pulsing a coil as the driveshaft or something in the tranny spins, so it produces a AC. Yes I assumed the peak, actual voltage generated would stay about the same, so more AC means higher duty cycle/more AC pulses. Either way it's looking ok when I recorded it, but I used a 33k resitor which may have been a bit too high.

And yes, on a 4 cyl you'd have 2 injections / crank rotation, 4 / cam rotation. On a V8 this is obviously different, but mine is even more different because it's TBI and only has 2 injectors right at the start of the intake runner that feeds all 8 cylinders.

I had originally assumed 2 batch fires / cam rotation (full OTTO cycle), but after reading online it is actually supposed to inject 8 times, I at first thoght this meant 4 times each / cam rotation, but that still looked awefully low, so I decided each one must be firing 8 times, so that's 4 times each / crank rotation. But yeah, definately with it just idling I can see really strange suff, like I can tune so that idle is about 1000 rpm but then when it warms up it can be as low as 350rpm. I'm sure it's just not calculated right, but sometimes I really think it's firing less times/cycle under certain conditions.

sonyhome
10-20-2008, 04:47 PM
LOL! Yeah, no way you can be at 350rpm... Unless your truck sounds and vibrates like a harley.

700rpm more likely.

I'd expect you'd go from 1200~1500rpm when cold down to 700~1000rpm idle when warm.

Vss could also be 12V pulled down to 0V, aka reversed.

As for how many injections per cycle, I dunno...
I dunno why you say 2 injections per cycle. (Note
I do not consider the case of cylinders that have 2 or
4 injectors, 8 or 16 valves or what not) For me an injection
is one injection of gas into a cylinder followed by a burn.
I woud expect each cylinder do do one burn per cycle.
However we're veering off topic here.

theholycow
10-20-2008, 05:13 PM
I woud expect each cylinder do do one burn per cycle.

Yes, but a cycle requires two revolutions.

http://upload.wikimedia.org/wikipedia/commons/a/a6/4-Stroke-Engine.gif (http://en.wikipedia.org/wiki/Four-stroke_engine)

itjstagame
10-21-2008, 08:27 AM
Yes, when I say cycle I mean full OTTO cycle, 2 revolutions of the crank and 1 revolution of the cam.

As for the 2 injections it's because I only have 2 injectors on my V8, not 8. The ECU could fire those whenever and how ever often it wants to as long as it's fuel requirements/cycle are met. Which is why I'm wondering if at idle or below a certain pulsewidth time if it doesn't just drop from 8 injections/cycle to 4 injections/cycle with larger pulse widths. I mean depending on injector size and fueling requirements I'd totally program it to do this so who knows what GM did.

theholycow
10-21-2008, 09:20 AM
Yes, when I say cycle I mean full OTTO cycle, 2 revolutions of the crank and 1 revolution of the cam.

Yeah, that discussion was a response to this:
AYou should be injecting 4x per rotation on a 4 cylinder, right?

Anyway...back to our regularly scheduled programming...

Which is why I'm wondering if at idle or below a certain pulsewidth time if it doesn't just drop from 8 injections/cycle to 4 injections/cycle with larger pulse widths. I mean depending on injector size and fueling requirements I'd totally program it to do this so who knows what GM did.

Measuring duty cycle, which IIRC is what we're talking about (but maybe I'm lost again), makes the question unnecessary. Whether you have 8 small injections or 4 large injections, your duty cycle is the same. This may be a short-attention-span-failure on my part...

itjstagame
10-21-2008, 10:05 AM
Good point, I'm sure we could change the code to work in this way possibly. Right now though the code just looks at each injection event. That is the 'pips' we see on the sound graph, it estimates that each pip corresponds to a certain amount of injected fuel and during a longer duty cycle would read as multiple 'pips' depending on how long is lasted. It samples at 44Khz (that's 44,000 times/ sec) and if the value is above a certain threshold it calls that a 'pip' a