FAQFAQ SearchSearch MemberlistMemberlist UsergroupsUsergroups RegisterRegister
ProfileProfile Log in to check your private messagesLog in to check your private messages Log inLog in

 
Proper data logging on OBD1 via Arduino

 
Post new topic   Reply to topic    TunerPro User Forum Forum Index -> Bosch
 
Hairyscreech



Joined: 20 Jun 2017
Posts: 157

PostPosted: Mon Nov 27, 2017 6:59 am    Post subject: Proper data logging on OBD1 via Arduino Reply with quote

After some trouble over the weekend getting the car to run well it is clear the biggest issue we face is not being able to log data properly from these ECUs.

The hit tracing is good but is never going to provide the level of detail that we need to find faults and 1 man tune these early motronic ECUs.

I was thinking about how to resolve this and came up with the idea of using an arduino to log signals and output the information via a normal OBD2 output.

This would essentially piggyback onto the ECU and monitor several inputs, most likely creating a couple of calculated channels (i.e. calculated load) and then spitting them out on demand to a normal OBD2 interface.

I did a bit of research and found that someone has created a OBD2 stimulator that throws out random OBD2 signals for testing OBD2 readers.
This was based on an arduino and has a lot of what we need baked into it.
The big change would be to make it sense and calculate the outputs rather than generating them at random.

An Arduino Mega2560 has all we need to do this job and they are cheaper than a pint in some london pubs. I think this can be done for way less than 100 but I know I am going to need help programming and testing this thing.

So who's in?

I have the following so far:

Arduino Mega2560 Generic - 8
CAN BUS shield Elec freeks - 6
EML327 OBD2 interface - 10
Dual VR sensor board - 18

Signals
- All input signals need to be limited to 5v max.
- TPS 0-5v signal, generally 0.4-4.5v - Might be ok to just tap as not as precise as we expect.
- MAF 0-5v signal, generally 2-5v - Sugested to use OP-amp buffer to prevent altering the voltage.
- IAT - As TPS?
- CLT - As TPS?
- WBO2 0-5v - Comes direct from gauge, probably just feed it in.
- Crank VR signal - Fine to feed direct but needs diode clamps to prevent over voltage.
- Cam Hall effect, 0-5v max. - Not really needed if V drop of coil 1 is used as reference? Square wave so just tap in.
- Ignition Cyl 1, Grounded 12v signal, Replace Cam signal? Need to sense this without grounding coil. Use inductive sensor instead?
- Injector 1 pulse width, grounded 12v signal
- VSS VR signal? Same issues as crank sensor? Same issue if taken from output to clocks?
- Vanos simple 0-12v on/off signal, reduce to 5v and connect to digital i/o pin.

Issues
- VR sensor has posibility to over voltage, Meg2560 needs protection from over voltage (Clamps?) how is the stock ECU protected?
- WBO2 output needs to be incorporated, simple 5v signal? Is it worth logging the stock lambda sensor if WBO2 is available?
- Load signal big issue, need to figure out the eqation used and program this into the Mega2560, check Nefmoto?
- Can power the board from 12v using Vin pin but need to regulate to 12v max?
- Code code code!

Posibilities
Could provide sensor diagnostic without pluging into ECU
Can obviously data log and feed to tunerpro
Can provide true injector pulse width and spark timing
Could use switched output to activate add on systems like a piggyback
Could be used to correct fuel signal to OBC/dash
Could take single vanos signal and control dual vanos with it
Could be used to switch on warning lights or feed back warnings to the ECU
If we can disassemble enough code the ATmega2560 is capable of running modified motronic code natively
Could provide digi dash readouts
Ability to provide more live data than the ECU ADS system.
Could be made to replicate stomp test using TPS connection and feedback the blink codes?
Could interface with a CAN device to control it or/and prevent issues


Last edited by Hairyscreech on Tue Jun 12, 2018 4:49 am; edited 1 time in total
Back to top
View user's profile Send private message
 

 
Hairyscreech



Joined: 20 Jun 2017
Posts: 157

PostPosted: Wed Nov 29, 2017 1:51 pm    Post subject: Reply with quote

Well with surprisingly little interest I have gone ahead and started anyway, the OBD2 reader turned up today so I popped that open (glued, not easy or pretty) and removed the resistor between the 2 CAN pins. It is not needed and ruins the communication on a lot of cars, the pins are notmally filtered with a resistor and capacitor but I doubt we will have much noise on the CANBUS given it is going direct to the Arduino CAN shield.

