Arduino Forum

Community => Exhibition / Gallery => Topic started by: Power_Broker on May 25, 2019, 12:32 am

Title: ELMduino - Library for Car Hacking
Post by: Power_Broker on May 25, 2019, 12:32 am
If you want to start car hacking through your OBD-II port using a bluetooth scanner - ELMduino is for you.

ELMduino download and GitHub Link (https://github.com/PowerBroker2/ELMduino)

This library is also installable via the Arduino IDE's Libraries Manager.

You can use this library to interface with OBD-II scanners such as this common one and will work with any car that has an OBD-II port:

(https://www.dhresource.com/0x0s/f2-albu-g5-M00-2E-57-rBVaJFkL34qAPWnrAAMhVPHp_gc029.jpg/new-obd-v2-1-super-mini-elm327-obd2-bluetooth.jpg)

And you can use it to query any pieces of data as specified by the OBD-II public PIDs. Here (https://en.wikipedia.org/wiki/OBD-II_PIDs) is a list of PIDs supported. Some notables include speed, rpm, MAF pressure, etc.



Below is an example code that will print rpm data from a (running) car.

Code: [Select]
#include <SoftwareSerial.h>
#include "ELMduino.h"


SoftwareSerial mySerial(2, 3); // RX, TX
#define ELM_PORT mySerial


ELM327 myELM327;


uint32_t rpm = 0;


void setup()
{
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, HIGH);

  Serial.begin(115200);
  ELM_PORT.begin(115200);

  Serial.println("Attempting to connect to ELM327...");

  if (!myELM327.begin(ELM_PORT))
  {
    Serial.println("Couldn't connect to OBD scanner");
    while (1);
  }

  Serial.println("Connected to ELM327");
}


void loop()
{
  float tempRPM = myELM327.rpm();

  if (myELM327.status == ELM_SUCCESS)
  {
    rpm = (uint32_t)tempRPM;
    Serial.print("RPM: "); Serial.println(rpm);
  }
  else
  {
    Serial.print(F("\tERROR: "));
    Serial.println(myELM327.status);
    delay(100);
  }
}



Note that you will need to connect to the bluetooth scanner using an HC-05 or other bluetooth to UART converter.

Title: Re: ELMduino - Library for Car Hacking
Post by: mppstrit on Apr 02, 2020, 07:57 pm
Hi, can do PID2102 support? PID response example 2102 (A2 F1 11 61 2 A5 80 0 6F 0 0 0 D0 E8 D0 E8 0 0 0 0 0 0 0 0 0 0 0 0 0 1 7F 0 0 0 0 0 0 8B)
Title: Re: ELMduino - Library for Car Hacking
Post by: Power_Broker on Apr 02, 2020, 08:28 pm
You can query any PID supported by the ELM327. For custom queries, take a look at this example that prints soot level:

Code: [Select]
// modified test + my custom PIDs
// based purely on library

#include "BluetoothSerial.h"
#include "ELMduino.h"


#define ELM_PORT SerialBT
#define ESP_BLUETOOTH_NAME "ESP32"


BluetoothSerial SerialBT;
ELM327 myELM327;


void setup()
{
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, HIGH);

  Serial.begin(115200);
  ELM_PORT.begin(ESP_BLUETOOTH_NAME, true);

  Serial.println("Attempting to connect to ELM327...");

  if (!ELM_PORT.connect("V-LINK"))
  {
    Serial.println("Couldn't connect to OBD scanner - Phase 1");
    while (1);
  }

  if (!myELM327.begin(ELM_PORT))
  {
    Serial.println("Couldn't connect to OBD scanner - Phase 2");
    while (1);
  }
 
  Serial.println("Connected to ELM327");
 
  for (int a = 0; a < 10; ++a)
  {
    digitalWrite(LED_BUILTIN,HIGH); delay(100);
    digitalWrite(LED_BUILTIN,LOW); delay(100);
  }
}


void loop()
{
  int32_t rpm = -1;
  int32_t soot = -1;
  int32_t burn = -1;
  float litersLeft = -1;

  /////////////////////////////////////////////////////// RPM
  float tempRPM = myELM327.rpm();
 
  Serial.print("Payload received for rpm: ");
  for (byte i = 0; i < PAYLOAD_LEN; i++)
    Serial.write(myELM327.payload[i]);
  Serial.println();
 
  if (myELM327.status == ELM_SUCCESS)
  {
    rpm = (int32_t)tempRPM;
    Serial.print("RPM: "); Serial.println(rpm);
  }
  else
      printError();

  /////////////////////////////////////////////////////// Soot
  if (myELM327.queryPID(34, 13162))
  {
    int32_t tempSoot = myELM327.findResponse();

    Serial.print("Payload received for soot: ");
    for (byte i = 0; i < PAYLOAD_LEN; i++)
      Serial.write(myELM327.payload[i]);
    Serial.println();
   
    if (myELM327.status == ELM_SUCCESS)
    {
      soot = tempSoot;
      Serial.print("Soot: "); Serial.println(soot);
    }
    else
      printError();
  }

  /////////////////////////////////////////////////////// Liters
  if (myELM327.queryPID(34, 4906))
  {
    int32_t tempLitersLeft = myELM327.findResponse() / 64.0;

    Serial.print("Payload received for liters: ");
    for (byte i = 0; i < PAYLOAD_LEN; i++)
      Serial.write(myELM327.payload[i]);
    Serial.println();

    if (myELM327.status == ELM_SUCCESS)
    {
      litersLeft = tempLitersLeft;
      Serial.print("Liters: "); Serial.println(litersLeft);
    }
    else
      printError();
  }

  /////////////////////////////////////////////////////// Burns
  if (myELM327.queryPID(34, 8434))
  {
    int32_t tempBurn = myELM327.findResponse();

    Serial.print("Payload received for DPF burns: ");
    for (byte i = 0; i < PAYLOAD_LEN; i++)
      Serial.write(myELM327.payload[i]);
    Serial.println();

    if (myELM327.status == ELM_SUCCESS)
    {
      burn = tempBurn;
      Serial.print("DPF burns: "); Serial.println(burn);
    }
    else
      printError();
  }

  for (int a = 0; a < 5; ++a)
  {
    digitalWrite(LED_BUILTIN,HIGH);
    delay(200);
    digitalWrite(LED_BUILTIN,LOW);
    delay(200);
  }
}


void printError()
{
  if (myELM327.status == ELM_SUCCESS)
    Serial.println(F("\tELM_SUCCESS"));
  else if (myELM327.status == ELM_NO_RESPONSE)
    Serial.println(F("\tERROR: ELM_NO_RESPONSE"));
  else if (myELM327.status == ELM_BUFFER_OVERFLOW)
    Serial.println(F("\tERROR: ELM_BUFFER_OVERFLOW"));
  else if (myELM327.status == ELM_GARBAGE)
    Serial.println(F("\tERROR: ELM_GARBAGE"));
  else if (myELM327.status == ELM_UNABLE_TO_CONNECT)
    Serial.println(F("\tERROR: ELM_UNABLE_TO_CONNECT"));
  else if (myELM327.status == ELM_NO_DATA)
    Serial.println(F("\tERROR: ELM_NO_DATA"));
  else if (myELM327.status == ELM_STOPPED)
    Serial.println(F("\tERROR: ELM_STOPPED"));
  else if (myELM327.status == ELM_TIMEOUT)
    Serial.println(F("\tERROR: ELM_TIMEOUT"));
  else if (myELM327.status == ELM_GENERAL_ERROR)
    Serial.println(F("\tERROR: ELM_GENERAL_ERROR"));
  }

  delay(500);
}



