I wrote this class back in the day.. Basically, once you create mscomm1 and timer1 you'll never need to touch those controls. When you use
dim withevents elm as clselm323
then you should see "elm" as a control in the code window with its own events. Those events fire whenever things happen with that class. So you don't have to handle mscomm1_oncomm at all.
Let's say that your elm323 is on com2.
strReturn$ = elm.openELM(mscomm1, 2, timer1)
if strReturn$ = "" then
msgbox "opened successfully"
msgbox "open error: " & strReturn$
private sub elm_statusmessage(byval strMessage as string)
private sub elm_OBDReturn(ByVal bMode As Byte, ByVal bPID As Byte, ByVal strData As String, ByVal lngData As Long)
msgbox "OBD Returned mode " & cstr(cint(bMode)) & ", pid " & cstr(cint(bPID)) & ": " & cstr(lngdata)
First of all thanks Erorus for nice class. I was able to implement OBD read VB program in few hours.
I tried using the MPG calculation in above thread and it seems to be pretty accurate. Many constants are similar to what is shown in this thread but this thread seems to be missing pound to gallon conversion and seems to be off by 10x as well. I see that the fuel trim is used here. I'll try to apply that. Looks like it may give you better estimate for your car rather than looking for ideal values.
The equation I am using is
14.7 g of air / 1 g of gas * 6.17 lb / 1 gal * 454 g / 1 lb * VSS Km / 1 h * 1 Mi / 1.609344 Km * 1s / MAF (100g from OBD) * 100g * 1 h / 3600 s * (0.7812 * (LTFT - 128) + 1)
Which will be
710.7 * VSS / MAF * (0.7812 * (LTFT - 128) + 1)
When cruising I get about 20 MPG and when I press the clutch I get like 105MPG which kinda makes sense.... =P When I calculate MPG when I fuel my car I get about 23MPG so I think this is pretty close.
Erorus, do you know if there is a way to read the OBD data in burst fashion? Or is this the limitation of ELM chip? I tried to tune the time to read the data from OBD but reading those three data takes at least 2.5 s. I kind of want to be able to read all three at the same time to increase the accuracy. In 2.5 second many things can change.
Is there a way to read back the data more quickly?
If not I guess running average or something similar can be implemented I suppose.. =)
Actually instead of 0.7812 it should be -0.007812. I forgot this was in percentage and also positive value means on LTFT means using more fuel.
I found my error regarding data ready time. I've set the timer interval before openELM function so default must have been assigned. I was able to set it to 200ms without getting any errors. However it would still be nice if we can read the data at the same time though. Is this possible?
Wouldn't it be easier to just use injector duty-cycle, engine RPM, and speed to derive this data?
I know nothing about PHP and I also know very little about what is avalible from the OBD2 interface, but here goes:
Yes i always wanted to make one of these. But i dont know how im not that smart of a person. But i love to learn ... You people know any good places to find codes for this stuff.
what is the bMode used in send_to_obd? also, what form should i be sending the PIDs as? something like "SAE.RPM" or the hex value 0C ?
and example send_to command would be helpful as well