PowerBroker2 / ELMduino

Arduino OBD-II Bluetooth Scanner Interface Library for Car Hacking Projects
MIT License
632 stars 123 forks source link

ESP32 connection issues #143

Closed enslinm123 closed 1 year ago

enslinm123 commented 1 year ago

Hey PowerBroker,

First off, it's an amazing feat of a project you've taken on making interfacing with a vehicles OBD easier for the noobs like myself.

Onto the issue. So I acquired one of those el'cheapo chinese bluetooth elm327's and it's working great with the torque android app. My initial thoughts were to identify the RX and TX pins of the bluetooth chip and intercept them with an Arduino Nano, make a 3D Printed enclosure and install it permanently into the car instead of looking at my mobile the whole time.

Did some tinkering and eventually gave up after a few months where I'm not able to identify the RX and TX pins with my logic analyzer. Mostly due to my clamps being too large and I cannot identify the actual BT chip or find smaller probes locally in my country (I am suspecting it's communicating over some sort of SPI interface).

Anyways down to the issue at hand, I decided to get myself an ESP32 Dev Kit V1 board and I've been trying to just get it connected to the ELM327 to display the rpm or engine coolant temperature (want to try both respectively before moving over to a multi PID setup and displaying it on either a OLED or LCD screen)

So, when I upload the ESP32_test sketch I am able to successfully connect using the MAC and pin (mine prompts for the pin when I connect with my android device). All the AT commands that I've run return values in HEX, for instance AT RV returns the current battery voltage so there is definitely communication between my ESP32, ELM327 and the car.

Here's the funniest part, the moment I upload the ESP32_Bluetooth_Serial sketch, all I see are timeouts and unable to connect messages so I'm at a loss for words and already pulled out a lot of hair, lol.

When I upload the paired devices sketch I can see the paired device. If I upload the ESP32_test sketch it connects successfully again. I've even removed it from the paired devices list, paired it again with the ESP32_test sketch, ran a couple AT commands to verify the connection, removed the pairing again, tried pairing by means of the ESP32_Bluetooth_Serial sketch and get the same errors. When it's paired via the ESP32_test sketch and I run the ESP32_Bluetooth_Serial sketch, the same errors come up.

When I set my logging to Information on the Arduino IDE, I can see all other bluetooth devices in the vicinity however it will not pair with the ELM327.

Am I missing something?

PowerBroker2 commented 1 year ago

I've never had to use the MAC address or pin on my ESP32s to connect, so I'm not sure if you missed anything there. However, based on your other debugging experiences, I doubt this is the issue.

Can you post (with proper markdown tags) the debug printouts?

enslinm123 commented 1 year ago

Hey PB,

Thank you for the response and apologies for only responding now.

Typical Murphy situation below, lol

Below is the terminal output when I uploaded the ESP32_test sketch only commenting out the following two lines to let the sketch compile and upload:

pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);

Terminal output with a few AT commands after a manual reset: Terminal with ELMTest

