Go Down

Topic: ELMduino - Library for Car Hacking (Read 7380 times) previous topic - next topic

cabriobob

#15
Jul 18, 2020, 03:17 pm Last Edit: Jul 19, 2020, 10:49 am by cabriobob
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);
}


cyberelectronics

#16
Jul 24, 2020, 01:05 pm Last Edit: Jul 24, 2020, 01:36 pm by cyberelectronics
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!


MrSkull

how do i use the pid code to read vehicle speed...Pid that in your github

Power_Broker

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.
"The desire that guides me in all I do is the desire to harness the forces of nature to the service of mankind."
   - Nikola Tesla

cabriobob

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, 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.

Power_Broker

"The desire that guides me in all I do is the desire to harness the forces of nature to the service of mankind."
   - Nikola Tesla

digidax

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
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

julian2477

#22
Aug 31, 2020, 09:55 pm Last Edit: Aug 31, 2020, 10:02 pm by julian2477
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.

cabriobob

#23
Aug 31, 2020, 10:10 pm Last Edit: Aug 31, 2020, 10:11 pm by cabriobob
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
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.

julian2477

#24
Sep 01, 2020, 05:07 am Last Edit: Sep 01, 2020, 05:09 am by julian2477
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!

Power_Broker

Please post your code and wiring diagram
"The desire that guides me in all I do is the desire to harness the forces of nature to the service of mankind."
   - Nikola Tesla

julian2477

#26
Sep 06, 2020, 06:25 pm Last Edit: Sep 06, 2020, 06:28 pm by julian2477
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("");
    }
  }
}

raymurai

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

Power_Broker

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.
"The desire that guides me in all I do is the desire to harness the forces of nature to the service of mankind."
   - Nikola Tesla

raymurai

#29
Oct 19, 2020, 03:55 pm Last Edit: Oct 19, 2020, 04:01 pm by raymurai
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?




Go Up