For more info on custom queries, you can look at this GitHub issue (https://github.com/PowerBroker2/ELMduino/issues/4).


However, that is an absolutely ridiculously long PID response. Are you sure the response is supposed to be that long? Can you provide a link to more info on this PID?

Title: Re: ELMduino - Library for Car Hacking
Post by: mppstrit on Apr 02, 2020, 08:53 pm
Code: [Select]
Name,ShortName,ModeAndPID,Equation,Min Value,Max Value,Units,Header

Температура охлаждающей жидкости,ЕСТ,2102,A/256*200-50,-40,150,C,
Температура на впуске,IAT,2102,B/256*200-50,-40,150,C,
Температура двигателя,EngTemp,210c,O/256*200-50,-40,150,C,
Положение ДЗ,TPS,2102,C/256*100,0,100,%,
Напряжение БС,Volt BS,2102,(D+1.5)/9.854,0,16,V,
Скорость,Speed,2102,E,0,256,km/h,
Обороты двигателя,RPM,2102,F*256+G,0,9000,rpm,
Требуемый ХХ,Need idle,210d,M*256+N,500,1500,rpm,
Барометрическое давление,BARO,2102,H*0.456,0,119,kPa,
Абсолютное давление,МАР,2102,J*0.456,0,119,kPa,
Массовый расход воздуха,MAF,2102,(L*256+M)/47,0,1400,mg/t,
Длительность впрыска пусковая,InjDurSt,2102,(N*256+O)/64,0,1050,ms,
Длительность впрыска текущая,InjDur,2102,(P*256+Q)/250,0,0,ms,
Коррекция длительности впрыска,Corr Inj,2102,T*256+U,0,65535,ms,
Передача МКПП,Gear,2102,V,0,6,,
Режим АКПП,AKPP,2102,W,0,256,,
Скважность продувки адсорбера,AdsFlow,2102,X/256*100,0,100,%,
Рециркуляция отработаных газов,EGR,2102,Y/256*100,0,100,%,

,,, 45 заменить на объем бака
,,,Fuel Tank,Fuel exist,2102,Z/256*45,0,45,l,
Fuel Tank%,Fuel exist,2102,Z/256*100,0,100,%,
Fuel Tank avg%,Fuel exist,210b,X*0.6,0,100,%,
Давление в системе кондиционирования,CondPres,2102,AB*12,0,3100,kPa,

Реальное положение ДЗ,RealTPS,2102,AC,0,256,steps,
Желаемое положение ДЗ,MeanTPS,2102,AE,0,256,steps,

Режим работы двигателя,Engine st,210c,AF,0,255,,
Бензонасос,FuelPump,210B,{A:0},0,1,0ff/On,
ДЗ закрыта,PSClose,210B,{I:0},0,1,0ff/On,
Кондиционер,Condit,210B,{R:0},0,1,0ff/On,
Реле низкой скор.вент.охл-я,L airfan,210B,{S:0},0,1,0ff/On,
Реле высокой скор.вент.охл-я,H airfan,210B,{T:0},0,1,0ff/On,

O2Sensor1,O2S1,2104,(C*256+B)*4.88,0,319810,mV,
O2Sensor2,O2S2,2104,(G*256+F)*4.88,0,319810,mV,
O2Sensor Heater,Heat O2S,210B,{B:0},0,1,0ff/On,
Датчик детонации,Detonate,2101,G*256+H,0,65535,mV,

УОЗ1,УОЗ1,2103,(180-A)/10,-15,15,deg,
УОЗ2,УОЗ2,2103,(180-B)/10,-15,15,deg,
УОЗ3,УОЗ3,2103,(180-C)/10,-15,15,deg,
УОЗ4,УОЗ4,2103,(180-D)/10,-15,15,deg,
Требуемый УОЗ,треб УОЗ,2103,(128-G)/10,-15,15,deg,

Краткосрочная коррекция топливоподачи,Inst Fuel Corr,2104,((S - (178*{S:7}))*256 + R)/655,-50,50,%,
Накопленная коррекция топливоподачи,Add Fuel Corr,2105,((G - (178*{G:7}))*256 + F)/655,-50,50,%,
Средняя коррекция топливоподачи,Abs Fuel Corr,2104,((W - (178*{W:7}))*256 + V)/655,-50,50,%,

Впускной коллектор переменной длины,Twin Port,210B,{Q:0},0,1,0ff/On,
полная нагрузка,FullLoad,210B,{H:0},0,1,0ff/On,
муфта гидротрансформатора АКПП,Clutch,210B,{U:0},0,1,0ff/On,
drive,drive,210c,{A:0},0,1,off/on,

Режим ХХ,EngIdle,210b,{C:0},0,1,Off/on,
Отключение подачи топлива,Inj off,210b,{G:0},0,1,Off/on,
Время с запуска двигателя,EngRunTime,2117,(I*256+J)/10,0,6553.5,sec
Положение ДЗ2,TPS2,2115,T,0,100,%


Pid 2102 contains all the parameters. Car Chevrolet Lacetti SIRIUS D42
Title: Re: ELMduino - Library for Car Hacking
Post by: Power_Broker on Apr 02, 2020, 09:02 pm
I don't speak Russian - can you provide an English internet link to a description of that PID?
Title: Re: ELMduino - Library for Car Hacking
Post by: mppstrit on Apr 02, 2020, 09:40 pm
pid2102 in my machine transmits all the data, each response byte is the data of each parameter.
Title: Re: ELMduino - Library for Car Hacking
Post by: Power_Broker on Apr 02, 2020, 09:47 pm
I don't speak Russian - can you provide an English internet link to a description of that PID?
Title: Re: ELMduino - Library for Car Hacking
Post by: mppstrit on Apr 02, 2020, 09:56 pm
Code: [Select]
Coolant temperature, EST, 2102,A/256*200-50,-40,150, C,
The temperature at the inlet,IAT,2102,B/256*200-50,-40,150,C,
Position DZ, TPS,2102,C/256*100,0,100,%,
Voltage BS, Volt BS, 2102,(D+1.5)/9.854,0,16,V,
Speed, Speed,2102,E, 0,256, km/h,
Engine speed, RPM, 2102,F*256+G, 0, 9000, rpm,
Barometric pressure, BARO,2102,H*0.456, 0, 119,kPa,
Absolute pressure, MAR, 2102, J*0.456, 0, 119, kPa,
Mass air consumption, MAF, 2102,(L*256+M)/47,0,1400, mg/t,
The duration of the injection launcher,InjDurSt,2102,(N*256+O)/64,0,1050,ms,
The duration of the injection current,InjDur,2102,(P*256+Q)/250,0,0,ms,
Correction of injection duration, Corr Inj,2102, T*256+U, 0,65535, ms,
Transmission of manual transmission, Gear, 2102, V, 0,6,,
Automatic transmission mode, AKPP,2102, W, 0,256,,
The duty cycle EVAP purge,AdsFlow,2102,X/256*100,0,100,%,
Exhaust gas recirculation, EGR,2102, Y/256*100,0,100,%,
Fuel Tank%, Fuel exist,2102,Z/256*100,0,100,%,
The pressure in the air conditioning system,CondPres,2102,AB*12,0,3100,kPa,
The real situation of the DMZ,RealTPS,2102,AC,0,256,steps,
Desired position DZ, MeanTPS,2102,AE, 0,256,steps,


links unfortunately only in Russian. this is the pid of torque
Title: Re: ELMduino - Library for Car Hacking
Post by: Power_Broker on Apr 02, 2020, 11:01 pm
Chrome can translate it for me, I want to see the link. I've never heard of a PID that returns more than one value.
Title: Re: ELMduino - Library for Car Hacking
Post by: mppstrit on Apr 07, 2020, 01:34 pm
http://arduino.ru/forum/proekty/bortovoi-kompyuter-dlya-opel-zafira?page=38
Title: Re: ELMduino - Library for Car Hacking
Post by: Power_Broker on Apr 07, 2020, 08:02 pm
As the library stands right now, the length of that response wouldn't fit inside the response buffer of the ELMduino library (max 40 bytes). Even if the entire response could fit, there's no way parse each of the individual pieces of data out of the response within the library, so you'd have to write your own parser anyway.

You can fork the library (or edit a local copy on your machine) to increase the response buffer and then write your own parser.

Basically, the standard library supports querying custom PIDs if the PID response is 40 chars long or less.

Title: Re: ELMduino - Library for Car Hacking
Post by: nieprzem on Apr 19, 2020, 05:55 pm
Hello to everybody.

First of all, thank you Power_Broker for creating such library.


I think I might use it but I need some help from more experienced users :)