Speaking of which I broke the CAN high and CAN low pins out from the OBD socket so I can send them direct to the high and low on the CAN shield.

The Mega2560 should turn up by Friday along with the CAN shield hopefully so I will get onto that soon as it turns up.

The links I posed seemed to disappear, I assume spam protection of some kind but there are on a text document in my dropbox.
I will post them again and see if they go.

In the meantime have some pictures:
Edit - Holy pic size batman. Best to go with the link here: https://imgur.com/gallery/H06hP

Also the info links missing from the first post:
Mega2560 documentation - https://www.arduino.cc/en/Main/arduinoBoardMega2560/
CAN BUS shield infromation - https://www.elecfreaks.com/wiki/index.php?title=CAN-BUS_Shield
CAN BUS Shield store link - http://www.elecfreaks.com/estore/can-bus-shield.html
ELM327 data sheet - https://cdn.sparkfun.com/assets/learn_tutorials/8/3/ELM327DS.pdf
OBD2 protocall information - https://en.wikipedia.org/wiki/OBD-II_PIDs
Guide for OBD2 simulator - http://techtinker.co.za/forum/viewtopic.php?f=14&t=10
Guide for OBD2 simulator - http://www.instructables.com/id/Arduino-OBD2-Simulator/
Op-amp buffer - https://www.eecs.tufts.edu/~dsculley/tutorial/opamps/opamps5.html
Speeduino dual VR board - https://diy-efi.co.uk/home/17-dual-vr-conditioner-speeduino-compatible.html
Notes on tapping Motronic signals - https://www.reddit.com/r/AskElectronics/comments/2p4hyg/car_ecu_question_if_i_tap_into_sensor_wires_in/
M44 OBD2 datalogging - http://m44.wikia.com/wiki/Data_logging
Sample ananlogue read code - https://www.arduino.cc/en/Tutorial/ReadAnalogVoltage
Speeduino code overview - https://speeduino.com/wiki/index.php/Code_overview
Back to top
View user's profile Send private message
 

 
Mykk



Joined: 05 Sep 2015
Posts: 96

PostPosted: Wed Nov 29, 2017 1:59 pm    Post subject: Reply with quote

Absolutely in, just don't have much to contribute as this is over my head. I have heard of people making standalone efi arduino units called Speeduino.

Last edited by Mykk on Wed Nov 29, 2017 2:51 pm; edited 1 time in total
Back to top
View user's profile Send private message
 

 
Hairyscreech



Joined: 20 Jun 2017
Posts: 157

PostPosted: Wed Nov 29, 2017 2:20 pm    Post subject: Reply with quote

I have been wondering if and arduino could be a data logger for a while, seeing the speeduino stuff just confirmed it.

Going to put together a speeduino for a friends M52 drift car soon. Will see how it goes as it seems to have killed off the low range megasquirt units completely. You can build one here for ~220 which is a lot of unit for not much cash.

Also, don't assume this is not totally over my head either, I'm just willing to go in with both feet and figure out the swimming bit when I know how deep the water is. Laughing
Back to top
View user's profile Send private message
 

 
Mykk



Joined: 05 Sep 2015
Posts: 96

PostPosted: Wed Nov 29, 2017 7:16 pm    Post subject: Reply with quote

https://www.youtube.com/watch?v=c_UQWqbNXgM
Back to top
View user's profile Send private message
 

 
Hairyscreech



Joined: 20 Jun 2017
Posts: 157

PostPosted: Sat Dec 02, 2017 8:09 am    Post subject: Reply with quote

Its interesting to see that several similar projects have been done before but none quite all the way to a full OBD2 compatible output.

Its looking like a lot of the work maybe figuring out where they could have been improved and then working out how to integrate them.

I ordered a canbus shield and didn't spot that it was coming from China. Doh, so that's not going to be here until January, fortunately I spotted that and ordered another in to UK at 2.5x the price which turned up today.
The mega2560 that's coming form the UK hasn't appeared yet either and I wanted to get on with it this weekend so I just stumped up the 30 for a genuine arduino from maplins.
My time this weekend is defenatly worth 30.

Also picked up the bits to make some of the signal conditioners so I will try to bang the hardware together tonight and begin coding over the next week.

It does mean I will have 80% of the bits needed to put a second one together or a spare for the 3d printer.
Back to top
View user's profile Send private message
 

 
Hairyscreech



Joined: 20 Jun 2017
Posts: 157

