Building a low cost OBD2 ECU Simulator

Building a low cost OBD2 ECU Simulator

Postby MartinViljoen » Mon Oct 06, 2014 6:14 pm

I was working on an Arduino project to build an OBD2 Scanner to display vehicle readouts on a 16X2 LCD screen.
Before i could do all this i needed to figure out how to translate data read from the OBD2 port to readable/valid values.

So obviously I'm sitting in my study in the house and when ever i need to test i had to keep going to the vehicle only to find there is something small i needed to change, then having haul the whole breadboard with delicate wires all over the place between the house and the car got a bit much, so i put the project on hold to first build an OBD2 Simulator.

If you dont know already OBD2 Simulators can cost up to R10 000, The lowest prices I've seen cost about R1800 , Didn't bargain on that and actually managed to build one my self.
And if you really wanted to you can actually build an OBD2 simulator that does what the R10 000 version does and more!!!! It just shows you how you can get ripped off!!!!

2 Most important things you need - For the rest use common sense.

Arduino UNO

1.JPG

Note the double sided mirror tape on the Arduino's USB port.


SeeedStudio CAN-BUS shield

2.JPG


CAN-BUS Shield Stacked on top of the Arduino

3.JPG


I stuck the doublesided mirror tape onto the USB port so that the button pins of the DB9 connector on the CAN-BUS shield doesn't short out on the USB port.

The 2 wires connected to the green screw terminal marked CAN-H and CAN-L on the CAN-BUS Shield is actually physically connected to the DB9 port via the tracks on the board.
So you can also use the DB9 port, for me it was easier to use the screw terminal.

And that's about it as far as the hardware goes the rest is just programming the Arduino to read and dump the data to the serial port of the Arduino which you can then read with another device such a PC another Arduino or OBD2 Scanner (ELM327) ect ect.

The Arduino Code.
Code: Select all
//This Arduino UNO Sketch requires the Seeed CAN-BUS Shield Libraries
//https://github.com/yexiaobo-seeedstudio/CAN_BUS_Shield
#include <SPI.h>
#include "mcp_can.h"



INT32U canId = 0x000;

//2024   4   65   12   18   248   185   147
 

unsigned char len = 0;
unsigned char buf[8];
char str[20];

String BuildMessage="";
int MSGIdentifier=0;

void setup()
{
    Serial.begin(38400);

START_INIT:

    if(CAN_OK == CAN.begin(CAN_500KBPS))
    {
        Serial.println("CAN BUS Shield init ok!");
    }
    else
    {
        Serial.println("CAN BUS Shield init fail");
        Serial.println("Init CAN BUS Shield again");
        delay(100);
        goto START_INIT;
    }
}


void loop()
{
    char rndCoolantTemp=random(1,200);
    char rndRPM=random(1,55);
    char rndSpeed=random(0,255);
    char rndIAT=random(0,255);
    char rndMAF=random(0,255);
    char rndAmbientAirTemp=random(0,200);
    char rndCAT1Temp=random(1,55);
   
    //GENERAL ROUTINE
    unsigned char SupportedPID[8] =       {1,2,3,4,5,6,7,8};
    unsigned char MilCleared[7] =         {4, 65, 63, 34, 224, 185, 147};
   
    //SENSORS
    unsigned char CoolantTemp[7] =        {4, 65, 5, rndCoolantTemp, 0, 185, 147}; 
    unsigned char rpm[7] =                {4, 65, 12, rndRPM, 224, 185, 147};
    unsigned char vspeed[7] =             {4, 65, 13, rndSpeed, 224, 185, 147};
    unsigned char IATSensor[7] =          {4, 65, 15, rndIAT, 0, 185, 147};
    unsigned char MAFSensor[7] =          {4, 65, 16, rndMAF, 0, 185, 147};
    unsigned char AmbientAirTemp[7] =     {4, 65, 70, rndAmbientAirTemp, 0, 185, 147};
    unsigned char CAT1Temp[7] =           {4, 65, 60, rndCAT1Temp, 224, 185, 147};
    unsigned char CAT2Temp[7] =           {4, 65, 61, rndCAT1Temp, 224, 185, 147};
    unsigned char CAT3Temp[7] =           {4, 65, 62, rndCAT1Temp, 224, 185, 147};
    unsigned char CAT4Temp[7] =           {4, 65, 63, rndCAT1Temp, 224, 185, 147};
   
    if(CAN_MSGAVAIL == CAN.checkReceive()) 
    {
     
      CAN.readMsgBuf(&len, buf);
        canId = CAN.getCanId();
        Serial.print("<");Serial.print(canId);Serial.print(",");

        for(int i = 0; i<len; i++)
        { 
          BuildMessage = BuildMessage + buf[i] + ",";
        }
        Serial.println(BuildMessage);
       
        //Check wich message was received.
        if(BuildMessage=="2,1,0,0,0,0,0,0,") {CAN.sendMsgBuf(0x7E8, 0, 8, SupportedPID);}
        if(BuildMessage=="2,1,1,0,0,0,0,0,") {CAN.sendMsgBuf(0x7E8, 0, 7, MilCleared);}
       
        //SEND SENSOR STATUSES
        if(BuildMessage=="2,1,5,0,0,0,0,0,") {CAN.sendMsgBuf(0x7E8, 0, 7, CoolantTemp);}
        if(BuildMessage=="2,1,12,0,0,0,0,0,"){CAN.sendMsgBuf(0x7E8, 0, 7, rpm);}
        if(BuildMessage=="2,1,13,0,0,0,0,0,"){CAN.sendMsgBuf(0x7E8, 0, 7, vspeed);}
        if(BuildMessage=="2,1,15,0,0,0,0,0,"){CAN.sendMsgBuf(0x7E8, 0, 7, IATSensor);}
        if(BuildMessage=="2,1,16,0,0,0,0,0,"){CAN.sendMsgBuf(0x7E8, 0, 7, MAFSensor);}
        if(BuildMessage=="2,1,70,0,0,0,0,0,"){CAN.sendMsgBuf(0x7E8, 0, 7, AmbientAirTemp);}
        if(BuildMessage=="2,1,60,0,0,0,0,0,"){CAN.sendMsgBuf(0x7E8, 0, 7, CAT1Temp);}
        if(BuildMessage=="2,1,61,0,0,0,0,0,"){CAN.sendMsgBuf(0x7E8, 0, 7, CAT2Temp);}
        if(BuildMessage=="2,1,62,0,0,0,0,0,"){CAN.sendMsgBuf(0x7E8, 0, 7, CAT3Temp);}
        if(BuildMessage=="2,1,63,0,0,0,0,0,"){CAN.sendMsgBuf(0x7E8, 0, 7, CAT4Temp);}

        BuildMessage="";

       

    }
   

}