I have a china ELM 327 BT device but because of the paring process I prefer to hook it up via wires.
In the device I found out the NXP TJA1040 transceiver:
https://www.nxp.com/docs/en/data-sheet/TJA1040.pdf

I would like to wire it with wemos d1 mini and now, I am not sure it this is right but I think I have to use this pins on the NXP chip. Is that right?

(https://i.imgur.com/7Tb8av2.jpg)
Title: Re: ELMduino - Library for Car Hacking
Post by: Power_Broker on Apr 19, 2020, 09:28 pm
First of all, thank you Power_Broker for creating such library.
:)  :)  :)


I would like to wire it with wemos d1 mini and now, I am not sure it this is right but I think I have to use this pins on the NXP chip. Is that right?
I've never used the Wemos D1 Mini, but if it has standard Bluetooth functionality built-in (like the ESP32s), then it would actually be a lot simpler just to use bluetooth. That being said, if you still want to hardwire your project and still use ELMduino.h, you will have to wire things up differently than you you suggest.

The chip pointed to in your pic is a CAN transceiver and not the ELM327 itself. In fact, the board in the pic doesn't have an ELM327 chip at all. ELM327s only come in dual-inline packages and the OBD interpreter on the board in your pic is a quad (bottom left hand corner with the surface removed). However, I think the OBD interpreter being used is the STN2120 (https://www.scantool.net/scantool/downloads/206/stn21xx_ds_c.pdf), which (I believe) is compatible with the ELM327 command set - meaning ELMduino.h should still work for the STN2120.

