OBDII CarPC MPG Calculator - Fuelly Forums

Android Users - Coming Soon! - Migrating from aCar 4.8 to 5.0

Reply
 
Thread Tools Display Modes
 
Old 10-04-2007, 06:51 AM   #1
Registered Member
 
Join Date: Apr 2007
Posts: 245
Country: United States
OBDII CarPC MPG Calculator

Some of you may have seen my previous thread about my CarPC, things are going well and I am ready to start working on the code to get MPG calculated out of the sensor data from my OBDII port.

HERE is a link to the other thread if you want to know what I am working with here.

The important part is the scanner, which is an ElmScan 322 from www.scantools.net. This device is for my 2000 Saturn SL.

I have found a perl program that was last updated in 2003 which should do basic polling of data from the port (I don't really know what is going on, just guessing here). This program and source can be found HERE I will also attach the zip in case the site goes down.

This program does not appear to pull any data involving injector pulses. I am going to try and hook up to my obdII port while running a program like Hyperterminal to see if I can tell what all data is coming out of it. I have not had much of a chance to mess with it yet but I am hoping to get some support on the programming side as this is quite new to me .

Also, if you think I should start with a different program let me know. I could change.

Another I had considered was JDash, it is based on Java but the programmer said that his program did not do anything but look at realtime data so calculating values off of the data that came in was beyond it. Not sure if that is a limitation of Java or just his program or what. I am not knowledgeable enough to know.

Something cross platform would be great in case someone else here wanted to run something on a Windows machine and could put to use some of what we figure out here.

Here is a section of the code, this is what appears to be the extent of the data that this perl script is programmed to grab, this is from the .ini file:

Code:
# Enable PID = 1, Disable PID = 0

$PID01 = 1;                # Number of trouble codes and test information
$PID03 = 1;                # Fuel system status
$PID04 = 1;                # Engine load %
$PID05 = 1;                # Coolant temp
$PID06 = 1;                # Short term fuel trim %, Bank 1
$PID07 = 1;                # Long term fuel trim %, Bank 1
$PID08 = 1;                # Short term fuel trim %, Bank 2
$PID09 = 1;                # Long term fuel trim %, Bank 2
$PID0A = 1;                # Fuel Pressure
$PID0B = 1;                # Intake manifold pressure
$PID0C = 1;                # Engine RPM
$PID0D = 1;                # Vehicle speed
$PID0E = 1;                # Timeing advance degrees
$PID0F = 1;                # Intake air temp
$PID10 = 1;                # MAF air flow
$PID11 = 1;                # Absolute trottle position
$PID12 = 1;                # Sec. air status
$PID14 = 1;                # Oxygen sensor voltage, Bank1, sensor 1
$PID15 = 1;                # Oxygen sensor voltage, Bank1, sensor 2
$PID16 = 1;                # Oxygen sensor voltage, Bank1, sensor 3
$PID17 = 1;                # Oxygen sensor voltage, Bank1, sensor 4
$PID18 = 1;                # Oxygen sensor voltage, Bank2, sensor 1
$PID19 = 1;                # Oxygen sensor voltage, Bank2, sensor 2
$PID1A = 1;                # Oxygen sensor voltage, Bank2, sensor 3
$PID1B = 1;                # Oxygen sensor voltage, Bank2, sensor 4
My main goal here is to get instant/trip/tank etc. MPG figures. Of course once instant and trip is figured out everything else should be just moving code around I would think. Of course a nice front end would be nice but something that showed up in a terminal window is just fine for now .

Google findings
http://www.circuitcellar.com/avr2004/wabstracts
MPG = VS * 71.07 / MAF

where VS = vehicle speed in kph (mode 01 PID 0D)
and MAF = air flow rate (mode 01 PID 10)
Attached Files
File Type: zip OBD_logger_perl.zip (4.4 KB, 89 views)
__________________

__________________
Fourthbean is offline   Reply With Quote
Old 10-04-2007, 07:25 AM   #2
Registered Member
 
skewbe's Avatar
 
Join Date: Jan 2007
Posts: 771
Country: United States
I don't know if all those values will be available, but anyway

just looking at Vehicle Speed/MAF will get you in the ballpark with some fudge factors to turn Vehicle speed into miles and MAF into gallons.

You might be able to tune MAF by determining the AF ratio, but I dont know if PID14 is available and if it is it could be even more logic to make sense out of the pulses.
__________________

__________________
Standard Disclaimer
skewbe is offline   Reply With Quote
Old 10-04-2007, 08:39 PM   #3
Registered Member
 
Join Date: Apr 2007
Posts: 245
Country: United States
Does anyone know what the Scangauge uses to measure MPG? I am considering that it also uses the MAP sensor as you must adjust it initially to get it right and modding for lean burn does not show up on the scangauge.
__________________
Fourthbean is offline   Reply With Quote
Old 10-04-2007, 09:02 PM   #4
Registered Member
 
skewbe's Avatar
 
Join Date: Jan 2007
Posts: 771
Country: United States
I don't know about the scangauge and am loathe to so blatently reverse engineer it, but there is tons and tons of obd <-> computer stuff online, here is a visual basic mpg function:
http://www.mp3car.com/vbulletin/engi...tml#post605372

I just googled for mpg obdii and scanned a little bit to find it.

You might want to cut and paste that function into a text file so you can refer back to it.
__________________
Standard Disclaimer
skewbe is offline   Reply With Quote
Old 10-05-2007, 01:56 AM   #5
Registered Member
 
Join Date: Apr 2007
Posts: 245
Country: United States
Thanks for the help so far. I wasn't meaning to imply reverse engineering, however I haven't looked at any documentation for the Scangauge so was curious if they had mentioned what values they use to calculate MPG off of.

I found some documentation for the ELM chip I am using, basically the port can be told to monitor everything happing in the car. It will send codes in hex with the second part of the first byte being the identifier to what that value relates to and then the rest being the relevant information. Seems pretty easy to decode and this perl script makes it look fairly simple.

The question is, will I be able to make it work. lol

I am currently trying to get this perl program to open my serial port. As although it was written in "cross platform" perl the command to open the serial port is for dos . I have sent an email to the developer hoping I can get some help and I am currently trying some other ways inside the code to open the port.
__________________
Fourthbean is offline   Reply With Quote
Old 10-05-2007, 05:17 AM   #6
Registered Member
 
skewbe's Avatar
 
Join Date: Jan 2007
Posts: 771
Country: United States
Hmm

For the com port, try editing obd.ini and changing:
$COM_PORT = "com1";
to:
$COM_PORT = "/dev/ttyS0";
__________________
Standard Disclaimer
skewbe is offline   Reply With Quote
Old 10-05-2007, 05:22 AM   #7
Registered Member
 
skewbe's Avatar
 
Join Date: Jan 2007
Posts: 771
Country: United States
Mp3car.com isn't working this morning? Anyway that mpg function was factoring in MAF, Vehicle Speed, and Long Term fuel trim.
__________________
Standard Disclaimer
skewbe is offline   Reply With Quote
Old 10-05-2007, 05:43 AM   #8
Registered Member
 
skewbe's Avatar
 
Join Date: Jan 2007
Posts: 771
Country: United States
I'll shut up shortly and give you a chance to look at things, just wanted to mention that if MAF is not available then you can get close by properly combining Manifold absolute pressure, RPM, and air intake temperature and a config variable for engine displacement. Humidity will be left out of the equation.

Also if your com port is not com1 (i.e. com2) then you will need to change ttyS0 (i.e. ttyS1).
__________________
Standard Disclaimer
skewbe is offline   Reply With Quote
Old 10-05-2007, 08:21 AM   #9
Registered Member
 
Join Date: Apr 2007
Posts: 245
Country: United States
I noticed the com1 and I think I tried changing it, however the problem I am having is this part of the .pl file:
Code:
#
#    Subroutines
#


sub open_tty                              # Open Com port and remove echo (ate0)
{
  system ("mode com1 baud=9600 parity=n data=8 stop=1 rts=off dtr=off >NUL");
  open DEV,"+>$COM_PORT" or die "Failed to open communication port\n";
  $ofh = select(DEV); $| = 1; select($ofh);
  print DEV "ate0\n";
  select(undef, undef, undef, 0.5);
  $jnk = <DEV>;

}
It is calling the command "mode" from the system. Which I cannot find for linux. So I am hunting around trying to find something that will work in it's place. I still haven't found anything that will allow me to connect to the serial port and see the codes like I can in hyperterminal in Windows.

I found code HERE showing how to access a serial port but could not get it to work for me . I set the Serial port to /dev/ttyS0 and also tried /dev/ttyS2 (seems those are the only valid ones on my system, though I cannot remember how I figured that out).

I also changed all the parameters to the correct ones for my obdII scanner. When running just that logger.pl perl script it acts like it is working (no error messages) but nothing gets written to the log file. I sent the command ATMA and also tried ATMA\n for it to hit enter after the command to no avail.

I will be working more on it soon, just wanted to keep this thread updated so that I know where I am at. And so that if anyone had anything to add they could.

I remember seeing that thread while doing my OBDII searching. I will have to do as you say and grab the values for later use in calculations. Thanks.
__________________
Fourthbean is offline   Reply With Quote
Old 10-05-2007, 05:01 PM   #10
Registered Member
 
skewbe's Avatar
 
Join Date: Jan 2007
Posts: 771
Country: United States
man stty
__________________

__________________
Standard Disclaimer
skewbe is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Not very precise mpg calculation larjerr Fuelly Web Support and Community News 4 08-20-2012 02:03 AM
Keeping my distance in traffic khurt General Fuel Topics 8 09-07-2008 04:23 AM
1986 toyota celica - a work in progress 86Celica Introduce Yourself - New member Welcome 22 01-07-2007 05:43 AM
Electrical power and cars. DracoFelis Automotive News, Articles and Products 2 09-16-2006 02:31 PM
"active" aero grille slats on 06 civic concept MetroMPG General Fuel Topics 21 01-03-2006 01:02 PM

Powered by vBadvanced CMPS v3.2.3


All times are GMT -8. The time now is 08:34 PM.


Powered by vBulletin® Version 3.8.8 Beta 1
Copyright ©2000 - 2017, vBulletin Solutions, Inc.