Once you have programmed it its waiting for OBD2 request from OBD2 Diagnostic Scanners and will respond as soon as a valid request was sent.
Is sends the following values.

Coolant Temperature in on Celsius
RPM
Vehicle Speed
Intake Air Temperature
MAF Value
Ambient Air Temperature
Catalytic converter Sensor1
Catalytic converter Sensor2
Catalytic converter Sensor3
Catalytic converter Sensor4]

These are all industry standard diagnostics information and you can add more if you like.
See them on http://en.wikipedia.org/wiki/OBD-II_PIDs

The values are randomized so when it send for argument sakes RPM it will be very erratic, the idea is to just get random data to work with.

You can test this by downloading free to use OBD2 Scan Tool Software from http://www.scantool.net/software/

Below is how i hooked it up with an ELM327 based OBD2 Scanner.

1photo 4.jpg


I modified my ELM327 slightly, i took a male to female USB extenter and cut it in half so that i can join the one end of the USB cable to PIN6 and PIN14 inside of the ELM327 scanner.
(Not all vehicles use the same pins as my Jeep Wrangler Rubicon, you will probably find all Chrysler use the same pins, but rather search for your self.)

Below is the Pin-Out of the Plug you find in most cars produced after 1996 (Female)

OBD2plug.png


The Arduino+CAN-BUS Setup from the green screw terminal CAN-H to PIN 6 on the above diagram.
The Arduino+CAN-BUS Setup from the green screw terminal CAN-L to PIN 14 on the above diagram.

To have a clean connection ,Its better to take a MALE OBD2 Connector with Wire connected to a DB9 Female connector so you can hook up the Arduino+CAN-BUS shield to an OBD2 scanner.

Generally a CAN-BUS system in your vehicle has been designed to withstand noise generated by the electronics and the vehicle's engine so its quite a robust system, BUT STILL!

A screenshot of the data I was able to read.

Scantool.png


208 km/h @ 696 RPM - YOU WISH!!!!! :mrgreen: :mrgreen: :mrgreen:

Enjoy!!!

Comments Please!
You do not have the required permissions to view the files attached to this post.
Image
User avatar
MartinViljoen
 
Posts: 109
Joined: Mon Oct 06, 2014 5:23 pm
Location: Centurion South Africa

Re: Building a low cost OBD2 ECU Simulator

Postby euphoriadamage » Fri Dec 12, 2014 8:36 pm

Greetings,

Your project is awesome. I am trying to make things work with the sparkfun shield. Do I have to modify something in the code to make it work? Because it seems I cant establish any short of connection.. CAN L and CAN H from the shield go directly to the ELM 327 pins or in the corresponding OBD plug pins?

Many thanks in advance and keep up the good work
euphoriadamage
 
Posts: 1
Joined: Wed Dec 10, 2014 12:56 pm

Re: Building a low cost OBD2 ECU Simulator

Postby Juanko » Thu Jan 01, 2015 8:25 pm

Very cool project indeed. I am wondering if you can also simulate mil events and trouble codes? Can you please get in contact with me Martin.
Juanko
 