The datasheet I linked has a chip pinout on page 6. Looks like the pins you're interested in are 4 and 5.

NOTE: THE STN2120 IS A 3V3 DEVICE!!
Title: Re: ELMduino - Library for Car Hacking
Post by: nieprzem on Apr 19, 2020, 10:01 pm
Thank you for the quick response.

The chip which is on the board has 8 pins on every edge.
STN2120 from datasheet has 11 pins.

Not sure if these are the same.
Never mind, I'll have to search for the proper ELM327 device then.
Title: Re: ELMduino - Library for Car Hacking
Post by: Power_Broker on Apr 19, 2020, 10:14 pm
Oops, I should've paid more attention to the number of pins...

Good luck!
Title: Re: ELMduino - Library for Car Hacking
Post by: cabriobob on Jul 18, 2020, 03:17 pm
P_B thanks for this library.

I had problems connecting my ESP32 to my ELM327, and found out today that it didn't like to connect using the name "OBDII" (which is the correct name btw),
I had to use the MAC address.
My correct working ESP32_Bluetooth_Serial.ino is as follows:

Code: [Select]

#include "BluetoothSerial.h"
#include "ELMduino.h"


BluetoothSerial SerialBT;
#define ELM_PORT   SerialBT
#define DEBUG_PORT Serial

//String MACadd = "DC:0D:30:48:8D:60";                         //enter the ELM327 MAC address
uint8_t address[6]  = {0xDC, 0x0D, 0x30, 0x48, 0x8D, 0x60};  //enter the ELM327 MAC address after the 0x

