Building a low cost OBD2 ECU Simulator

Re: Building a low cost OBD2 ECU Simulator

Postby Juanko » Sun Jan 04, 2015 5:58 pm

I reset and reconnected everything, and with the elm connected reset the arduino again. this time with another result.

2015-01-04 17_50_49-COM3.png


2015-01-04 17_49_48-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 Sonnytkt » Sat Jan 10, 2015 10:58 pm

Hi Martin, first of all I would like to congratulate you for your effort and all your job, it's really great and you are have realised the exact things I always wanted to do (both the simulator and the ELM327 to arduino communication). I am experiencing the same issues Juanko does, and I still haven't found the solution to that but I can give you further details to it.
Here's what I use (dropbox links because images are quite big in order to see all details and chip names):
https://dl-web.dropbox.com/get/Camera%20Uploads/2015-01-10%2022.17.02.jpg?_subject_uid=189098255&w=AABd7TQ5iFNGMeN8jBZCmE-EmkoOQ7TokJg3ruRe23sq4A
https://dl-web.dropbox.com/get/Camera%20Uploads/2015-01-10%2022.19.31.jpg?_subject_uid=189098255&w=AACmk6Gji02PgMuWqoEAWJsiImbWvUwOxvAz-M_EfPJ-Ig
https://dl-web.dropbox.com/get/Camera%20Uploads/2015-01-10%2022.18.13.jpg?_subject_uid=189098255&w=AAArcTOtRmc3essBZhGGJ7J09P4YWrgk43bDnNsmGS5G-A
The CAN shield is an Elecfreaks one and works good.
(http://www.elecfreaks.com/wiki/index.php?title=CAN-BUS_Shield)

I have noticed that the ELM is powered both by the USB and by the car plug (12V), because it has the red LED turning ON slightly when I plug it into the laptop USB and it becomes a lot brighter when I plug it into the car OBD, i supposed it also needed that 12v power so I used a computer power source to simulate that in order to be sure it isn't create problems.
I have uploaded the code you wrote and used 2 different libraries, the one you indicated:https://github.com/yexiaobo-seeedstudio/CAN_BUS_Shield
and this one:
https://github.com/Seeed-Studio/CAN_BUS_Shield
Since the TX,RX and INT lights from the canbus shield flicker when trying to communicate and if I use other codes from examples I suppose the shields are identical (seeedstudio and elecfreaks).

EDIT: The only working library with elecfreaks shield is the second one!

That's the result of the testing with Scantool:
Image
I also tried to read fault codes, even if I know there would be none to display and I found out they are similar:
Image
I also tried to use another scantool (PCMscan) and here's what the log tells me:

[22:47:58.846] Loading PID scripts...
[22:47:58.849] Loaded 3 PID scripts.
[22:48:01.837] Opening OBD-II Connection...
[22:48:01.837] Searching for ELM interface...
[22:48:01.838] Checking COM6...
[22:48:01.997] Found ELM interface on COM6!
[22:48:02.541] OBD-II connection successful!
[22:48:02.541] Retrieving VIN...
[22:48:02.896] Detecting Vehicle Information...
[22:48:04.487] Detected 0 on-board modules.
[22:48:04.487] Finished detecting vehicle information.
[22:48:05.106] Detecting Supported PIDs...
[22:48:13.881] Invalid parameter: SAE.RPM!
[22:48:13.881] Invalid parameter: SAE.VSS!
[22:48:13.881] Invalid parameter: SAE.MAP!
[22:48:13.884] Invalid parameter: SAE.IAT!
[22:48:13.884] Invalid parameter: SAE.ECT!
[22:48:13.884] Failed to initialize OBD-II data logger! Error 703: Error: parameter list is empty.
[22:48:14.359] Invalid parameter: SAE.RPM!
[22:48:14.359] Invalid parameter: SAE.VSS!
[22:48:14.359] Invalid parameter: SAE.MAP!
[22:48:14.362] Invalid parameter: SAE.IAT!
[22:48:14.362] Invalid parameter: SAE.ECT!
[22:48:14.362] Failed to initialize OBD-II data logger! Error 703: Error: parameter list is empty.
[22:48:14.575] Invalid parameter: SAE.RPM!
[22:48:14.575] Invalid parameter: SAE.VSS!
[22:48:14.575] Invalid parameter: SAE.MAP!
[22:48:14.578] Invalid parameter: SAE.IAT!
[22:48:14.578] Invalid parameter: SAE.ECT!
[22:48:14.578] Failed to initialize OBD-II data logger! Error 703: Error: parameter list is empty.

each time I try to hit "live data" it tells me the 5 invalid parameters followed by error 703. I don't know what else to try, thank you very much for your time, I don't understand how you were able to insert those numbers into the code starting from the Wikipedia PID link, I really want to know how these things work, but I seem quite far away from it :roll:
User avatar
Sonnytkt
 
Posts: 7
Joined: Sat Jan 10, 2015 1:29 pm
Location: Targoviste, Romania

Re: Building a low cost OBD2 ECU Simulator

Postby MartinViljoen » Mon Jan 12, 2015 8:16 pm

I got to tell you I really want to help, but I jus cant understand why it works for me and not for everyone else, when I have more time I will try to figure it out.

One thing comes to mind, I think the elm327 remembers settings so it could be that my elm327 has been set to a specific setting that works which is not default on out the box elm327s

As far as figuring out how it all works and the pids I used from Wikipedia
I initially set the scanner software made by scan tool.net to monitor for i.e RPM then I just captured it in a serial monitor so when ever a device sends the rpm request I reply to it with random information in the correct format
From there it was easy as the same methodology applies to the next pid. A bit of cheating though :-)

