Repository navigation
ESP32 Fails to Connect to ELM327 – Stuck at Phase 1 #291
Description
Activity
- addedquestionFurther information is requestedFurther information is requested
on Jul 6, 2025 Can you provide some serial debug logs from your test app that shows what is happening when you attempt to connect?
Yes sure
Code
#include "BluetoothSerial.h"
#include "ELMduino.h"BluetoothSerial SerialBT;
#define ELM_PORT SerialBT
#define DEBUG_PORT SerialELM327 myELM327;
uint32_t rpm = 0;
void setup()
{
DEBUG_PORT.begin(115200);
delay(1000);
DEBUG_PORT.println("Booting...");#if LED_BUILTIN
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
#endifDEBUG_PORT.println("Initializing Bluetooth...");
ELM_PORT.begin("ArduHUD", true);
delay(1000);DEBUG_PORT.println("Attempting to connect to OBDII...");
bool connectStatus = ELM_PORT.connect("OBDII");if (!connectStatus)
{
DEBUG_PORT.println("Couldn't connect to OBD scanner - Phase 1");
DEBUG_PORT.println("Bluetooth status: " + String(ELM_PORT.connected() ? "CONNECTED" : "DISCONNECTED"));
while (1);
}
else
{
DEBUG_PORT.println("Bluetooth connected to OBDII");
}DEBUG_PORT.println("Starting ELM327 handshake...");
if (!myELM327.begin(ELM_PORT, true, 2000))
{
DEBUG_PORT.println("Couldn't connect to OBD scanner - Phase 2");
while (1);
}DEBUG_PORT.println("Connected to ELM327 successfully");
}void loop()
{
float tempRPM = myELM327.rpm();if (myELM327.nb_rx_state == ELM_SUCCESS)
{
rpm = (uint32_t)tempRPM;
DEBUG_PORT.print("Engine RPM: ");
DEBUG_PORT.println(rpm);
}
else if (myELM327.nb_rx_state != ELM_GETTING_MSG)
{
DEBUG_PORT.println("Error getting RPM:");
myELM327.printError();
}delay(1000);
}Output:
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:4888
load:0x40078000,len:16516
load:0x40080400,len:4
load:0x40080404,len:3476
entry 0x400805b4
Booting...
Initializing Bluetooth...
Attempting to connect to OBDII...
Couldn't connect to OBD scanner - Phase 1
Bluetooth status: DISCONNECTED@jimwhitelaw Sorry for the ping, but any help would be appreciated
Yeah, there's not much info to go on. Are you sure the BT adapter does not need a pin? It's failing at the Bluetooth connection phase, before any ELMduino code runs...
@jimwhitelaw yeah I was previously running the same code, when I connect the ELM327, a red light comes, up further more it connects through when I try pairing it with my phone, it requires.a pin code though, I tried connecting through setPin method but still no luck
And I tried ran a Bluetooth scan on the ESP to check whether the OBDII is discoverable and it indeed is
I have the same issue and haven't found a solusion
Yeah I think the reseting procedure should work I didn't have time so I used MAC address to connect, make sure to uncomment the setpin() line
I have the same issue and haven't found a solusion
No bonded devices found. I made sure to uncomment the setpin() line, and nothing changes. The PIN is correct, it works with my mobile phone.
No bonded devices found. I made sure to uncomment the setpin() line, and nothing changes. The PIN is correct, it works with my mobile phone.
Are you sure your phone isn't preventing the ESP's connection? I've seen things like that happen. Try running your sketch but with every phone/laptop BT disabled and see what happens.
~~I also have the same problem. Even with the phone bluetooth disables, the esp doesn't connect to the ELM. I attached some photos to show that it's working with "Torque" app and using AT commands while paired to the phone.
Code in use:
void elm_setup(void) { SerialBT.begin("OBD_DISPLAY", true); SerialBT.setPin("1234"); xTaskCreate(elm_task, "elm_task", TASK_STACK_SIZE, NULL, 1, NULL); } static void elm_task(void *parameter) { // Wait for bluetooth initialization while (!SerialBT.isReady()) { vTaskDelay(pdMS_TO_TICKS(100)); } set_bt_indicator_color(lv_color_make(255, 0, 0)); // Set Bluetooth indicator to red // Inizializza valori su display set_var_max_speed("N/A"); set_var_speed("N/A"); set_var_temperature("N/A"); set_var_voltage("N/A"); set_var_tps("N/A"); set_var_map("N/A"); set_var_rpms(0); // Begin BT talk /*if (!SerialBT.connect("81:23:45:67:89:BA")) { Serial.println("Couldn't connect to OBD scanner with MAC"); } else*/ if (!SerialBT.connect("OBDII")) { Serial.println("Couldn't connect to OBD scanner - Phase 1"); restart_task(); // Restart Connection } vTaskDelay(pdMS_TO_TICKS(1000)); if (!myELM327.begin(SerialBT, true, CONNECTION_TIMEOUT, ISO_14230_FAST_INIT)) { Serial.println("Couldn't connect to OBD scanner - Phase 2"); restart_task(); } else { Serial.println("ELM327 pronto!"); set_bt_indicator_color(lv_color_make(0, 255, 0)); } ...~~Nevermind I made it work






Board: DOIT ESP32 DEVKIT V1
ELM327: Generic Bluetooth OBD-II Adapter
Library Used: ELMduino
Baud Rate: 115200
Tested On: Arduino IDE 2.3.2 (also tested on earlier versions a year ago)
ELM327 discoverable under the name: "OBDII" by the ESP
What I’ve Tried
Verified MAC address and device name (OBDII)
Re-tested ELM327 via mobile apps (works fine)
Reduced baud rate from 115200 to 38400 and vice versa
Used BluetoothSerial.connect(address) with known MAC
Tried ELM_PORT.begin("ESP32", true, 10000); with/without pin
Library and board package are up to date