ELM327 myELM327;


uint32_t rpm = 0;


void setup()
{
#if LED_BUILTIN
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, LOW);
#endif

  DEBUG_PORT.begin(115200);
  //SerialBT.setPin("1234");
  ELM_PORT.begin("ArduHUD", true);

  if (!ELM_PORT.connect(address))            //"OBDII" replaced by "address"
  {
    DEBUG_PORT.println("Couldn't connect to OBD scanner - Phase 1");
    while (1);
  }

  if (!myELM327.begin(ELM_PORT))
  {
    Serial.println("Couldn't connect to OBD scanner - Phase 2");
    while (1);
  }

  Serial.println("Connected to ELM327");
}


void loop()
{
  float tempRPM = myELM327.rpm();

  if (myELM327.status == ELM_SUCCESS)
  {
    rpm = (uint32_t)tempRPM;
    Serial.print("RPM: "); Serial.println(rpm);
  }
  else
  {
    printError();
  }
}


void printError()
{
  Serial.print("Received: ");
  for (byte i = 0; i < myELM327.recBytes; i++)
    Serial.write(myELM327.payload[i]);
  Serial.println();

  if (myELM327.status == ELM_SUCCESS)
    Serial.println(F("\tELM_SUCCESS"));
  else if (myELM327.status == ELM_NO_RESPONSE)
    Serial.println(F("\tERROR: ELM_NO_RESPONSE"));
  else if (myELM327.status == ELM_BUFFER_OVERFLOW)
    Serial.println(F("\tERROR: ELM_BUFFER_OVERFLOW"));
  else if (myELM327.status == ELM_UNABLE_TO_CONNECT)
    Serial.println(F("\tERROR: ELM_UNABLE_TO_CONNECT"));
  else if (myELM327.status == ELM_NO_DATA)
    Serial.println(F("\tERROR: ELM_NO_DATA"));
  else if (myELM327.status == ELM_STOPPED)
    Serial.println(F("\tERROR: ELM_STOPPED"));
  else if (myELM327.status == ELM_TIMEOUT)
    Serial.println(F("\tERROR: ELM_TIMEOUT"));
  else if (myELM327.status == ELM_TIMEOUT)
    Serial.println(F("\tERROR: ELM_GENERAL_ERROR"));

  delay(100);
}

Title: Re: ELMduino - Library for Car Hacking
Post by: cyberelectronics on Jul 24, 2020, 01:05 pm
Power_Broker, thank you for sharing this library!