Posts: 7
Joined: Thu Jan 01, 2015 8:03 pm

Re: Building a low cost OBD2 ECU Simulator

Postby MartinViljoen » Sat Jan 03, 2015 1:52 pm

Juanko wrote:Very cool project indeed. I am wondering if you can also simulate mil events and trouble codes? Can you please get in contact with me Martin.



Hi I think you could, cant be that hard, the obd2 wiki page does mention something about it, i could try it out if you want me to
Image
User avatar
MartinViljoen
 
Posts: 109
Joined: Mon Oct 06, 2014 5:23 pm
Location: Centurion South Africa

Re: Building a low cost OBD2 ECU Simulator

Postby Juanko » Sun Jan 04, 2015 10:49 am

If you can Martin that would be awesome. I bought an obd shield at communica, which they assured it was the same as the seeeduino one, coz places are still closed and couldnt find an original one on short notice. The cide runs and the int lights comes on when connected to scantool. But then scantool says its not connected to an obd device. It looks almost the same as your shield. http://www.communica.co.za/Catalog/Details/P1865739722

Can you please have a look and tell me if it will work. I really appreciate your help.
Juanko
 
Posts: 7
Joined: Thu Jan 01, 2015 8:03 pm

Re: Building a low cost OBD2 ECU Simulator

Postby MartinViljoen » Sun Jan 04, 2015 3:26 pm

The one you bought should work fine,

Does the arduino sketch which i made compile without errors?
When you say the scan tool is complaining it cant read the obd2 device , how are you connecting to it?

You cant connect the scantool directly to the arduino and canbus shield to read simulated values.
You have to connect the scantool to an elm327 device then connect the eml327 to the arduino and can bus shield like you would in the real world, the arduino and cb shield then becomes the car.


If you connect the scantool directly to the arduino And cb shield then you are using it as scan device to read from a vehicle, which is possible to do, but you need to have an obd2 reader sketch loaded.
Image
User avatar
MartinViljoen
 
Posts: 109
Joined: Mon Oct 06, 2014 5:23 pm
Location: Centurion South Africa

Re: Building a low cost OBD2 ECU Simulator

Postby Juanko » Sun Jan 04, 2015 4:59 pm

The code you provided works perfectly and compiles without any errors. When I start the serial monitor it shows me : CAN BUS Shield init ok!

I am connecting through a usb elm327 device which works perfectly in my navara. When connecting the elm327 to my scantool, I can read sensor data 100%.

When I connect the elm327 to the can shield, I get the 2nd image. Scantool says connected to device, but the gives an error.

2015-01-04 16_51_34-COM3.png


2015-01-04 16_50_30-ScanTool.net 1.20.png
You do not have the required permissions to view the files attached to this post.
Juanko
 
Posts: 7
Joined: Thu Jan 01, 2015 8:03 pm

Re: Building a low cost OBD2 ECU Simulator

Postby MartinViljoen » Sun Jan 04, 2015 5:17 pm

Ok I now see what you mean, I quickly tried it and i'm able to produce the same error.

It means its connected to the ELM327 but the ELM327 is not getting data back from the Arduino and CAN-BUS shield,
I'm quickly hooking up the Arduino and my Seedstudio shield to see if there isnt maybe an error in the code i posted.

I noticed your Serial monitor returned 2015, which is 7dF in hex , 7DF is actually an OBD2 addressed message which was returned from the shield to the ELM
Will reply in a few moments
Image
User avatar
MartinViljoen
 
Posts: 109
Joined: Mon Oct 06, 2014 5:23 pm
Location: Centurion South Africa

Re: Building a low cost OBD2 ECU Simulator

Postby MartinViljoen » Sun Jan 04, 2015 5:36 pm

I hooked it up and its working just fine, I'm confused :x

Untitled.png


It seems like some data is going missing.
2015: 2,1,12,0,0,0,0,0, is the request for RPM
You arduino is only showing 2015

You can try to disconnect the arduino from the ELM327

Reboot both the ELM327 and Arduino , then connect the Arduino to pin 6 & 14 on the ELM327 after that start the Scan tool.
You do not have the required permissions to view the files attached to this post.
Image
User avatar
MartinViljoen
 
Posts: 109
Joined: Mon Oct 06, 2014 5:23 pm
Location: Centurion South Africa

Re: Building a low cost OBD2 ECU Simulator

Postby MartinViljoen » Sun Jan 04, 2015 5:40 pm

On another note.

You should only see
Enter setting mode success
set rate success!!
Enter Normal Mode Success!!
CAN BUS Shield init ok!


Once if it repeats without you pressing the arduino's reset button means that it restarted the serial connection, The code does not restart the serial connection
Image
User avatar
MartinViljoen
 
Posts: 109
Joined: Mon Oct 06, 2014 5:23 pm
Location: Centurion South Africa

Next

Return to OBD2 & CAN-BUS Projects

Who is online

Users browsing this forum: No registered users and 1 guest

cron