This morning, I uploaded my BT Clear sketch (pasted near the bottom of this post) containing the "#define REMOVE_BONDED_DEVICES 1" to remove all pairings, afterwards I uploaded the ESP32_Bluetooth_Serial sketch (only changin the BT name of the ESP32 to "ESP32test" instead of "ArduHUD") and below is my terminal output when powering my ELM327 on the bench with GND (chassis ground on the ODB Port) and 5v (basically just to power it's Bluetooth chip) having it connect on "OBDII" without the pin and MAC address, but it seems fine now for some reason. I received connection errors on the bench as well as when connected to the car leaving the sketch default as well as change it to connect to the MAC address, previously I was not seeing any "OK" returns from the ELM327 in the terminal, not even a ELM327 version response.

I am suspecting now that changing the ESP32 BT Name as per below is what resolved my connection issue:

  //ELM_PORT.begin("ArduHUD", true);
  ELM_PORT.begin("ESP32test", true);

Terminal output below from bench powered ELM327 (The ESP32 detects my neighbor's Xoami MiBox, lol) Just a side note, the detected MAC Address: "aa:bb:cc:11:22:33" is the correct MAC for my ELM327, this is where one can see the 10 second delay in connecting to the BT Name instead of the Address.

Terminal Debug output:

[   498][I][BluetoothSerial.cpp:571] esp_bt_gap_cb(): ESP_BT_GAP_CONFIG_EIR_DATA_EVT: stat:0 num:4
[   498][I][BluetoothSerial.cpp:685] _init_bt(): device name set
[   500][I][BluetoothSerial.cpp:263] esp_spp_cb(): ESP_SPP_INIT_EVT
[   508][I][BluetoothSerial.cpp:938] connect(): master : remoteName
[   509][I][BluetoothSerial.cpp:571] esp_bt_gap_cb(): ESP_BT_GAP_CONFIG_EIR_DATA_EVT: stat:0 num:4
[   527][I][BluetoothSerial.cpp:507] esp_bt_gap_cb(): ESP_BT_GAP_DISC_STATE_CHANGED_EVT started
[  3295][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[  3295][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[  3299][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[  3307][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 196
[  3345][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[  3345][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[  3349][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[  3357][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 194
[  3366][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[  3372][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[  3380][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[  3387][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 186
[  3627][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[  3627][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[  3631][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[  3639][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 189
[  4126][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[  4126][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[  4130][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[  4138][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 185
[  4254][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[  4254][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: 6c:0d:c4:06:3b:c4
[  4258][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x280424
[  4266][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 160
[  4273][I][BluetoothSerial.cpp:435] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT : EIR : MIBOX4 nown : 11
[  4556][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[  4556][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[  4560][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[  4568][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 195
[  4854][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[  4854][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: 6c:0d:c4:06:3b:c4
[  4859][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x280424
[  4866][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 166
[  4874][I][BluetoothSerial.cpp:435] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT : EIR : MIBOX4 nown : 11
[  5126][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[  5126][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[  5130][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[  5138][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 195
[  5306][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[  5306][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[  5310][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[  5318][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 195
[  5647][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[  5647][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[  5651][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[  5659][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 187
[  6286][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[  6286][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: 6c:0d:c4:06:3b:c4
[  6291][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x280424
[  6298][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 164
[  6306][I][BluetoothSerial.cpp:435] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT : EIR : MIBOX4 nown : 11
[  6636][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[  6637][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: 6c:0d:c4:06:3b:c4
[  6641][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x280424
[  6649][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 165
[  6656][I][BluetoothSerial.cpp:435] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT : EIR : MIBOX4 nown : 11
[  8307][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[  8307][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[  8312][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[  8319][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 194
[  8428][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[  8428][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[  8433][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[  8440][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 187
[  8568][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[  8568][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: 6c:0d:c4:06:3b:c4
[  8572][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x280424
[  8580][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 163
[  8659][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[  8659][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: 6c:0d:c4:06:3b:c4
[  8663][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x280424
[  8671][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 161
[  9068][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[  9068][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[  9073][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[  9080][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 188
[  9498][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[  9498][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[  9503][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[  9510][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 190
[  9818][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[  9818][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[  9823][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[  9830][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 194
[ 10349][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[ 10349][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[ 10354][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[ 10361][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 186
[ 10688][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[ 10688][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[ 10693][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[ 10700][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 191
[ 11141][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[ 11142][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: 6c:0d:c4:06:3b:c4
[ 11146][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x280424
[ 11154][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 167
[ 11161][I][BluetoothSerial.cpp:435] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT : EIR : MIBOX4 nown : 11
[ 12884][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[ 12884][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: 6c:0d:c4:06:3b:c4
[ 12888][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x280424
[ 12896][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 162
[ 13410][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[ 13410][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[ 13414][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[ 13422][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 195
[ 13951][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[ 13951][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[ 13955][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[ 13963][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 186
[ 14521][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[ 14521][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[ 14525][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[ 14533][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 185
[ 15031][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[ 15031][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[ 15035][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[ 15043][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 193
[ 15082][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[ 15082][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[ 15086][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[ 15094][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 194
[ 15302][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[ 15302][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[ 15307][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[ 15314][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 190
[ 15611][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[ 15611][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[ 15615][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[ 15623][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 193
[ 15706][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[ 15706][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: 6c:0d:c4:06:3b:c4
[ 15711][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x280424
[ 15718][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 164
[ 15726][I][BluetoothSerial.cpp:435] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT : EIR : MIBOX4 nown : 11
[ 15792][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[ 15792][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[ 15796][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[ 15804][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 191
[ 16006][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[ 16007][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: 6c:0d:c4:06:3b:c4
[ 16011][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x280424
[ 16019][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 166
[ 16026][I][BluetoothSerial.cpp:435] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT : EIR : MIBOX4 nown : 11
[ 18652][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[ 18652][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[ 18657][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[ 18664][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 192
[ 19033][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[ 19033][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[ 19038][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[ 19045][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 196
[ 19313][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[ 19313][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[ 19318][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[ 19325][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 195
[ 19683][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[ 19683][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[ 19688][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[ 19695][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 195
[ 20313][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[ 20313][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[ 20318][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[ 20325][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 194
[ 20843][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[ 20843][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[ 20848][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[ 20855][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 196
[ 22686][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=1
[ 22686][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[ 22690][I][BluetoothSerial.cpp:454] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT : SPP_START_DISCOVERY_BDNAME : OBDII
[ 22701][I][BluetoothSerial.cpp:503] esp_bt_gap_cb(): ESP_BT_GAP_DISC_STATE_CHANGED_EVT stopped
[ 22711][I][BluetoothSerial.cpp:503] esp_bt_gap_cb(): ESP_BT_GAP_DISC_STATE_CHANGED_EVT stopped
[ 24571][I][BluetoothSerial.cpp:350] esp_spp_cb(): ESP_SPP_DISCOVERY_COMP_EVT num=1
[ 24571][D][BluetoothSerial.cpp:353] esp_spp_cb(): ESP_SPP_DISCOVERY_COMP_EVT: spp [0] channel: 1 service name:SPP slave
[ 24578][I][BluetoothSerial.cpp:361] esp_spp_cb(): ESP_SPP_DISCOVERY_COMP_EVT: spp connect to remote aa:bb:cc:11:22:33 channel 1
[ 24591][I][BluetoothSerial.cpp:402] esp_spp_cb(): ESP_SPP_CL_INIT_EVT handle:129 sec_id:55
[ 24692][I][BluetoothSerial.cpp:384] esp_spp_cb(): ESP_SPP_OPEN_EVT
Clearing input serial buffer
Sending the following command/query: AT D
    Received char: A
    Received char: T
    Received char: _
    Received char: D
    Received char: \r
    Received char: O
    Received char: K
    Received char: \r
    Received char: \n
    Received char: >
Delimiter found.
All chars received: ATDOK
Clearing input serial buffer
Sending the following command/query: AT Z
    Received char: A
    Received char: T
    Received char: _
    Received char: Z
    Received char: \r
    Received char: E
    Received char: L
    Received char: M
    Received char: 3
    Received char: 2
    Received char: 7
    Received char: _
    Received char: v
    Received char: 1
    Received char: .
    Received char: 5
    Received char: \r
    Received char: \n
    Received char: >
Delimiter found.
All chars received: ATZELM327v1.5
Clearing input serial buffer
Sending the following command/query: AT E0
    Received char: A
    Received char: T
    Received char: _
    Received char: E
    Received char: 0
    Received char: \r
    Received char: O
    Received char: K
    Received char: \r
    Received char: \n
    Received char: >
Delimiter found.
All chars received: ATE0OK
Clearing input serial buffer
Sending the following command/query: AT S0
    Received char: O
    Received char: K
    Received char: \r
    Received char: \n
    Received char: >
Delimiter found.
All chars received: OK
Clearing input serial buffer
Sending the following command/query: AT AL
    Received char: O
    Received char: K
    Received char: \r
    Received char: \n
    Received char: >
Delimiter found.
All chars received: OK
Clearing input serial buffer
Sending the following command/query: AT ST 00
    Received char: O
    Received char: K
    Received char: \r
    Received char: \n
    Received char: >
Delimiter found.
All chars received: OK
Clearing input serial buffer
Sending the following command/query: AT TP A0
    Received char: O
    Received char: K
    Received char: \r
    Received char: \n
    Received char: >
Delimiter found.
All chars received: OK
Connected to ELM327
Service: 1
PID: 12
Normal length query detected
Query string: 010C1
Clearing input serial buffer
Sending the following command/query: 010C1
    Received char: S
    Received char: E
    Received char: A
    Received char: R
    Received char: C
    Received char: H
    Received char: I
    Received char: N
    Received char: G
    Received char: .
    Received char: .
    Received char: .
    Received char: \r
    Received char: \n
Timeout detected with overflow of 0ms
Received: SEARCHING...
ERROR: ELM_TIMEOUT
Service: 1
PID: 12
Normal length query detected
Query string: 010C1
Clearing input serial buffer
Sending the following command/query: 010C1
Timeout detected with overflow of 0ms
Received: 
ERROR: ELM_TIMEOUT
Service: 1
PID: 12
Normal length query detected
Query string: 010C1
Clearing input serial buffer
Sending the following command/query: 010C1
    Received char: U
    Received char: N
    Received char: A
    Received char: B
    Received char: L
    Received char: E
    Received char: _
    Received char: T
    Received char: O
    Received char: _
    Received char: C
    Received char: O
    Received char: N
    Received char: N
    Received char: E
    Received char: C
    Received char: T
    Received char: \r
    Received char: \n
    Received char: >
Delimiter found.
All chars received: UNABLETOCONNECT
ELM responded with errror "UNABLE TO CONNECT"
Received: UNABLETOCONNECT
ERROR: ELM_UNABLE_TO_CONNECT
Service: 1
PID: 12
Normal length query detected
Query string: 010C1
Clearing input serial buffer
Sending the following command/query: 010C1
    Received char: S
    Received char: E
    Received char: A
    Received char: R
    Received char: C
    Received char: H
    Received char: I
    Received char: N
    Received char: G
    Received char: .
    Received char: .
    Received char: .
    Received char: \r
    Received char: \n
Timeout detected with overflow of 0ms
Received: SEARCHING...
ERROR: ELM_TIMEOUT
Service: 1
PID: 12
Normal length query detected
Query string: 010C1
Clearing input serial buffer
Sending the following command/query: 010C1

My BT Clear sketch, found it online:

#include "esp_bt_main.h"
#include "esp_bt_device.h"
#include"esp_gap_bt_api.h"
#include "esp_err.h"

#define REMOVE_BONDED_DEVICES 1   // <- Set to 0 to view all bonded devices addresses, set to 1 to remove

#define PAIR_MAX_DEVICES 20
uint8_t pairedDeviceBtAddr[PAIR_MAX_DEVICES][6];
char bda_str[18];

bool initBluetooth()
{
  if(!btStart()) {
    Serial.println("Failed to initialize controller");
    return false;
  }

  if(esp_bluedroid_init() != ESP_OK) {
    Serial.println("Failed to initialize bluedroid");
    return false;
  }

  if(esp_bluedroid_enable() != ESP_OK) {
    Serial.println("Failed to enable bluedroid");
    return false;
  }

}

char *bda2str(const uint8_t* bda, char *str, size_t size)
{
  if (bda == NULL || str == NULL || size < 18) {
    return NULL;
  }
  sprintf(str, "%02x:%02x:%02x:%02x:%02x:%02x",
          bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]);
  return str;
}

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

  initBluetooth();
  Serial.print("ESP32 bluetooth address: "); Serial.println(bda2str(esp_bt_dev_get_address(), bda_str, 18));
  // Get the numbers of bonded/paired devices in the BT module
  int count = esp_bt_gap_get_bond_device_num();
  if(!count) {
    Serial.println("No bonded device found.");
  } else {
    Serial.print("Bonded device count: "); Serial.println(count);
    if(PAIR_MAX_DEVICES < count) {
      count = PAIR_MAX_DEVICES; 
      Serial.print("Reset bonded device count: "); Serial.println(count);
    }
    esp_err_t tError =  esp_bt_gap_get_bond_device_list(&count, pairedDeviceBtAddr);
    if(ESP_OK == tError) {
      for(int i = 0; i < count; i++) {
        Serial.print("Found bonded device # "); Serial.print(i); Serial.print(" -> ");
        Serial.println(bda2str(pairedDeviceBtAddr[i], bda_str, 18));     
        if(REMOVE_BONDED_DEVICES) {
          esp_err_t tError = esp_bt_gap_remove_bond_device(pairedDeviceBtAddr[i]);
          if(ESP_OK == tError) {
            Serial.print("Removed bonded device # "); 
          } else {
            Serial.print("Failed to remove bonded device # ");
          }
          Serial.println(i);
        }
      }        
    }
  }
}

void loop() {}

All that is left now is to go and connect it up to the car and hope for the best, I will report back once I have connected it to the car with some more terminal debug outputs, thank you for trying to assist me with my random issue that went away mysteriously.

Just a random question, which displays have you successfully been able to get working with your ESP32's ? I have a Waveshare 1.5" RGB OLED I want to use and plan on using the Adafruit SSD1351 Library, hoping that will work lol

Regards, Martin

enslinm123 commented 1 year ago

So a quick update.

Managed to get a quick gap and tried connecting to the car, it connected successfully without any issues, I can kick myself for not capturing the terminal output, but was in such a rush to test it quickly before my boss noticed I was gone 😝 and for my own sanity sake. I even power cycled and it connected again and again without fail, I'm amazed that it just keeps on working now 👏

Also managed to connect my TTP223 and 1.5" 65K Display over SPI successfully and able to display some text on it. Had some issues with the Adafruit library so I found the SSD13XX library from Sumotoy here on github 👌 it works great and is super easy as well. My next challenge will be to port my sketch to a larger 2" IPS LCD that I have coming in the mail.

Thank you for the help PB, no idea what resolved my issue but hey I'm not complaining 😄 💪

Just sorting out a bug in a switch statement I want to use for multiple pages/screens where I have a summary page/screen with about 4 PID's actively displaying, then use the TTP223 to flip between pages/screens for a more detailed view of each PID and round robin back to the summary page.

enslinm123 commented 1 year ago

The celebrations were short lived 🤣

I am able to successfully connect to my car without problems (my car uses ISO 9141-2 or AT SP3, auto tends to cause problems for some reason) and executes the AT commands from the library successfully every single time.

So I went ahead and coded the PID's that I want to display on my OLED screen with a plain ol "switch" statement in my main loop where I then call the switch cases defined below the main loop and made a quick summary page displaying 4 PID's (Will post a picture in the next post as it's on my mobile), but this is where I am stuck now, more on that later...

The TTP223 works fantastic going through the pages, had a slight hiccup on the terminal output where it only loads a line when I touch the TTP223. Fixed that issue (as you will see in my code below in the comments) by using a couple of "If" statements instead of an "else if" statement (it worked flawlessly on my Ardu Nano on another project I had with the else if statement).

So the issue I am seeing now, no matter if I have the car running or just the IGN switched on, none of my PID's are displaying any data on the OLED display nor on the serial terminal. As you can see from the terminal output below, I get connected to the ELM327, the AT commands from the library go through and then it displays nothing further, only shows RPM as 0.

If I connect with my android BT Serial app and execute the AT commands manually, they all work and I also receive the correct HEX back (photo to follow in the next post).

I would appreciate your assistance with this as I am getting frustrated now 😭

Here is my terminal debug output:

[   741][I][BluetoothSerial.cpp:571] esp_bt_gap_cb(): ESP_BT_GAP_CONFIG_EIR_DATA_EVT: stat:0 num:4
[   741][I][BluetoothSerial.cpp:685] _init_bt(): device name set
[   744][I][BluetoothSerial.cpp:263] esp_spp_cb(): ESP_SPP_INIT_EVT
[   769][I][BluetoothSerial.cpp:938] connect(): master : remoteName
[   772][I][BluetoothSerial.cpp:571] esp_bt_gap_cb(): ESP_BT_GAP_CONFIG_EIR_DATA_EVT: stat:0 num:4
[   823][I][BluetoothSerial.cpp:507] esp_bt_gap_cb(): ESP_BT_GAP_DISC_STATE_CHANGED_EVT started
[  4028][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[  4029][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[  4042][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[  4064][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 182
[  4378][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[  4378][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[  4392][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[  4414][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 193
[  4768][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[  4768][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[  4782][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[  4804][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 195
[  4859][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[  4859][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[  4873][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[  4896][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 196
[  5448][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[  5448][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[  5462][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[  5484][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 196
[  5506][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[  5530][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[  5553][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[  5576][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 197
[  5811][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[  5811][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[  5824][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[  5846][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 190
[  5868][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[  5892][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[  5915][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[  5938][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 192
[  8781][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[  8781][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[  8794][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[  8816][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 198
[  8901][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[  8901][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[  8914][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[  8937][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 196
[  9371][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[  9371][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[  9384][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[  9406][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 197
[  9551][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[  9551][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[  9564][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[  9587][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 197
[  9642][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[  9642][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[  9656][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[  9678][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 192
[ 10191][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[ 10191][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[ 10204][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[ 10227][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 201
[ 10342][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[ 10342][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[ 10355][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[ 10378][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 198
[ 10751][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[ 10751][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[ 10764][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[ 10787][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 188
[ 13693][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[ 13693][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[ 13707][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[ 13729][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 200
[ 14113][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[ 14113][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[ 14127][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[ 14149][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 198
[ 14171][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[ 14195][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[ 14218][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[ 14241][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 200
[ 14753][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[ 14753][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[ 14767][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[ 14789][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 200
[ 14834][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[ 14835][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[ 14858][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[ 14880][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 198
[ 15223][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[ 15223][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[ 15237][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[ 15259][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 198
[ 15774][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[ 15774][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[ 15787][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[ 15809][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 197
[ 15831][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[ 15855][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[ 15878][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[ 15901][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 196
[ 16156][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[ 16156][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[ 16169][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[ 16191][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 193
[ 18756][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[ 18756][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[ 18769][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[ 18791][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 201
[ 19036][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[ 19036][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[ 19049][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[ 19071][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 200
[ 19496][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[ 19496][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[ 19509][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[ 19531][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 200
[ 19553][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[ 19577][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[ 19600][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[ 19623][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 199
[ 19645][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[ 19669][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[ 19692][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[ 19714][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 201
[ 19817][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[ 19817][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[ 19831][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[ 19853][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 198
[ 20146][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[ 20146][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[ 20159][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[ 20182][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 194
[ 20307][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[ 20307][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[ 20320][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[ 20343][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 200
[ 20365][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[ 20389][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[ 20412][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[ 20434][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 196
[ 20658][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[ 20658][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[ 20672][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[ 20694][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 199
[ 20746][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[ 20746][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[ 20763][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[ 20785][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 196
[ 20887][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=3
[ 20887][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[ 20901][D][BluetoothSerial.cpp:467] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_COD 0x1f00
[ 20923][D][BluetoothSerial.cpp:477] esp_bt_gap_cb(): ESP_BT_GAP_DEV_PROP_RSSI 199
[ 22788][I][BluetoothSerial.cpp:423] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT properties=1
[ 22788][I][BluetoothSerial.cpp:426] esp_bt_gap_cb(): Scanned device: aa:bb:cc:11:22:33
[ 22802][I][BluetoothSerial.cpp:454] esp_bt_gap_cb(): ESP_BT_GAP_DISC_RES_EVT : SPP_START_DISCOVERY_BDNAME : OBDII
[ 22832][I][BluetoothSerial.cpp:503] esp_bt_gap_cb(): ESP_BT_GAP_DISC_STATE_CHANGED_EVT stopped
[ 22859][I][BluetoothSerial.cpp:503] esp_bt_gap_cb(): ESP_BT_GAP_DISC_STATE_CHANGED_EVT stopped
[ 24661][I][BluetoothSerial.cpp:350] esp_spp_cb(): ESP_SPP_DISCOVERY_COMP_EVT num=1
[ 24661][D][BluetoothSerial.cpp:353] esp_spp_cb(): ESP_SPP_DISCOVERY_COMP_EVT: spp [0] channel: 1 service name:SPP slave
[ 24681][I][BluetoothSerial.cpp:361] esp_spp_cb(): ESP_SPP_DISCOVERY_COMP_EVT: spp connect to remote aa:bb:cc:11:22:33 channel 1
[ 24717][I][BluetoothSerial.cpp:402] esp_spp_cb(): ESP_SPP_CL_INIT_EVT handle:129 sec_id:55
[ 24816][I][BluetoothSerial.cpp:384] esp_spp_cb(): ESP_SPP_OPEN_EVT
Clearing input serial buffer
Sending the following command/query: AT D
    Received char: O
    Received char: K
    Received char: \r
    Received char: \n
    Received char: >
Delimiter found.
All chars received: OK
Clearing input serial buffer
Sending the following command/query: AT Z
    Received char: A
    Received char: T
    Received char: _
    Received char: Z
    Received char: \r
    Received char: E
    Received char: L
    Received char: M
    Received char: 3
    Received char: 2
    Received char: 7
    Received char: _
    Received char: v
    Received char: 1
    Received char: .
    Received char: 5
    Received char: \r
    Received char: \n
    Received char: >
Delimiter found.
All chars received: ATZELM327v1.5
Clearing input serial buffer
Sending the following command/query: AT E0
    Received char: A
    Received char: T
    Received char: _
    Received char: E
    Received char: 0
    Received char: \r
    Received char: O
    Received char: K
    Received char: \r
    Received char: \n
    Received char: >
Delimiter found.
All chars received: ATE0OK
Clearing input serial buffer
Sending the following command/query: AT S0
    Received char: O
    Received char: K
    Received char: \r
    Received char: \n
    Received char: >
Delimiter found.
All chars received: OK
Clearing input serial buffer
Sending the following command/query: AT AL
    Received char: O
    Received char: K
    Received char: \r
    Received char: \n
    Received char: >
Delimiter found.
All chars received: OK
Clearing input serial buffer
Sending the following command/query: AT ST 00
    Received char: O
    Received char: K
    Received char: \r
    Received char: \n
    Received char: >
Delimiter found.
All chars received: OK
Clearing input serial buffer
Sending the following command/query: AT TP A0
    Received char: O
    Received char: K
    Received char: \r
    Received char: \n
    Received char: >
Delimiter found.
All chars received: OK
Connected to ELM327
Service: 1
PID: 12
Normal length query detected
Query string: 010C1
Clearing input serial buffer
Sending the following command/query: 010C1
RPM: 0
[ 40055][I][BluetoothSerial.cpp:583] esp_bt_gap_cb(): ESP_BT_GAP_MODE_CHG_EVT: mode: 0

Here is my entire sketch. I'm sure there are ways to shorten and improve the code, but for a noob at C coding I don't think I'm doing too bad 😝 :

/* OBD Gauge source code
Written September 2022
Using PowerBroker's ELMDuino library to interface the ESP32 Dev Kit V1 with a el'cheapo Bluetooth ELM327
*/

#include "BluetoothSerial.h"
#include "ELMduino.h"
#include <SSD_13XX.h>
#include <SPI.h>
#include <Wire.h>

#define touchSW      15

// Define ELM327 parameters
BluetoothSerial SerialBT;
#define ELM_PORT   SerialBT
#define DEBUG_PORT Serial

ELM327 myELM327;

uint32_t rpm = 0;
float kph = 0;
uint8_t MAP = 0;           // To be used later to determine boost
uint8_t abdBaro = 0;     // To be used later to determine boost
uint8_t boost = 0;         // To be used later to determine boost
float maf = 0;
float ect = 0;
float iat = 0;
float afr = 0;
float batt = 0;

// Define OLED parameters for ESP32
#define _cs   17            // GPIO 17 pin 27
#define _dc   16            // GPIO 16 pin 25
#define _mosi 23            // GPIO 23 pin 36
#define _sclk 18            // GPIO 18 pin 35
#define _rst  5             // GPIO 5 pin 34
#define _miso
SSD_13XX tft = SSD_13XX(_cs, _dc, _rst);

// Button Variables
int selector = 0, summary = 0;
boolean isPressed = false;

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

  pinMode(touchSW, INPUT);
  tft.begin();
  tft.fillScreen(BLACK);
  DEBUG_PORT.begin(38400);
  ELM_PORT.begin("OBD_Gauge", true);

  if (!ELM_PORT.connect("OBDII"))
  {
    DEBUG_PORT.println("Couldn't connect to OBD scanner - Phase 1");
    tft.clearScreen();
    tft.setTextColor(RED, BLACK);
    tft.setTextScale(1);
    tft.setCursor(25, 20);
    tft.print("NOT Connected");
    tft.setCursor(25, 50);
    tft.print("Phase 1");
    delay(1000);
    tft.clearScreen();
    while(1);
  }

  if (!myELM327.begin(ELM_PORT, true, 2000))
  {
    Serial.println("Couldn't connect to OBD scanner - Phase 2");
    tft.clearScreen();
    tft.setTextColor(RED, BLACK);
    tft.setTextScale(1);
    tft.setCursor(25, 20);
    tft.print("NOT Connected");
    tft.setCursor(25, 50);
    tft.print("Phase 2");
    delay(1000);
    tft.clearScreen();    
    while (1);
  }

  Serial.println("Connected to ELM327");
  tft.clearScreen();
  tft.setTextColor(GREEN, BLACK);
  tft.setTextScale(2);
  tft.setCursor(25, 60);
  tft.print("Connected");
  delay(1000);
  tft.clearScreen();   

// Initialize Splash Screen
  tft.clearScreen();
  tft.setTextColor(WHITE, BLACK);
  tft.setTextScale(2);
  tft.setCursor(35, 20);
  tft.print("OBD II");
  delay(300);
  tft.setCursor(35, 50);
  tft.print("Gauge");
  tft.setTextColor(CYAN, BLACK);
  tft.setTextScale(1);
  tft.setCursor(20,100);
  delay(300);
  tft.clearScreen();
}

void loop()
{
  if (digitalRead(touchSW) == LOW &&  isPressed == false){
    isPressed = true;

    doSwitchStatement();
    selector++;

    if (selector >= 8) {
      selector = 0;
    } 
  }
  //else if (digitalRead(touchSW) == HIGH){             // If I remove the comments and comment out the line below I get the odd results in serial monitor where it only displays a line per TTP223 touch
  if (digitalRead(touchSW) == HIGH && isPressed == true){
    isPressed = false;
  }
}

// Setup the different main pages to display the PID data. Don't mind the spacing, still need to fine tune it or find an easier way of doing it :P
void doSwitchStatement(){
  switch(selector){
  case 0:
    tft.fillScreen(BLACK);
    tft.setTextColor(WHITE, BLACK);
    tft.setTextScale(1);
    tft.setCursor(32, 0);
    tft.println(" SUMMARY ");
    doSummary();
    break;

  case 1:
    tft.fillScreen(BLACK);
    tft.setTextColor(WHITE, BLACK);
    tft.setTextScale(1);
    tft.setCursor(32, 0);
    tft.println(" ECT ");  
      getECT();
   break;

   case 2:
    tft.fillScreen(BLACK);
    tft.setTextColor(WHITE, BLACK);
    tft.setTextScale(1);
    tft.setCursor(32, 0);
    tft.println(" IAT ");   
      getIAT();
   break;

   case 3:
    tft.fillScreen(BLACK);
    tft.setTextColor(WHITE, BLACK);
    tft.setTextScale(1);
    tft.setCursor(32, 0);
    tft.println(" AFR ");   
      getAFR();
   break;

   case 4:
    tft.fillScreen(BLACK);
    tft.setTextColor(WHITE, BLACK);
    tft.setTextScale(1);
    tft.setCursor(32, 0);
    tft.println(" BATT ");   
      getBATT();
   break;

   case 5:
    tft.fillScreen(BLACK);
    tft.setTextColor(WHITE, BLACK);
    tft.setTextScale(1);
    tft.setCursor(32, 0);
    tft.println(" RPM ");
      getENG_RPM();
   break;

   case 6:
    tft.fillScreen(BLACK);
    tft.setTextColor(WHITE, BLACK);
    tft.setTextScale(1);
    tft.setCursor(32, 0);
    tft.println(" KM/H ");   
      getSPEED();
   break;

   case 7:
    tft.fillScreen(BLACK);
    tft.setTextColor(WHITE, BLACK);
    tft.setTextScale(1);
    tft.setCursor(32, 0);
    tft.println(" MAF ");   
      getMAF();
   break;   
 }
}

void doSummary() {
  switch (summary) {
    case 0:
    summary++;
     if (summary >= 1) {
      summary = 0;
     }
      rpmSUM();
      MAFSum();
      IATSum();
      coolSUM();
  break;
  }
}

void coolSUM(){
  if (myELM327.nb_rx_state == ELM_SUCCESS)
  {
    ect = myELM327.engineCoolantTemp();
    Serial.print("RPM: "); Serial.println(ect);
  }
  else if (myELM327.nb_rx_state != ELM_GETTING_MSG)
  {
    myELM327.printError();
  }

  tft.setTextColor(WHITE, BLACK);
  tft.setTextScale(1);
  tft.drawRect(4, 10, 57, 52, CYAN); 
  tft.setCursor(11, 12);
  tft.print("Coolant");
  tft.setCursor(6, 30);
  tft.setTextScale(1);
  tft.print(ect);
/*  tft.setTextSize(1);
  tft.println("o");
  tft.setTextSize(2);
  tft.print("c");*/
}

void IATSum(){
  if (myELM327.nb_rx_state == ELM_SUCCESS)
  {
    iat = myELM327.intakeAirTemp();
    Serial.print("IAT: "); Serial.println(iat);
  }
  else if (myELM327.nb_rx_state != ELM_GETTING_MSG)
  {
    myELM327.printError();
  }

    tft.setTextColor(WHITE, BLACK);
    tft.setTextScale(1);
    tft.drawRect(67, 10, 57, 52, YELLOW);
    tft.setCursor(85, 12);
    tft.print("IAT");
    tft.setCursor(69, 30);
    tft.setTextScale(1);
    tft.print(iat);
/*      tft.setTextSize(1);
    tft.print("o");
    tft.setTextSize(2);
    tft.print("c");  */    
}

void MAFSum(){
  if (myELM327.nb_rx_state == ELM_SUCCESS)
  {
    maf = myELM327.mafRate();
    Serial.print("MAF: "); Serial.println(maf);
  }
  else if (myELM327.nb_rx_state != ELM_GETTING_MSG)
  {
    myELM327.printError();
  }

    tft.setTextColor(WHITE, BLACK);
    tft.setTextScale(1);    
    tft.drawRect(4, 69, 57, 52, RED);
    tft.setCursor(25, 71);
    tft.print("MAF");
    tft.setCursor(6, 90);
    tft.setTextScale(1);
    tft.print(maf);
}

void rpmSUM(){
  if (myELM327.nb_rx_state == ELM_SUCCESS)
  {
    rpm = myELM327.rpm();
    Serial.print("RPM: "); Serial.println(rpm);
  }
  else if (myELM327.nb_rx_state != ELM_GETTING_MSG)
  {
    myELM327.printError();
  }

  tft.setTextColor(WHITE, BLACK);
  tft.setTextScale(1);
  tft.drawRect(67, 69, 57, 52, GREEN);
  tft.setCursor(85, 71);
  tft.print("RPM");
  tft.setCursor(69, 90);
  tft.setTextScale(1);
  tft.print(rpm);
}

void BoostSum(){
  tft.setTextColor(WHITE, BLACK);
  tft.setTextScale(1);
  tft.drawRect(67, 69, 57, 52, GREEN);
  tft.setCursor(80, 71);
  tft.print("BOOST");
  tft.setCursor(69, 90);
  tft.setTextScale(2);
  tft.print("N/A");
}

void getECT(){
  if (myELM327.nb_rx_state == ELM_SUCCESS)
  {
   ect = myELM327.engineCoolantTemp();
   Serial.print("ect: ");
   Serial.println(ect);
   tft.setTextColor(WHITE, BLACK);
   tft.setTextScale(1);
   tft.setCursor(10, 60);
   tft.print(ect);
   tft.print(" C");
   }
   else if (myELM327.nb_rx_state != ELM_GETTING_MSG)
   {
    myELM327.printError();
   }
}

void getIAT(){
  if (myELM327.nb_rx_state == ELM_SUCCESS)
  {
    iat = myELM327.intakeAirTemp();
    Serial.print("iat: ");
    Serial.println(iat);
    tft.setTextColor(WHITE, BLACK);    
    tft.setTextScale(1);      
    tft.setCursor(10, 60);
    tft.print(iat);
    tft.print(" C");
  }
  else if (myELM327.nb_rx_state != ELM_GETTING_MSG)
  {
    myELM327.printError();
   }
}

void getAFR(){
  if (myELM327.nb_rx_state == ELM_SUCCESS)
  {
    afr = myELM327.commandedAirFuelRatio();
    Serial.print("afr: ");
    Serial.println(afr);
    tft.setTextScale(1);      
    tft.setCursor(10, 60);
    tft.print(afr);
    tft.print(" AFR");
   }
  else if (myELM327.nb_rx_state != ELM_GETTING_MSG)
  {
    myELM327.printError();
   }
}

void getBATT(){
  if (myELM327.nb_rx_state == ELM_SUCCESS)
  {
    batt = myELM327.batteryVoltage();
    Serial.print("batt: ");
    Serial.println(batt);
    tft.setTextScale(1);      
    tft.setCursor(10, 60);
    tft.print(batt);
    tft.print(" V");
   }
  else if (myELM327.nb_rx_state != ELM_GETTING_MSG)
  {
    myELM327.printError();
   }
}

void getENG_RPM(){
  if (myELM327.nb_rx_state == ELM_SUCCESS)
  {
    rpm = myELM327.rpm();
    Serial.print("rpm: ");
    Serial.println(rpm);
    tft.setTextScale(1);        
    tft.setCursor(10, 60);
    tft.print(rpm);
    tft.print(" RPM");
   }
  else if (myELM327.nb_rx_state != ELM_GETTING_MSG)
  {
    myELM327.printError();
   }
}

void getSPEED(){
  if (myELM327.nb_rx_state == ELM_SUCCESS)
  {
    kph = myELM327.kph();
    Serial.print("kph: ");
    Serial.println(kph);
    tft.setTextScale(1);        
    tft.setCursor(10, 60);
    tft.print(kph);
    tft.print(" KPH");
   }
  else if (myELM327.nb_rx_state != ELM_GETTING_MSG)
  {
    myELM327.printError();
   }
}

void getMAF(){
  if (myELM327.nb_rx_state == ELM_SUCCESS)
  {
    maf = myELM327.mafRate();
    Serial.print("maf: ");
    Serial.println(maf);
    tft.setCursor(10, 60);
    tft.print(maf);
    tft.print(" g/s");
   }
else if (myELM327.nb_rx_state != ELM_GETTING_MSG)
{
  myELM327.printError();
 }
}
enslinm123 commented 1 year ago

Output of the android bt serial terminal. I forgot to set Carriage Return options, but it should display better if I change it. I see now that I've uploaded the picture its from another ELM327 I have that is "V2.1" but has very limited features (does not have the K and L lines soldered on), hence me buying another one that is V1.5

Screenshot_20220702-191754_Serial Bluetooth Terminal

This is my quick and dirty Summary page:

20220930_221954

Showing the next page by pressing the TTP223. It changes quicker then I could touch it 🤣

20220930_221941

PowerBroker2 commented 1 year ago

I'm having a hard time understanding what's going on here, but I have a few suggestions:

  1. Make sure you finish parsing the last response from the ELM327 before requesting a new PID
  2. "NO DATA" usually means the car doesn't have that data available to give to the ELM327 in the first place
  3. Verify you can get each PID individually (i.e. request one PID and don't request the others, but cycle through all PIDs you want to use)
  4. Issues are mainly for bugs/feature requests. You'll probably get more in-depth/faster help with project styled questions on the Arduino forum
PlastiBots commented 1 year ago

@enslinm123, not sure if you solved your issue, but having a look at your code, I think one issue is you are making the request for the value after ELM_SUCCESS ( iat = myELM327.intakeAirTemp(); is inside this). However, I don't think you will get a success as there's nothing being checked. Look at the examples provided as you have to request the PID outside of this. Also, per PowerBroker2's note, only do one at a time.

void getIAT(){
  if (myELM327.nb_rx_state == ELM_SUCCESS)
  {
    iat = myELM327.intakeAirTemp();
    Serial.print("iat: ");
    Serial.println(iat);
    tft.setTextColor(WHITE, BLACK);    
    tft.setTextScale(1);      
    tft.setCursor(10, 60);
    tft.print(iat);
    tft.print(" C");
  }
  else if (myELM327.nb_rx_state != ELM_GETTING_MSG)
  {
    myELM327.printError();
   }
}
enslinm123 commented 1 year ago

@enslinm123, not sure if you solved your issue, but having a look at your code, I think one issue is you are making the request for the value after ELM_SUCCESS ( iat = myELM327.intakeAirTemp(); is inside this). However, I don't think you will get a success as there's nothing being checked. Look at the examples provided as you have to request the PID outside of this. Also, per PowerBroker2's note, only do one at a time.

void getIAT(){
  if (myELM327.nb_rx_state == ELM_SUCCESS)
  {
    iat = myELM327.intakeAirTemp();
    Serial.print("iat: ");
    Serial.println(iat);
    tft.setTextColor(WHITE, BLACK);    
    tft.setTextScale(1);      
    tft.setCursor(10, 60);
    tft.print(iat);
    tft.print(" C");
  }
  else if (myELM327.nb_rx_state != ELM_GETTING_MSG)
  {
    myELM327.printError();
   }
}

Hey bud,

No I have not solved this issue and gave up and put everything back in my parts box for now, lol.

What I was trying to do is take the multiple PID's example (as the lib is non blocking) and adapt it for my purposes where I have a LCD displaying multiple items on a single screen as well as have the ability to flip between screens for a more detailed view of each PID.

I had a quick glance at my sketch again and I think I know where the problem lies. Comparing to the multiple PID example I need to adapt my code to reflect the correct flow as per below copied from the example and switch the obd states.

I'm still learning how to work with cases and reading up a bit on it and glancing at my sketch I can see a lot of improvements I need to make, lol.

Here's the excerpt from the example I'm referring to:

typedef enum { ENG_RPM,
              SPEED } obd_pid_states;
obd_pid_states obd_state = ENG_RPM;

float rpm = 0;
float mph = 0;

I honestly think I was trying to over complicate things too soon instead of growing the project bit by bit. I did however have slight success with a single PID for rpm to display it on the serial monitor, but it was not updating on my LCD after which I decided to pack it away to look into again at another stage.

But thank you for pointing that out, I'm definitely going to look into it again and comb through my sketch with a fine tooth comb and start fresh from the ground up.

enslinm123 commented 1 year ago

So just a quick update.

I managed to get around to quickly testing today and the multiple PID's work like a charm, now I just need to figure out how I will display that on a OLED screen, that's the next step lol.

The sketch I tested with:

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

// Define ELM327 parameters
BluetoothSerial SerialBT;
#define ELM_PORT   SerialBT
#define DEBUG_PORT Serial

ELM327 myELM327;

typedef enum { ENG_RPM,
               ENG_COOL,
               BATT } obd_pid_states;
obd_pid_states obd_state = ENG_RPM;

float rpm = 0;
float ect = 0;
float batt = 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("Gauge", true);

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

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

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

void loop()
{
  switch (obd_state)
  {
    case ENG_RPM:
    {
      rpm = myELM327.rpm();

      if (myELM327.nb_rx_state == ELM_SUCCESS)
      {
        Serial.print("rpm: ");
        Serial.println(rpm);
        obd_state = ENG_COOL;
      }
      else if (myELM327.nb_rx_state != ELM_GETTING_MSG)
      {
        myELM327.printError();
        obd_state = ENG_COOL;
      }

      break;
    }

    case ENG_COOL:
    {
      ect = myELM327.engineCoolantTemp();

      if (myELM327.nb_rx_state == ELM_SUCCESS)
      {
        Serial.print("ect: ");
        Serial.println(ect);
        obd_state = BATT;
      }
      else if (myELM327.nb_rx_state != ELM_GETTING_MSG)
      {
        myELM327.printError();
        obd_state = BATT;
      }

      break;
    }

    case BATT:
    {
      batt = myELM327.batteryVoltage();

      if (myELM327.nb_rx_state == ELM_SUCCESS)
      {
        Serial.print("batt: ");
        Serial.println(batt);
        obd_state = ENG_RPM;
      }
      else if (myELM327.nb_rx_state != ELM_GETTING_MSG)
      {
        myELM327.printError();
        obd_state = ENG_RPM;
      }

      break;
    }
  }
}

In Serial Monitor I could see RPM, Battery voltage and also Engine Coolant Temp scrolling by at quite a pace, stupid me closed the window before copying some of the text, smh.

Thanks again to @PowerBroker2 for the assistance and trying to understand my issue and to @PlastiBots for pointing out my issue. It definitely helps to have a fresh set of eyes look at your sketch and point out your mistakes. No harm no foul, and I learnt a lot.

With that said, I am going to close this issue as it no longer needs to be open.