I also tried the example sketch above, but I always receive the ELM_Timeout message.
In my case the connection is stable, using just "Android-Vlink" name (Vgate iCar Pro BL 4.0 https://amzn.to/3jB7NSZ ).
With the ESP32_test sketch, I'm able to send AT commands to this OBDII adapter, successfully.

Thanks for your help!

(https://i.imgur.com/rFAl317.jpg)
Title: Re: ELMduino - Library for Car Hacking
Post by: MrSkull on Aug 02, 2020, 02:26 pm
how do i use the pid code to read vehicle speed...Pid that in your github
Title: Re: ELMduino - Library for Car Hacking
Post by: Power_Broker on Aug 06, 2020, 04:19 am
There are "kph()" and "mph()" member functions available for querying vehicle speed. If you want to know what a library can and can't do, check the header file for a quick reference.
Title: Re: ELMduino - ESP32
Post by: cabriobob on Aug 22, 2020, 02:26 pm
Found out something new today regarding the ESP32,
once you've connected your ESP32 to some ELM327, and want to connect to a different ELM,
you'll have to remove the bonded ELM from the ESP32 using this code:

github link (https://github.com/espressif/arduino-esp32/pull/3219/files/8483a1280d0683f036fa2ab5c6fb44c3eb88cd4d#diff-1c3994d60420f416849fac0484fc597c), setting the "#define REMOVE_BONDED_DEVICES 0" from 0 to 1

While having done that, I could connect to a different ELM327 either by name or MAC address.
Title: Re: ELMduino - Library for Car Hacking
Post by: Power_Broker on Aug 24, 2020, 08:30 pm
Oh cool, thanks for sharing!
Title: Re: ELMduino - Library for Car Hacking
Post by: digidax on Aug 30, 2020, 11:16 am
Hi, have still posted an issue on github but hoping here are reading some more experts than me :-)

I'm using this adapter: https://www.amazon.de/Bluetooth-Diagnose-Interface-Vgate-Scanner/dp/B07537S9G9 (https://www.amazon.de/Bluetooth-Diagnose-Interface-Vgate-Scanner/dp/B07537S9G9)
Name: ELM327 Bluetooth Mini Diagnose CAN BUS Interface Auto Car PKW KFZ OBD 2 MINI Vgate Scan Tool OBD2 OBDII ELM327



Working well with Torque and I can acces it manually by sending ELM327 AT commands via Android BT serial monitor and get a propper answer.

Now, I've tried to use it with ESP32: connect by using the name ODBII - no success, then using the MAC and getting the following:

Code: [Select]

[I][BluetoothSerial.cpp:510] _init_bt(): device name set
[I][BluetoothSerial.cpp:225] esp_spp_cb(): ESP_SPP_INIT_EVT
[I][BluetoothSerial.cpp:722] connect(): master : remoteAddress
[I][BluetoothSerial.cpp:290] esp_spp_cb(): ESP_SPP_DISCOVERY_COMP_EVT
[I][BluetoothSerial.cpp:292] esp_spp_cb(): ESP_SPP_DISCOVERY_COMP_EVT: spp connect to remote
[I][BluetoothSerial.cpp:314] esp_spp_cb(): ESP_SPP_CL_INIT_EVT
[I][BluetoothSerial.cpp:298] esp_spp_cb(): ESP_SPP_OPEN_EVT Connected to ELM327
ASSERT_WARN(1 8), in lc_task.c at line 5054Received:
ERROR: ELM_TIMEOUT Received:
ERROR: ELM_TIMEOUT Received:
ERROR: ELM_TIMEOUT Received:
ERROR: ELM_TIMEOUT


The log says connected to ELM327 followed by timeouts.
Have also tried to set the serial baud rate to 9600 - no success.

Here is the code:
Code: [Select]
#include "BluetoothSerial.h"
#include "ELMduino.h"


BluetoothSerial SerialBT;
#define ELM_PORT   SerialBT
#define DEBUG_PORT Serial

// to remove bonded devices, set to 1 in normal to 0
#define REMOVE_BONDED_DEVICES 0


ELM327 myELM327;


uint32_t rpm = 0;
String name = "OBDII";

String MACadd = "23:32:17:05:88:45"; // discovered by serial BT monitor (Android)
// converted to hex
uint8_t address[6]  = {0x23, 0x32, 0x17, 0x05, 0x88, 0x45};


void setup()
{
#if LED_BUILTIN
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, LOW);
#endif

  // 115200 |
  DEBUG_PORT.begin(9600);
  SerialBT.setPin("1234");
  ELM_PORT.begin("ArduHUD", true);
 
  if (!ELM_PORT.connect(address))
  {
    DEBUG_PORT.println("Couldn't connect to OBD scanner - Phase 1");
    while(1);
  }

  if (!myELM327.begin(ELM_PORT))
  {
    Serial.println("Couldn't connect to OBD scanner - Phase 2");
    while (1);
  }

  Serial.println("Connected to ELM327");
}


void loop()
{
  float tempRPM = myELM327.rpm();

  if (myELM327.status == ELM_SUCCESS)
  {
    rpm = (uint32_t)tempRPM;
    Serial.print("RPM: "); Serial.println(rpm);
  }
  else
    printError();
}


void printError()
{
  Serial.print("Received: ");
  for (byte i = 0; i < myELM327.recBytes; i++)
    Serial.write(myELM327.payload[i]);
  Serial.println();
 
  if (myELM327.status == ELM_SUCCESS)
    Serial.println(F("\tELM_SUCCESS"));
  else if (myELM327.status == ELM_NO_RESPONSE)
    Serial.println(F("\tERROR: ELM_NO_RESPONSE"));
  else if (myELM327.status == ELM_BUFFER_OVERFLOW)
    Serial.println(F("\tERROR: ELM_BUFFER_OVERFLOW"));
  else if (myELM327.status == ELM_UNABLE_TO_CONNECT)
    Serial.println(F("\tERROR: ELM_UNABLE_TO_CONNECT"));
  else if (myELM327.status == ELM_NO_DATA)
    Serial.println(F("\tERROR: ELM_NO_DATA"));
  else if (myELM327.status == ELM_STOPPED)
    Serial.println(F("\tERROR: ELM_STOPPED"));
  else if (myELM327.status == ELM_TIMEOUT)
    Serial.println(F("\tERROR: ELM_TIMEOUT"));
  else if (myELM327.status == ELM_TIMEOUT)
    Serial.println(F("\tERROR: ELM_GENERAL_ERROR"));

  delay(100);
}



Does anyone has ideas or an useful hint please?
Thanks, Frank
Title: Re: ELMduino - Library for Car Hacking
Post by: julian2477 on Aug 31, 2020, 09:55 pm
Hello, excellent project, I hope you can help me since I can not make it work. I have bought an elm327 wifi adapter, which works fine with torque app using the ISO14430-4 protocol, i can also send you at command with telnet from the pc, on the other hand when uploading the sketch to the nodemcu (esp8266) they connect between both, but I receive error 7 or timeout, and I don't know how to continue. Please I need your help, thank you very much in advance.
Sorry bad english i'm translating with google.
Title: Re: ELMduino - Library for Car Hacking
Post by: cabriobob on Aug 31, 2020, 10:10 pm
Hi, have still posted an issue on github but hoping here are reading some more experts than me :-)