PostPosted: Wed Dec 06, 2017 6:37 am    Post subject: Reply with quote

Got the Mega2560 and the CANBUS shield all fitted up together and wired to the OBD2 output.

Had quite a bit of trouble getting the shield initialized, turns out the pin assignment is a little different on the arduino uno they were designed for and the Mega2560.
A bit of jumper wiring of pins 10-13 to pins 50-53 and a small change to the code got it working.

I uploaded the OBD2 simulator code I had and got a working OBD2 output from the interface.

So far so good, I have not touched it more yet as I have been updating the M3.3.1 stuff with all of the new info over the last few days,

From here it is a case of putting some code together to read the pins and output the results to the CAN shield. From looking at the sample code I used to test it it may not be too much of a difficult thing to do.

Olafu mentioned something the other day that made me wonder if I can pick up a true load signal from the auto gearbox interface, going to see if that is possible a it will be more accurate than a back calculated simulated load output.
Back to top
View user's profile Send private message
 

 
Mykk



Joined: 05 Sep 2015
Posts: 96

PostPosted: Wed Dec 06, 2017 8:09 am    Post subject: Reply with quote

Very cool stuff.

I got started on putting together my own speeduino to sit in the DME case and utilize the 88 pin connector for stock wiring harness. So far I've got the Ardiuno Mega2560 and a gutted dme. Still awaiting the Sppeduino v0.4.4 board. Once the firmware is loaded on the arduino it connects and communicates with Tunerstudio.

You could spend some time with the speeduino.ini file and Tunerstudio to give you the visual layout you want for the data logging and live gauges. No DTC's however.
Back to top
View user's profile Send private message
 

 
Evil



Joined: 18 Jul 2017
Posts: 120
Location: France

PostPosted: Wed Dec 06, 2017 11:32 am    Post subject: Reply with quote

Maybe it is possible To pick up load signal with the econometer output?
Back to top
View user's profile Send private message
 

 
Hairyscreech



Joined: 20 Jun 2017
Posts: 157

PostPosted: Thu Dec 07, 2017 12:43 am    Post subject: Reply with quote

The speeduino mates with tunerstudio the same way that the megasquirt does, not sure how that is but it won't port across to Tunerpro.

I believe I need to sort out an ADX file for tunerpro but I will cross that bridge later.

As far as I am aware the econometer output is just a square wave pulse that is based on injector pulse width and speed, possibly only pulse width as the clocks already know speed and the OBC wires through the clocks.

It is something I would like to be able to adjust actually as I like having the calculated consumption and range outputs on the E30 one.

The auto box ECU is a more likely candidate as that does actually need to know load due to the kickdown and other functions the auto box needs to be able to do.
Olafu is right though that it may need some sniffing of the connection unless I can find the info I need out there already.
I do wonder if this is active on the manual cars but the checks for the auto box are just disabled? It would make more sense than them programming two whole variants of the code and I have not heard of people needing a specific "auto" ECU.
I know the M60 auto ECU works ok in manual config but throws a trouble code/possibly limps because it cannot detect the autobox, other than that it seems to be fine which is what makes me think it is just an enable/disable checks thing.
Back to top
View user's profile Send private message
 

 
Evil



Joined: 18 Jul 2017
Posts: 120
Location: France

PostPosted: Thu Dec 07, 2017 7:02 am    Post subject: Reply with quote

Hairyscreech wrote:


As far as I am aware the econometer output is just a square wave pulse that is based on injector pulse width and speed, possibly only pulse width as the clocks already know speed and the OBC wires through the clocks.

It is something I would like to be able to adjust actually as I like having the calculated consumption and range outputs on the E30 one.


I have seen somewhere that the cluster was receiving load signal for econometer. Don't remember where, I've seen that totally accidentally when searching for something else Laughing

Moreover, speed signal comes first to the cluster and then is dispatched to "accessories" (wipers relay, DME, etc). It should be more logical for the calculation for consumption to be done in the cluster than in the DME.

But like you, it could be a good thing to adjust for me with the E85 conversion, for the moment I have a 6l/100 in cruise where I was at 8.5 with fuel Laughing Laughing
But it could be interesting to know anyway for any application.
Back to top
View user's profile Send private message
 

 
Hairyscreech



Joined: 20 Jun 2017
Posts: 157

PostPosted: Thu Dec 07, 2017 11:18 am    Post subject: Reply with quote

I am pretty sure the conversion does happen in the cluster.

