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:
# 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 .
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.
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.
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).
I noticed the com1 and I think I tried changing it, however the problem I am having is this part of the .pl file:
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.