I'm using this adapter: https://www.amazon.de/Bluetooth-Diagnose-Interface-Vgate-Scanner/dp/B07537S9G9 (https://www.amazon.de/Bluetooth-Diagnose-Interface-Vgate-Scanner/dp/B07537S9G9)
Name: ELM327 Bluetooth Mini Diagnose CAN BUS Interface Auto Car PKW KFZ OBD 2 MINI Vgate Scan Tool OBD2 OBDII ELM327
The log says connected to ELM327 followed by timeouts.
Have also tried to set the serial baud rate to 9600 - no success.
I had not the same but a similar issue:
Using a Vgate iCar 2, which has the ELM327 Version 2.1 (as does yours), I could not connect to with an ESP32. not by name and not by mac address.
I switched over to a Vgate iCar pro 4.0, which functions flawlessly.
An "old" ELM327 version 1.5 also works OK.
Title: Re: ELMduino - Library for Car Hacking
Post by: julian2477 on Sep 01, 2020, 05:07 am
I had not the same but a similar issue:
Using a Vgate iCar 2, which has the ELM327 Version 2.1 (as does yours), I could not connect to with an ESP32. not by name and not by mac address.
I switched over to a Vgate iCar pro 4.0, which functions flawlessly.
An "old" ELM327 version 1.5 also works OK.

I have the elm327 v.1.5 and nodemcu but this library doesn't work for me, and doing it without it is all a complication. I was able to enter the at commands from serial, but decoding them is a lot for me. Why am I not doing elmduino, help!
Title: Re: ELMduino - Library for Car Hacking
Post by: Power_Broker on Sep 01, 2020, 08:24 pm
Please post your code and wiring diagram
Title: Re: ELMduino - Library for Car Hacking
Post by: julian2477 on Sep 06, 2020, 06:25 pm
Hello power broker, thank you very much for answering me and trying to help me, tremendous work you have done with the library, I hope to be able to use it, I have an elm327 v1.5 wifi connected to an esp8266 (nodemcu v3), and this esp8266 connected by usb to the pc from where I see the serial monitor. The code is the one you have put in the example and the error it gives me is timeout. I can connect to the elm327 from the pc via telnet without problems, as well as from the cell phone with the torque app and others. in advance thank you very much, below I leave the code used.

Code: [Select]

#include <ESP8266WiFi.h>
#include "ELMduino.h"


const char* ssid = "WiFi-OBDII";
//const char* password = "your-password";


//IP Adress of your ELM327 Dongle
IPAddress server(192, 168, 0, 10);
WiFiClient client;
ELM327 myELM327;


uint32_t rpm = 0;


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

  // Connecting to ELM327 WiFi
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid);
  // WiFi.begin(ssid, password); //Use this line if your ELM327 has a password protected WiFi

  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("Connected to Wifi");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());

  if (client.connect(server, 35000))
    Serial.println("connected");
  else
  {
    Serial.println("connection failed");
    ESP.reset();
  }

  myELM327.begin(client);
}


void loop()
{
  float tempRPM = myELM327.rpm();

  if (myELM327.status == ELM_SUCCESS)
  {
    rpm = (uint32_t)tempRPM;
    Serial.print("RPM: "); Serial.println(rpm);
  }
  else
    printError();
}


void printError()
{
  Serial.print("Received: ");
  for (byte i = 0; i < myELM327.recBytes; i++)
    Serial.write(myELM327.payload[i]);
  Serial.println();
  
  if (myELM327.status == ELM_SUCCESS)
    Serial.println(F("\tELM_SUCCESS"));
  else if (myELM327.status == ELM_NO_RESPONSE)
    Serial.println(F("\tERROR: ELM_NO_RESPONSE"));
  else if (myELM327.status == ELM_BUFFER_OVERFLOW)
    Serial.println(F("\tERROR: ELM_BUFFER_OVERFLOW"));
  else if (myELM327.status == ELM_UNABLE_TO_CONNECT)
    Serial.println(F("\tERROR: ELM_UNABLE_TO_CONNECT"));
  else if (myELM327.status == ELM_NO_DATA)
    Serial.println(F("\tERROR: ELM_NO_DATA"));
  else if (myELM327.status == ELM_STOPPED)
    Serial.println(F("\tERROR: ELM_STOPPED"));
  else if (myELM327.status == ELM_TIMEOUT)
    Serial.println(F("\tERROR: ELM_TIMEOUT"));
  else if (myELM327.status == ELM_TIMEOUT)
    Serial.println(F("\tERROR: ELM_GENERAL_ERROR"));

  delay(100);
}




On the other hand, I would like to share a code that works in the configuration I have (elm327v1.5, esp8266nodemcu and pc) so I rule out that the problem is the hardware, but this code does not bring the information as I want, it returns it without format and in hex

