Giter Site home page Giter Site logo

Esp32 connection about elmduino HOT 31 CLOSED

powerbroker2 avatar powerbroker2 commented on July 22, 2024
Esp32 connection

from elmduino.

Comments (31)

patfelst avatar patfelst commented on July 22, 2024 1

The name of the ELM327 device that i am using for testing is called (OBDll) .I have onother ELM327 device called "OBDll bluetooth",for simplicity i will refer to this device as NO2.

Is setting up device NO2 as easy as changing the if (!ELM_PORT.connect("OBDII")) line of code or do i have to dig deeper into the library .

I know you're not trying to optimise here but simply get your code working, but if you look at the Arduino bluetooth library, you'll see that using the OBD scanner's bluetooth MAC address is much faster than using its name (10 seconds vs up to 30 seconds). Have a look this comment. I'm using the "address" method and it works very reliably.

Also I would recommend finding out why your program was crashing, there is probably a very simple explanation, probably an issue with a string variable or a timeout not long enough. You can use this tool which is very easy to use within the Arduino IDE. It will show you the exact line of source code where the program is crashing.

from elmduino.

PowerBroker2 avatar PowerBroker2 commented on July 22, 2024 1

A separate issue for this would be better, but yes, I'm interested

from elmduino.

PowerBroker2 avatar PowerBroker2 commented on July 22, 2024

Try the ESP32_test.ino sketch again, but with the ELM327 on and present. Also ensure that no other bluetooth devices are paired with the ELM327 and that your car is on and running (with the ELM327 plugged into the car of course). If you get Connected to ELM327, type in the following commands into the serial montior (carriage return line ending selected):

AT Z
AT E0
AT S0
AT SP0
010C

Let me know what the responses for each of these commands are.

Also be aware that some people have better luck using 38400 baud instead of 115200.

from elmduino.

philo-create avatar philo-create commented on July 22, 2024

Hello again.I just followed the instructions you gave me and i didn't get any response back.so basically nothing happens and after a while the board reboots. below is a picture of what happens when i eneter the commands one after another
AT SPO

AT SPO  2

I just also want to let you know that i have tested the obd2 scanner with the torque android app and it works fine .

from elmduino.

PowerBroker2 avatar PowerBroker2 commented on July 22, 2024

2 things:

  1. What is the name of the ELM327 device when you connect to it on your Android? Is it's name "OBDII"? If not, what is it?
  2. Are you turning off your phone's bluetooth when attempting to connect to the ELM327 with your ESP32?

from elmduino.

philo-create avatar philo-create commented on July 22, 2024

The name of the ELM327 device that i am using for testing is called (OBDll) .I have onother ELM327 device called "OBDll bluetooth",for simplicity i will refer to this device as NO2.

Is setting up device NO2 as easy as changing the if (!ELM_PORT.connect("OBDII")) line of code or do i have to dig deeper into the library .

from elmduino.

PowerBroker2 avatar PowerBroker2 commented on July 22, 2024

Yes, you can simply change that line and it should work fine for the other module

from elmduino.

philo-create avatar philo-create commented on July 22, 2024

Thank you, device No2 works .it would have taken me forever to realise that changing the board rate would fix it..still dont understand why the other device doesnot work.
I might be asking for too much in the next question so i understand if you choose not to answer.
from my understanding after going through your library I kinda assume that if i want for example speed in kph i would write the code like this

 uint32_t kph = 0;

float speed = myELM327.kph();
{
if (myELM327.status == ELM_SUCCESS)
{
kph= (uint32_t)speed;
Serial.print("speed: "); Serial.println(kph);
}
else
printError();
}

How do i get fuel level ? so bassically want to know how to make use of the List of standard PIDs:?

from elmduino.

PowerBroker2 avatar PowerBroker2 commented on July 22, 2024

Yes, except I would make kph a float.

In order to use the PIDs in the list, you can do something like this:

// https://en.wikipedia.org/wiki/OBD-II_PIDs#Service_01
float fuelLevel = 0; // in %
if (myELM327.queryPID(SERVICE_01, FUEL_TANK_LEVEL_INPUT))
	fuelLevel = myELM327.findResponse() * 100.0 / 255.0;

More info here.

from elmduino.

philo-create avatar philo-create commented on July 22, 2024

Thank you. I will test everything and keep you informed

from elmduino.

philo-create avatar philo-create commented on July 22, 2024

@PowerBroker2. I have tested the following code and i have only been able to get 0 as an output

// https://en.wikipedia.org/wiki/OBD-II_PIDs#Service_01
float fuelLevel = 0; // in %
if (myELM327.queryPID(SERVICE_01, FUEL_TANK_LEVEL_INPUT))
	fuelLevel = myELM327.findResponse() * 100.0 / 255.0;

from elmduino.

PowerBroker2 avatar PowerBroker2 commented on July 22, 2024

I can't help unless you provide as much detail as possible on the context of the problem since I don't know what steps you've taken, what your physical setup is, or what your entire code looks like. Please post your entire sketch.

Also, have you verified the connection does in fact work for the example sketches? What were the responses to the manual AT commands as recommended in earlier posts?

from elmduino.

philo-create avatar philo-create commented on July 22, 2024

I tested the example schetch and it does work .The responses to the manual AT commands are.

AT Z =ELM327 V1.5
AT E0 =AT EOOK
AT S0 =OK
AT SP0 =OK
010C = 410COBDA

Below is the entire code i am using

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


BluetoothSerial SerialBT;
#define ELM_PORT   SerialBT
#define DEBUG_PORT Serial