I admit my explanations are not so good I'm good at doing stuff but don't ask me to explain :lol:
but I try.

You should first try what I just said above Monitor what a scantool sends convert some of the ID's to HEX and back to DECIMAL you will quickly see how it makes sense), once you understand and get your head around how all of it works is actually pretty simple, initially all of this stuff was very intimidating to me.
Image
User avatar
MartinViljoen
 
Posts: 110
Joined: Mon Oct 06, 2014 5:23 pm
Location: Centurion South Africa

Re: Building a low cost OBD2 ECU Simulator

Postby Juanko » Tue Mar 17, 2015 11:22 am

Hi Martin,

Still havent gotten mine to work. I was wondering instead of giving a random value for speed/rpm.. can you use a variable resistor on an input to create a value?

I am busy with a new product at work, that's if I get mine to work, will need to give it a set value for speed and rpm.. I will also need to display the value on a small lcd to verify that the unit I am working on is receiving the correct value. If we can set it up like that it would be awesome. I can also purchase such a unit from you to compensate you for your time.

Regards,

Juan
Juanko
 
Posts: 7
Joined: Thu Jan 01, 2015 8:03 pm

Re: Building a low cost OBD2 ECU Simulator

Postby MartinViljoen » Tue Mar 17, 2015 3:09 pm

Juanko wrote:Hi Martin,

Still havent gotten mine to work. I was wondering instead of giving a random value for speed/rpm.. can you use a variable resistor on an input to create a value?

I am busy with a new product at work, that's if I get mine to work, will need to give it a set value for speed and rpm.. I will also need to display the value on a small lcd to verify that the unit I am working on is receiving the correct value. If we can set it up like that it would be awesome. I can also purchase such a unit from you to compensate you for your time.

Regards,

Juan