I think (means I need to check) that the speed signal is sent to the cluster first and is just a pulse from the trigger at the rear, the clocks turn this into a speed pulse for the OBC and the ECU, the E30 pulses are the same as the E36 but wheel size and thus speed is different.

The quantity of fuel being used is spat out to the clocks from the ecu and the clock turn these two signals into M/G.

What I do not know is if the ECU spits out the pulse width and the clock does the pulse to volume calculation based on the coding plug or if the ECU spits out a calculated fuel quantity signal using what injector scaling we know of.
Back to top
View user's profile Send private message
 

 
olafu



Joined: 26 Jul 2016
Posts: 101
Location: Finland

PostPosted: Mon Dec 11, 2017 7:54 am    Post subject: Reply with quote

Why not to get direct data from K-line to Tunerpro? Needs some work to log RS232 data and clear it, but then we know how scan tool "asks" data from ECU.
Back to top
View user's profile Send private message
 

 
Hairyscreech



Joined: 20 Jun 2017
Posts: 157

PostPosted: Mon Dec 11, 2017 1:16 pm    Post subject: Reply with quote

I believe the serial transmission is too slow for live data.

I think it has been tried on an 8051 generation chip and they are way too slow, I don't think the 80196 is much better in that regard.

It was one of my first thoughts when I saw it had a serial port.
Back to top
View user's profile Send private message
 

 
Mykk



Joined: 05 Sep 2015
Posts: 96

PostPosted: Thu Dec 28, 2017 4:35 am    Post subject: Reply with quote

It's been brought to my attention that the M3.x.x can indeed live data from diag port. You need an old Windows xp computer with an rs232 serial port. And you need the Tiny ADS interface. Using the software DIS v39.






..however I hear the information updating is rather slow and there isn't a way to log what little information is available. But it's better then nothing. I still fully support the use of an Arduino or even a Teensy (faster processor) piggyback system for actual sensor data logging and live information.

The software package that includes DIS v39:

https://www.pss-autosoft.net/

Tiny ADS interface board only:

http://openlabs.co/store/Tiny-ADS-Interface

Tiny ADS interface in the 20pin diag connector:

http://openlabs.co/store/Tiny-ADS-Interface-inside-20-pin-connector
Back to top
View user's profile Send private message
 

 
Hairyscreech



Joined: 20 Jun 2017
Posts: 157

PostPosted: Fri Dec 29, 2017 7:41 am    Post subject: Reply with quote

Yep, that's exactly what I have from getting the E30 engine running. The data is very choppy and lags quite a bit, it could only ever be used for steady state on a dyno.

I do also doubt it's accuracy in some cases, on mine I know everything is working in spec but INPA shows somethings responding in abnormal ways on the live stream.

Trying to get some work done on this at the moment but the family requirements of the festive period are making focus a bit tricky. Exclamation
Back to top
View user's profile Send private message
 

 
Hairyscreech



Joined: 20 Jun 2017
Posts: 157

PostPosted: Sun Jan 28, 2018 12:10 pm    Post subject: Reply with quote

To bring things back to life after the Christmas hibernation we all seem to have been doing I thought I would give an update on where I have got to with this.

Before christmas I got the Arduino Mega working with the canbus shield and used the OBD2 simulator code to get it going with the OBD2 scanner.
After a bit of fiddling it worked ok with the variables that were defined in the code. I could connect and get the OBD2 scanner software to show the random values the Arduino was generating.
This was actually great progress as it proved the hardware out and meant any future issues are pure software related.

Over Christmas I started working on the code for the reading of the sensors and logging the Motronic.

Right now I have a handful of analog reads setup to read some of the sensors and I have been working on the reading of the crank sensor, this is arguably the hardest part if you want more than just the RPM of the engine.
In this case the measured actual ignition angle would be good so I have been working with some code that was originally intended to read and log the angles of the cams on a dual vanos system.
It looks like it is going to work ok for the first generation and give a reasonable ignition timing output and an accurate RPM output.
Where it will be limited is that the current code is only capable of detecting when the crank sensor signal goes high or low and thus 1/2 a crank tooth is the max accuracy, this means 3 degrees is the smallest measurable value for the ignition timing.
Not ideal but better than nothing to start with, after all the measured ignition timing is just a bonus onto of the other features.

I took a look at the Speeduino source code to see how they have done the crank sensor, I have to say the code for the speeduino is well beyond my abilities at the moment, for a future version/code update I might be able to use a similar method to the speeduino to get much greater accuracy to the ignition timing result. For now I will be happy just to get the unit working and logging so I can tune via the OBD2 outputs.