ELM327 myELM327;


//uint32_t rpm = 0;
//const uint8_t FUEL_TANK_LEVEL_INPUT  = 47;

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

  DEBUG_PORT.begin(38400);
  //SerialBT.setPin("1234");
  ELM_PORT.begin("ArduHUD", true);
  
  Serial.println("Attempting to connect to ELM327...");
  if (!ELM_PORT.connect("OBDll bluetooth"))
  {
    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 fuelLevel = 0; // in %

if(myELM327.queryPID(SERVICE_01, FUEL_TANK_LEVEL_INPUT)){
  fuelLevel = myELM327.findResponse() * 100.0 / 255.0;
  Serial.print("FuelLevel: "); Serial.println(fuelLevel);  
  
}
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);
}

from elmduino.

PowerBroker2 avatar PowerBroker2 commented on July 22, 2024

Looks like your ELM327 is connected and responding correctly. I'm curious, if you run the test sketch again and enter 012F, what do you get as a response?

from elmduino.

philo-create avatar philo-create commented on July 22, 2024

I tested it and i got NoData as a response

from elmduino.

PowerBroker2 avatar PowerBroker2 commented on July 22, 2024

In that case, you might need to use a different PID. Check the header file/wiki page and find one that works for fuel level.

from elmduino.

patfelst avatar patfelst commented on July 22, 2024

Hey @PowerBroker2 I wrote a bit of code to query "Supported PIDs" for the vehicle, and a google spreadsheet to decode it. Would you be interested in me sharing it?

from elmduino.

maksumon avatar maksumon commented on July 22, 2024

Hello, @PowerBroker2 Thanks for the excellent library. But unfortunately, I could not manage to use it yet as it is failing to connect on phase 2. Then I tried the ESP32_test.ino, it connects but no response from the AT commands you have mentioned above.

image

This is the device I am using and it works fine with Torque and any other OBDII application. I have also made sure that no other Bluetooth device was connected to the OBDII device.

Do you know what can be the issue or should I buy and try another OBDII device?

from elmduino.

PowerBroker2 avatar PowerBroker2 commented on July 22, 2024

Sometimes there are issues with baud rates. Try using 38400 baud instead of 115200. If you still have trouble, try all other possible bauds. I've seen one case where the ELM327 only worked at 9600.

from elmduino.

maksumon avatar maksumon commented on July 22, 2024

Ow, okay, I have tried 38400 and 115200 but no luck... Tomorrow I will try all other baud rates and let you know. Thanks for the prompt reply.

from elmduino.

maksumon avatar maksumon commented on July 22, 2024

@PowerBroker2 I have tried all the baud rates from 9600 to 115200 with 2 ESP32 boards but no luck :(. I don't have any spare ELM327 device to try out.

from elmduino.

PowerBroker2 avatar PowerBroker2 commented on July 22, 2024

If it doesn't respond to manual AT commands, it probably means the ELM327 is automatically connecting to a previously paired device (i.e. whatever device you had running Torque). Make sure to do testing with NO other bluetooth devices enabled other than the ELM327 and your Arduino.

Also, someone with a similar problem was able to resolve it by following these steps.

from elmduino.

maksumon avatar maksumon commented on July 22, 2024

But no other devices were connected at the moment I was testing... I even tried to disconnect the EMP327 form the OBD port and reconnect.

I have tried with 3 different ESP32 but all cannot connect.

I will try following the steps mentioned and let you know.

Thanks

from elmduino.

maksumon avatar maksumon commented on July 22, 2024

@PowerBroker2 I tried connecting my laptop with the OBDII and it was successful. I sent the command AT Z and it printed ELM327 V2.1, is that something to do with the version of ELM327 to connect with ESP32?

from elmduino.

PowerBroker2 avatar PowerBroker2 commented on July 22, 2024

If no other bluetooth devices are enabled during testing, the car is running, and you're using the EP32_test.ino sketch and still do not get responses from the ELM327 at any baud, it might mean that the ESP32 isn't paired to the ELM327 in the first place.

This may be due to your ELM327's bluetooth name not being "OBDII". When you open your laptop and choose your ELM327 as a bluetooth device, what is the device name? Is it "OBDII"? If not, you will have to change it in the test sketch. NOTE: you can replace the device name in the test sketch with the ELM327's MAC address instead.

from elmduino.

maksumon avatar maksumon commented on July 22, 2024

@PowerBroker2 The EML327 device name is OBDII when I connect from phone and laptop

from elmduino.

PowerBroker2 avatar PowerBroker2 commented on July 22, 2024

If the test sketch doesn't work, all I can say is the problem doesn't lie with the library (the test sketch doesn't use the library at all) - the problem is elsewhere. Either it's your ELM327 or your ESP32...

from elmduino.

maksumon avatar maksumon commented on July 22, 2024

Tomorrow I will give it a try with Arduino and HC-06 and will let you know

from elmduino.

maksumon avatar maksumon commented on July 22, 2024

@PowerBroker2 I have not tried with Arduino yet but wanted to make sure, do I need to run AT commands to make HC-06 as master and bind with the ELM327?

from elmduino.

PowerBroker2 avatar PowerBroker2 commented on July 22, 2024

I'm not sure if it's possible to connect to the ELM327 with an HC-06 - I think you need an HC-05, since an HC-06 can't be used as a master. If you use an HC-05, you can follow the setup directions here to connect to your ELM327.

from elmduino.

maksumon avatar maksumon commented on July 22, 2024

@PowerBroker2 Thanks for the info brother. I will give it a try at the weekend and let you know.

from elmduino.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.