Hi Juan.
You can use a variable resistor to "Generate" an RPM or Speed value (Thats what they do with the freematics unit)
Let me have a go at it, I will set it up tonight, and display it to LCD (Thats If the LCD Shield's pins are not conflicting with the CAN-BUS Shield)

I will try and let you know
Image
User avatar
MartinViljoen
 
Posts: 110
Joined: Mon Oct 06, 2014 5:23 pm
Location: Centurion South Africa

Re: Building a low cost OBD2 ECU Simulator

Postby MartinViljoen » Tue Mar 17, 2015 8:42 pm

Hi Juan.

I think this is what you want to do.

I couldn't find a variable resistor, So instead I used the UP/Down buttons on the LCD to increase/decrease the RPM and Speed Factor.
Also made it so when Pressing Left & Right It selects the PID to be changed.

I uploaded a video to my YouTube Channel for you.

https://www.youtube.com/watch?v=_Gop8Tm ... e=youtu.be

Excuse the bad quality, for some reason my internet speed is a bit slow tonight, So i compressed the video a bit too much.
Image
User avatar
MartinViljoen
 
Posts: 110
Joined: Mon Oct 06, 2014 5:23 pm
Location: Centurion South Africa

Re: Building a low cost OBD2 ECU Simulator

Postby Juanko » Wed Mar 18, 2015 4:36 pm

Sorry for the late reply, been hectic last couple of days... That is awesome.. and more or less what I am looking for.. The reason I asked for a variable resistor is because I already have a "jig" that I want to put this simulator in, You can see the 4 holes is for the resistors, the buttons and lights I want to use as MIL event triggers. The space left bottom is for an 1.8 inch tft lcd, that I want to display the reading as and Mil events.
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 » Wed Mar 18, 2015 5:33 pm

Thats realy cool.

When i have a moment i will send you the arduino code, in the meantime google on how to generate a value in between 1 and 230 with a variable resistor, if you want im might be able to get your arduino and cb shield running remotly.
Image
User avatar
MartinViljoen
 
Posts: 110
Joined: Mon Oct 06, 2014 5:23 pm
Location: Centurion South Africa

Re: Building a low cost OBD2 ECU Simulator

Postby Juanko » Thu Mar 19, 2015 9:35 pm

Had a look at the variable resistor online... your help would really be appretiated Martin... the navara's fuel tank is taking strain with driving round testing obd2 units the whole day. I am bases in Irene.. or wecan try the remote help. Regards, Juan
Juanko
 
Posts: 7
Joined: Thu Jan 01, 2015 8:03 pm

Re: Building a low cost OBD2 ECU Simulator

Postby MartinViljoen » Thu Mar 19, 2015 9:56 pm

AIts really easy to read a variable resistor,

Take the variable resistor, one outer leg goes to GND, the other outer leg goes to 5V and the middle to Analog pin 0.

The Code
Code: Select all


int potpin = 0;  // analog pin used to connect the potentiometer
int val;    // variable to read the value from the analog pin
 
void setup()
{
  Serial.begin(38400);
}
 
void loop()
{
  val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)
  val = map(val, 0, 1023, 1, 229);     // scale it to use it with the simulator (value between 1 and 230)
  Serial.println(val);
  delay(15);                           // waits for the servo to get there
}



It will constantly print the value to the serial and change as you change the value of the variable resistor.

By the Way, the code for the Simulator. (Before you attempt the below try get the variable resistor to work)

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"
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
char rndRPM=10;
char rndSpeed=10;

int ReadButtonPress;
int MenuID=1;
int NewMenuID=1;
int RPMFactor=10;
int CalculateRPM=10;
int SpeedFactor=10;
int CalculateSpeed=10;

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);
  //SETUP LCD
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.setCursor(0,0);
  lcd.print("OBD2 Simulator.");
  INITScreen();
  lcd.setCursor(0,1);
  lcd.print("0                  ");
 
  delay(2000);
 
 
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(103);
        goto START_INIT;
    }
}