Going to start working on the rest of the code tonight, I want to get the sensor side of things set up over the next couple of weeks.
To get reliable sensor resistance values I am going to make use of the heat bed on my 3d printer, it can do very accurate temperatures so I can measure the IAT and CLT sensors anywhere from room temp to 100degC and will post the results.

As a group we will need to figure out what those resistance values correspond to in terms of voltages on the ECU pins and maybe that will help set the correct conversion factors in the XDF files.
Back to top
View user's profile Send private message
 

 
Hairyscreech



Joined: 20 Jun 2017
Posts: 157

PostPosted: Tue Jun 12, 2018 4:44 am    Post subject: Reply with quote

Wanted to put an update into this since it was looking pretty dead, I have just been a bit busy make in my car work first (you know, helps sometimes Mad )

I have been bashing away on this and now have the following bench tested and believed working:
Vanos on/off
RPM
Spark angle
Cam angle
CLT temp
Intake Air temp
MAF in Grams/sec
TPS %
Lambda as AFR or Eq Ratio
Calculated Load (as motronic 0-12.75ms and %)

Have not got the fuel rate or the Vspeed working yet but this should give me a starter, it is most of the data we need to log for tuning purposes.

Currently working out how to read all the sensors without altering the sensor output or frying the arduino or ECU.
I think I have most of the sensors worked out but i'm open to review and criticism as I am no electrical engineer.
I have seen suggestions to use some filtering or spike protection on some of the lines but to me this seems unnecessary on 5v signals direct from or to the ECU, any spike would fry the ECU so protecting the arduino A2D seems a bit secondary?

I will try to get together some circuit diagrams and pictures later today.

The Arduino Sketch and the info needed to get a canbus shield working with the ArduinoMega are in the drop box, I have tried to document the code as much as possible so if anyone wants to review it or trial if feel free however I HAVE NOT TESTED THIS ON A VEHICLE YET SO IT IS AT YOUR OWN RISK
Back to top
View user's profile Send private message
 

 
Hairyscreech



Joined: 20 Jun 2017
Posts: 157

PostPosted: Wed Jun 27, 2018 5:46 am    Post subject: Reply with quote

Another quick update.

I spent a couple of late nights on this to get the interface working with the tunerpro ADX files.
I found an ADX from a LS V8 and took a bit of time to work out how it all fitted together, the upshot of that is I was able to create a similar ADX file that connects to the ELM237 unit and sends the correct commands to the arduino to receive the data and have it display live in tunerpro.

By setting the RPM and Load to a static value in the arduino code I managed to get a few maps live tracing at the same time and the data recorder working to record an playback runs.

The ADX to do this is in the dropbox but it still fairly immature, it all seems to work but I am having some strange problems with the IAT reading "9" instead of whatever the correct value should be. This isnt an arduino issue as the OBD scantool shows the correct value, I think it may be a weird bug in tunerpro or the ADX file.

I tested the data logger on the car vs INPA and I can happily report nothing complained and the car ran fine, the MAF, IAT, CLT, TPS, Load and 02 were reading and displaying ok, the Arduino Mega was also ok about being powered directly from the 12-15v car supply (it has a built in Vreg) but I found an odd issue with fluctuating A2D reference voltage which I need to solve as it changes the analogue readings a little.

Biggest issue at the moment is I cannot get the RPM working correctly when reading the VR sensor, I am not sure if this is an issue with the hardware or arduino software but it prevents an accurate RPM output being read from the crank.
I have a work around which involves taking a signal from the ECU to Tachometer signal, the drawback is that while this will allow a simple RPM signal it does not allow the use of the fancy Crank Angle vs Cam angle or spark angle things to work.
A small loss for now as the key thing is to get this up and logging to save much work on the tuning side.

I have to go code a more simple RPM read now and hopefully we can have some M3.3.1 OBD1 data logs in the near future!

p.s. also updated the read me in the Arduino data logger dropbox folder to include the latest info.
At this stage it is safe(ish) to test provided you follow the info in that read me.
Back to top
View user's profile Send private message
 

Display posts from previous:   
View previous topic :: View next topic  
Post new topic   Reply to topic    TunerPro User Forum Forum Index -> Bosch All times are GMT - 9 Hours
 
Page 1 of 1
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
 


Powered by phpBB © 2001, 2002 phpBB Group
RedSquare theme 1.0.3 © DoubleJ(Jan Jaap)