Code: [Select]

#include <ESP8266WiFi.h>

const char* ssid = "WiFi-OBDII";
//const char* pass = "pass";

//ip ELM327
IPAddress server(192, 168, 0, 10);

boolean last_in = false;

WiFiClient client;

void setup() {
Serial.begin(9600);
delay(10);

Serial.println("");
Serial.println("");
Serial.println("Conectando a ");
Serial.println(ssid);

WiFi.mode(WIFI_STA);
WiFi.begin(ssid);
// WiFi.begin(ssid, pass);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}

Serial.println("");
Serial.println("Conectado a Wifi");
Serial.println("Direccion IP: ");
Serial.println(WiFi.localIP());

  if (client.connect(server, 35000)) {
    Serial.println("Conectado");
    //Serial.println("<ATZ");
    // Make a Request
    //client.println("ATZ");
  }
  else {
    Serial.println("Error de conexion");
    ESP.reset();
  }
}

void loop() {
  if (!client.connected()) {
    Serial.println("");
    Serial.println("CLIENTE DESCONECTADO - RESETEANDO!");
    client.stop();
    ESP.reset();
  }

// si hay bytes entrantes disponibles desde el servidor, léalos e imprímalos:

  if (client.available()) {
    if (!last_in) {
      Serial.println("");
      Serial.print(">");
      last_in = true;
    }
    char c = client.read();
    //Serial.print("");
    //Serial.print(c, HEX);
    //Serial.println("");
    Serial.print(c);
  }

// siempre que haya bytes en la cola de serie, léalos y envíelos al socket si está abierto:

  while (Serial.available() > 0) {
    if (last_in) {
      //Serial.println("");
      //Serial.print("<< Enviando request");
      //Serial.println("");
      last_in = false;
    }
    char inChar = Serial.read();
    if (client.connected()) {
      client.print(inChar);
      Serial.println("");
    }
  }
}
Title: Re: ELMduino - Library for Car Hacking
Post by: raymurai on Oct 15, 2020, 09:03 am
Hello guys and P_B. 

First of all amazing library, thanks for that. Secondly i have a wire connection problem here. I can connect my elm327 via wifi and can get RPM and coolant temp. I'm cool with that. But I want to transfer data via wires. I have elm327 with cable too. It has data+/- pins on it. How can i use them with this library and how to connect them into my wemos' RX TX. Any help will be appreciated.


Best wishes.

Eymen
Title: Re: ELMduino - Library for Car Hacking
Post by: Power_Broker on Oct 16, 2020, 11:39 pm
Thank you for your kind compliment, I'm glad people find the lib useful.

Could you post a link to where you bought the ELM327? Maybe a pic too?

If it's USB, you'll need a USB host shield or an Arduino with built-in USB host functionality.
Title: Re: ELMduino - Library for Car Hacking
Post by: raymurai on Oct 19, 2020, 03:55 pm
https://urun.n11.com/tespit-ve-test-cihazlari/elm327-v15-kablolu-arac-ariza-tespit-cihazi-turkce-pic18f25k80-P394066613?gclsrc=aw.ds&&cid=601002&gclid=Cj0KCQjw8rT8BRCbARIsALWiOvSUlKS6Fw1F4C83ae7azSHMr1uCoLy_SA6Xjib53ugUnd4yjW4HLyYaAou0EALw_wcB (http://"http://\"https://urun.n11.com/tespit-ve-test-cihazlari/elm327-v15-kablolu-arac-ariza-tespit-cihazi-turkce-pic18f25k80-P394066613?gclsrc=aw.ds&&cid=601002&gclid=Cj0KCQjw8rT8BRCbARIsALWiOvSUlKS6Fw1F4C83ae7azSHMr1uCoLy_SA6Xjib53ugUnd4yjW4HLyYaAou0EALw_wcB"")

Sorry for foreigner link. Couldnt find any same device on globalmarkets. I want to use data+/- pin behind of it.

Can i use usb ttl to convert data for uart communication?

(https://forum.arduino.cc/index.php?action=dlattach;topic=617795.0;attach=386070)

(https://forum.arduino.cc/index.php?action=dlattach;topic=617795.0;attach=386072)
Title: Re: ELMduino - Library for Car Hacking
Post by: Power_Broker on Oct 19, 2020, 11:36 pm
Can i use usb ttl to convert data for uart communication?
No, if it's USB, you can only use a host controller to communicate with it. You can either spend $5-$15 to get a different OBDII scanner or use a host controller shield. I'd just get a bluetooth OBDII scanner (or a UART one if you can find one)
Title: Re: ELMduino - Library for Car Hacking
Post by: raymurai on Oct 20, 2020, 02:54 pm
I'd just get a bluetooth OBDII scanner (or a UART one if you can find one)
Okay, thanks for your time and information. Let me try this one.
Regards.