void loop()
{

  if(MenuID!=NewMenuID){lcd.setCursor(0,1);lcd.print("Press Up or Down to begin");NewMenuID=MenuID;}
 
 
  //MenuNavigation
  ReadButtonPress = analogRead (0);
  if (ReadButtonPress > 800 and ReadButtonPress < 820){}//Select
  if (ReadButtonPress > 620 and ReadButtonPress < 630){if(MenuID>=2){MenuID=MenuID-1;}}//Left

 
  if (ReadButtonPress > -10 and ReadButtonPress < 10){if(MenuID<=1){MenuID=MenuID+1;}}//Right
 
 
  //When Down Button Was pressed Decrease Factors
  if (ReadButtonPress > 400 and ReadButtonPress < 415)
  {
    if(MenuID==1)//RPM
    {
    CalculateRPM=(RPMFactor*256)/4;
    if(RPMFactor>=10){RPMFactor=RPMFactor-1;}lcd.setCursor(0,1);lcd.print(CalculateRPM-64);lcd.print("                         ");
    }
    if(MenuID==2)//SPEED
    {
    CalculateSpeed=SpeedFactor;
    if(SpeedFactor>10){SpeedFactor=SpeedFactor-1;}lcd.setCursor(0,1);lcd.print(CalculateSpeed-1);lcd.print("                   ");
    }   
  }
  //When UP Button Was pressed Decrease Factors
  if (ReadButtonPress > 190 and ReadButtonPress < 215)
  {
    if(MenuID==1)
    {
    CalculateRPM=(RPMFactor*256)/4;
    if(RPMFactor<=230){RPMFactor=RPMFactor+1;}lcd.setCursor(0,1);lcd.print(CalculateRPM+64);lcd.print("                          ");   
    }
    if(MenuID==2)//SPEED
    {
    CalculateSpeed=SpeedFactor;
    if(SpeedFactor<230){SpeedFactor=SpeedFactor+1;}lcd.setCursor(0,1);lcd.print(CalculateSpeed+1);lcd.print("                     ");
    }     
  } 
   
    if(MenuID==1){lcd.setCursor(0,0);lcd.print ("RPM Output              ");}
    if(MenuID==2){lcd.setCursor(0,0);lcd.print ("Speed Output            ");}
 
 
 
 


 
    char rndCoolantTemp=random(1,200);
   
    /*
    if(rndRPM<=100)
    {
      rndRPM++;
    }
    else
    {
      rndRPM=13;
    }
    */
   

    rndRPM=RPMFactor;
    rndSpeed=SpeedFactor;
    char rndIAT=random(0,255);
    char rndMAF=random(0,255);
    char rndAmbientAirTemp=random(0,200);
    char rndCAT1Temp=random(100,110);
    char rndEGT1 = 103;
   
    //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, 0, 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};
    unsigned char EGT1[7] =               {4, 65, 120, 01, 19, 20, 0};

    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);}
        if(BuildMessage=="2,1,120,0,0,0,0,0,"){CAN.sendMsgBuf(0x7E8, 0, 7,EGT1); }
   
        BuildMessage="";

       

    }
   

   
   
   

   
 
}

void INITScreen()
{
  lcd.setCursor(0,0);
  lcd.print("OBD2 Simulator.");
  delay(500);
   lcd.setCursor(0,0);
  lcd.print("OBD2 Simulator..");
  delay(500);
   lcd.setCursor(0,0);
  lcd.print("OBD2 Simulator...");
  delay(500);
   lcd.setCursor(0,0);
  lcd.print("OBD2 Simulator....");
  delay(500);
   lcd.setCursor(0,0);
  lcd.print("OBD2 Simulator.....");
  delay(500);
   lcd.setCursor(0,0);
  lcd.print("OBD2 Simulator......");
  delay(1000);
  lcd.setCursor(0,0);
  lcd.print("Welcome!             ");
  delay(1000);
 


Image
User avatar
MartinViljoen
 
Posts: 110
Joined: Mon Oct 06, 2014 5:23 pm
Location: Centurion South Africa

PreviousNext

Return to OBD2 & CAN-BUS Projects

Who is online

Users browsing this forum: No registered users and 1 guest

cron