Comments (18)
Hi, today it happened the breakthrough! It works.
What I had to do, is use from examples the bt_remove_paired_devices sketch and change #define REMOVE_BONDED_DEVICES 0 to 1.
Thank you for your help!
from elmduino.
Please post your entire code (in tags) and a description of your physical setup. Also, please ensure all other bluetooth devices are either disabled or turned off, ensure your car is on and running, and be sure to try all other baud rates
from elmduino.
Hi, here is my code (esp32_bluetooth_serial):
#include "BluetoothSerial.h"
#include "ELMduino.h"
BluetoothSerial SerialBT;
#define ELM_PORT SerialBT
#define DEBUG_PORT Serial
ELM327 myELM327;
uint32_t rpm = 0;
uint16_t BaudRate=115200;
//uint16_t BaudRate=38400;
uint16_t payloadLen=40;
/*
* * Protocol - Description
* 0 - Automatic
* 1 - SAE J1850 PWM (41.6 kbaud)
* 2 - SAE J1850 PWM (10.4 kbaud)
* 3 - ISO 9141-2 (5 baud init)
* 4 - ISO 14230-4 KWP (5 baud init)
* 5 - ISO 14230-4 KWP (fast init)
* 6 - ISO 15765-4 CAN (11 bit ID, 500 kbaud)
* 7 - ISO 15765-4 CAN (29 bit ID, 500 kbaud)
* 8 - ISO 15765-4 CAN (11 bit ID, 250 kbaud)
* 9 - ISO 15765-4 CAN (29 bit ID, 250 kbaud)
* A - SAE J1939 CAN (29 bit ID, 250* kbaud)
* B - User1 CAN (11* bit ID, 125* kbaud)
* C - User2 CAN (11* bit ID, 50* kbaud)
*/
char protocol='5';
void setup()
{
#if LED_BUILTIN
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
#endif
DEBUG_PORT.begin(BaudRate);
SerialBT.setPin("1234");
ELM_PORT.begin("ArduHUD", true);
if (!ELM_PORT.connect("OBDII")) //or "00-00-00-11-11-11" or "00:00:00:11:11:11"
{
DEBUG_PORT.println("Couldn't connect to OBD scanner - Phase 1");
while(1);
}
//myELM327.initializeELM(protocol);
if (!myELM327.begin(ELM_PORT, ISO_14320_FAST_INIT /*or protocol */, payloadLen ))
{
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);
}
I plugged the ELM327 in my car OBDII connector, and turned on the engine
I downloaded this code above on a esp32 wroom, and then press the en button on esp32 to reset the microcontroller.
I turned off all my bluetooth devices, but i'm parking on the street, so i can't be sure, there isn't available other bluetooth devices
I watch the esp32 microcontroller through my laptop's serial monitor, and the result is: "Couldn't connect to OBD scanner - Phase 2"
My car's protocol: ISO 14230-4 KWP (fast init). (I tried the elm327 with an Android app and that showed me this.)
I tried with 115200 and 38400 baudrates too.
Thank you for your help!
from elmduino.
Try commenting out SerialBT.setPin("1234");
and using protocol 0
from elmduino.
I already tried these I'am afraid :(
from elmduino.
What's your make/model of your car? Also, can you confirm you've taken care of the following?:
Also, please ensure all other bluetooth devices are either disabled or turned off, ensure your car is on and running, and be sure to try all other baud rates
from elmduino.
peugeot 206 sw cool look - 1.6 HDI diesel - 2005
Alright, tomorrow i'll try find a place, where no other bluetooth devices are available.
Yes the engine was running, while i'm trying to get the data.
I tried only 115200 and 38400 baudrates, what else are you provide?
from elmduino.
peugeot 206 sw cool look - 1.6 HDI diesel - 2005
I can't guarantee this lib will work for any vehicles produced earlier than 2008
I tried only 115200 and 38400 baudrates, what else are you provide?
All other bauds
from elmduino.
What is the difference between the cars produced before and after 2008, if they use the same protocol? Can you give me a hint? I want to succed this project.
from elmduino.
what I can't understand, that if I run the esp32_test.ino file (from the examples),
i get on the serial monitor: "Couldn't connect to OBD scanner", soo ELM_PORT.connect("OBII") return with false
if (!ELM_PORT.connect("OBDII"))
{
DEBUG_PORT.println("Couldn't connect to OBD scanner");
while(1);
}
BUT if i run the ESP32_Bluetooth_serial.ino
i get: "Couldn't connect to OBD scanner - Phase 2"
which is after that ELM_PORT.connect("OBDII") returns with true
if (!ELM_PORT.connect("OBDII"))
{
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);
}
what could be different? (same baudrate115200, engine turned on, all bluetooth are off)
from elmduino.
What is the difference between the cars produced before and after 2008, if they use the same protocol? Can you give me a hint? I want to succed this project.
From what I've read, 2008 was the first year the OBDII protocol was made standard on all cars in the US/EU (I do believe some locations/manufacturers adopted it earlier, though). It's because of this that I can't guarantee the lib will work with earlier cars.
The behavior in your last post is definitely odd. Are you sure the BT name of your ELM327 is "OBDII"? Can you check the name with your phone/laptop?
Last ditch effort: Try this sketch:
#include "BluetoothSerial.h"
BluetoothSerial SerialBT;
#define DEBUG_PORT Serial
#define ELM_PORT SerialBT
void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);
DEBUG_PORT.begin(115200);
//ELM_PORT.setPin("1234");
ELM_PORT.begin("ESP32test", true);
DEBUG_PORT.println("Attempting to connect to ELM327...");
ELM_PORT.connect("OBDII");
DEBUG_PORT.println("Connected to ELM327");
DEBUG_PORT.println("Ensure your serial monitor line ending is set to 'Carriage Return'");
DEBUG_PORT.println("Type and send commands/queries to your ELM327 through the serial monitor");
DEBUG_PORT.println();
}
void loop()
{
if(DEBUG_PORT.available())
{
char c = DEBUG_PORT.read();
DEBUG_PORT.write(c);
ELM_PORT.write(c);
}
if(ELM_PORT.available())
{
char c = ELM_PORT.read();
if(c == '>')
DEBUG_PORT.println();
DEBUG_PORT.write(c);
}
}
And input the following into the serial monitor:
AT Z
AT E0
AT S0
AT AL
AT TP A0
Lastly, post exactly what the Arduino responds with and we can see what's going on.
from elmduino.
Atleast i get this answer with your last sent code, but I'm not sure I wrote the code in the serial monitor precisely.
This is the right way?( i set line ending to carriage return )
AT(space)Z(enter)
AT(space)E0(enter)....and so on?
Otherwise I found this table for my car type:
Do you know what do this codes mean?
from elmduino.
A new twist today, I downloaded the OBD Auto Doctor software and with my laptop connected to the elm327, it works perfectly.
So i don't really understand, what could be wrong with the esp32.
I attached the whole obd commands/answer log, but from that it's clear, that the issue is with esp32... :(
from elmduino.
I attached the whole obd commands/answer log, but from that it's clear, that the issue is with esp32... :(
This might be because the ELM327's Bluetooth device name is not "OBDII" - can you check this?
from elmduino.
On laptop and on mobile the ELM327's name is OBDII as well, and I paired with that, before i started OBD Auto Doctor.
Tomorrow i'll check with MAC_Address, and pray...
from elmduino.
Are you sure your ELM327 is classic bluetooth and not BLE?
from elmduino.
Well I'm not, I would never say elm327 uses BLE. I check this! However my laptop is kinda old, I'm not certain it supports BLE
from elmduino.
@adamkovari, Can you post your Code that Worked? I have the same problem but your solution didn't worked for me!
Thanks
from elmduino.
Related Issues (20)
- PID 70: Boost pressure control (Service 01) HOT 1
- Problem with flashing RPM value on OLED when using latest version of ELMduino HOT 8
- ESP32 not connecting to ELM327 HOT 5
- Protocol Data Point HOT 4
- Couldn't connect to OBD scanner (stucked) HOT 18
- First time Bluetooth pairing between ESP32 and ELM327 HOT 1
- custom pid for DPF HOT 17
- BT Pairing problem between ESP-32 and ELM327 HOT 6
- How to change OBD protocol HOT 5
- Response not detected HOT 28
- Error in getting Multiple PID's HOT 9
- ESP32 s3 BLE compatibility? HOT 3
- Attempting to read non-standard PID HOT 1
- When does `queryPid` return `true`? HOT 4
- ESP32_CheckPIDs_1_20.ino HOT 1
- How to read data if I know TXD RXF RXD and MTH HOT 2
- ERROR: ELM_BUFFER_OVERFLOW on Honda Vezel 2023 HOT 4
- Problems in phase 1, can't connect with ELM327 HOT 3
- couldn't connect to OBD scanner HOT 5
- ERROR: ELM_TIMEOUT . Value received for a while and then error happens. HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from elmduino.