Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Board crashing after connection when attempting to add new hybrid focused PIDs #10

Open
cr08 opened this issue Oct 22, 2024 · 6 comments

Comments

@cr08
Copy link

cr08 commented Oct 22, 2024

Hi! Hope I can get some direction and pointers. I've exhausted the debugging options I can some up with on this. My Arduino/ESP32 knowledge is fairly limited.

But I'm trying to modify this and add some hybrid specific PIDs from my own Ford vehicle. The stock code works fine and the various gauges show data where available. However once I add the new PID (just doing one for now to test) once the connection is established and the first display page is rendered it crashes.

Here's the manual queries I ran on my OBD adapter:

>001100BB

41 0B 63 

>00110055                                                                                                        
                                                                                                                 
41 05 34                                                                                                         
41 05 34                                                                                                         
41 05 34                                                                                                         
                                                                                                                 
>00110044                                                                                                        
                                                                                                                 
41 04 00                                                                                                         
41 04 00                                                                                                         
41 04 00                                                                                                         
                                                                                                                 
>001155cc                                                                                                        
                                                                                                                 
NO DATA                                                                                                          
                                                                                                                 
>222211667744                                                                                                    
                                                                                                                 
NO DATA                                                                                                          

>222211ee11cc

62 1E 1C 00 C3 
62 1E 1C 00 F8 

>222244880011

62 48 01 BA EB 

>2222dddd0044

62 DD 04 FF 
62 DD 04 38 

>2222448800bb

62 48 0B 00 00 
62 48 0B 00 00 

>222244884411

62 48 41 0F CD

Ignore the duplicate characters. I misconfigured my minicom instance. But PID 224801 is the one I tested with in the sketch. PIDs 22480B, 22DD04, and 224841 are additional ones I want to use but haven't put into the sketch yet. I'm testing with the one for now.

Here's the serial monitor log:


<<  Va&Cob OBDII Gauge  >>
by Ratthanin W. BUILD -> Oct 20 2024 - 15:56:55
Error: File not found!
Show System: 0
Temp Offset: -50
Bluetooth..OK
Connecting to OBDII - 00:1d:a5:00:02:40
Connected Successfully!
ATZ


ELM327 v1.5


Display layout -> 0
010B
41 0B 63 


010C
41 0C 00 00 
41 0C 00 00 
41 0C 00 00 


Guru Meditation Error: Core  1 panic'ed (StoreProhibited). Exception was unhandled.

Core  1 register dump:
PC      : 0x40092728  PS      : 0x00060a30  A0      : 0x800ef26f  A1      : 0x3ffd08a0  
A2      : 0xae5b725a  A3      : 0x3ffd098c  A4      : 0x00000003  A5      : 0x0000ff00  
A6      : 0x00ff0000  A7      : 0xff000000  A8      : 0x00000000  A9      : 0xae5b725a  
A10     : 0x00000030  A11     : 0x00000000  A12     : 0x00000001  A13     : 0x0000ff00  
A14     : 0x00ff0000  A15     : 0xff000000  SAR     : 0x00000015  EXCCAUSE: 0x0000001d  
EXCVADDR: 0xae5b725a  LBEG    : 0x4009273c  LEND    : 0x40092741  LCOUNT  : 0x00000000  


Backtrace: 0x40092725:0x3ffd08a0 0x400ef26c:0x3ffd08c0 0x400ef38a:0x3ffd08e0 0x400d54ca:0x3ffd0900 0x400dae52:0x3ffd09c0 0x400f24dd:0x3ffd0a40

Ran an exception decoder:

Backtrace: 0x40092725:0x3ffd08a0 0x400ef26c:0x3ffd08c0 0x400ef38a:0x3ffd08e0 0x400d54ca:0x3ffd0900 0x400dae52:0x3ffd09c0 0x400f24dd:0x3ffd0a40


Decoding stack results
0x40092725: memmove at /builds/idf/crosstool-NG/.build/xtensa-esp32-elf/src/newlib/newlib/libc/string/memmove.c:75
0x400ef26c: String::move(String&) at /home/cr08/.arduino15/packages/esp32/hardware/esp32/2.0.17/cores/esp32/WString.cpp:237
0x400ef38a: String::operator=(String&&) at /home/cr08/.arduino15/packages/esp32/hardware/esp32/2.0.17/cores/esp32/WString.cpp:277
0x400d54ca: getAB(String) at /home/cr08/Software/ESP32-OBD2-Gauge_cr08/sketch/VaAndCobOBD2Gauge/meter.h:396
0x400dae52: loop() at /home/cr08/Software/ESP32-OBD2-Gauge_cr08/sketch/VaAndCobOBD2Gauge/VaAndCobOBD2Gauge.ino:480
0x400f24dd: loopTask(void*) at /home/cr08/.arduino15/packages/esp32/hardware/esp32/2.0.17/cores/esp32/main.cpp:50

Since I have my own fork for this with some added lines, here should be direct links to the lines being referenced:
https://github.com/cr08/ESP32-OBD2-Gauge/blob/cd845ff29f4046cf22e46fbfb5648ac8caeb7632/sketch/VaAndCobOBD2Gauge/VaAndCobOBD2Gauge.ino#L480

https://github.com/cr08/ESP32-OBD2-Gauge/blob/cd845ff29f4046cf22e46fbfb5648ac8caeb7632/sketch/VaAndCobOBD2Gauge/meter.h#L396

Added the PID as an extra line which should come up as PID number 7 and that's been added in display 0:
https://github.com/cr08/ESP32-OBD2-Gauge/blob/cd845ff29f4046cf22e46fbfb5648ac8caeb7632/sketch/VaAndCobOBD2Gauge/VaAndCobOBD2Gauge.ino#L101C3-L101C78

And also an extra formula line for it:
https://github.com/cr08/ESP32-OBD2-Gauge/blob/cd845ff29f4046cf22e46fbfb5648ac8caeb7632/sketch/VaAndCobOBD2Gauge/meter.h#L473

Probably a lot of info but wanted to make sure I provide as much as I can and what I've ran through trying to debug it myself. Any help would be greatly appreciated in trying to figure this out. Seems I'm so close to getting it going.

Thanks!

@VaAndCob
Copy link
Owner

VaAndCob commented Oct 23, 2024 via email

@VaAndCob
Copy link
Owner

VaAndCob commented Oct 23, 2024

oh one more thing. some ELM327 adaptor's quality is low. slow speed and sometimes return garbage data, since the code itself, there is no error checking. this could lead to errors during calculation.

@cr08
Copy link
Author

cr08 commented Oct 26, 2024

Thanks for looking into it! Yeah, I'm very aware of some adapter's quality. I've had a few over the years that have been hit or miss. This one I'm working with I have had before I discovered this project but specifically picked out because it had the recommended PIC18F25K80 chip and separate bluetooth daughterboard which seems to be better amongst the clones out there and should be the same as the linked Aliexpress product aside from being a different brand.

I did do some further testing. First thing I did was run the 'SerialToSerialBTM' example code from the Arduino IDE which basically allows a simple Bluetooth to serial monitor terminal so I could manually run things from the same board for debugging. Followed all the init commands in your code and then tried to poll the PIDs. All looks good to me?

ATE0
OK

>SEARCHING...
41 00 00 00 00 00 
41 00 98 18 00 13 
41 00 BE 3F A8 13 
41 00 98 18 00 13 
STOPPED

>41 05 39 
41 05 39 
41 05 39 
STOPPED

>62 48 01 BA 18 
STOPPED

>41 0C 00 00 
41 0C 00 00 
STOPPED

>62 48 0B FF F6 
62 48 0B 00 00 
STOPPED

>62 48 01 BA 11 
STOPPED

The 62 48 01 XX XX is the PID I've been working on once again.

I did also try adjusting the formula for that PID to clean it up some and more closely match some of the other formula in case that was an issue. The math still checks out:

case 7: data = (A*256+B)/5/100; break;

Unfortunately still have the same issue.

@VaAndCob
Copy link
Owner

https://wokwi.com/projects/412905386300120065

I test the code, it works without problem. so can u debug step by step?

  1. Serial.println( A and B) after calling getAB() function. to know exactly the value of A and B

  2. Serial.print (data in formula 7) to see what the value of data after calculation done.

if (A and B) are interpreted correctly, it should work well when passing to formula 7 equation.

@cr08
Copy link
Author

cr08 commented Nov 3, 2024

Had a chance to dive into this a bit more today and looks like my added PID and formula are fine. In fact now it seems to possibly be crashing on some of the existing PIDs. Not sure how I managed to get a flawless running build before. I even went back and compiled and flashed your version and was getting the same crash cycles as with my mods.

I wonder if any of this is due to this being a hybrid vehicle. In all of my tests the vehicle is fully running but the engine is off so stuff like the engine speed and load should be 0 but everything else in theory should be available.

If this may be related, I'll have to push forward and try putting in all the hybrid PIDs I want and see how it behaves. The existing PIDs in your version would be completely wiped away and replaced which is the intent of my own fork.

But that said, here's the most recent log I have from my own code with the suggested modifications per your last comment. DEBUG #1 section is the A and B print lines with an extra line displaying the PID label and number to keep track of what's queried.
DEBUG #2 is the output of the formula calculation. Only added to the extra formula I added

<<  Va&Cob OBDII Gauge  >>
by Ratthanin W. BUILD -> Nov  3 2024 - 15:36:47
Error: File not found!
Show System: 0
Temp Offset: -50
Bluetooth..OK
Connecting to OBDII - 00:1d:a5:00:02:40
Connected Successfully!
ATZ


ELM327 v1.5


Display layout -> 0
DEBUG #1
HVB SOC, 224801
0, 0

DEBUGEND
DEBUG #2
0.00
DEBUGEND
010B
41 0B 62 


62



DEBUG #1
MAP, 010B
98, 0

DEBUGEND

41 0B 62 
41
0B
DEBUG #1
ENG Load, 0104
65, 11

DEBUGEND
010B
41 0B 63 


63



DEBUG #1
MAP, 010B
99, 0

DEBUGEND

41 0B 63 



41
0B
DEBUG #1
ENG Load, 0104
65, 11

DEBUGEND
010B
41 0B 63 


63

DEBUG #1
MAP, 010B
99, 0

DEBUGEND

CAN ERROR



CAN
ERROR


DEBUG #1
ENG Load, 0104
202, 14

DEBUGEND
010B
41 0B 62 


62



DEBUG #1
MAP, 010B
98, 0

DEBUGEND
224801
62 48 01 B7 E3 


B7
E3
DEBUG #1
HVB SOC, 224801
183, 227

DEBUGEND
DEBUG #2
94.00
DEBUGEND
0105
41 05 34 
41 05 34 
41 05 34 


Guru Meditation Error: Core  1 panic'ed (StoreProhibited). Exception was unhandled.

Core  1 register dump:
PC      : 0x40092728  PS      : 0x00060c30  A0      : 0x800ef2ba  A1      : 0x3ffd0810  
A2      : 0x98d28953  A3      : 0x3ffea398  A4      : 0x00000003  A5      : 0x0000ff00  
A6      : 0x00ff0000  A7      : 0xff000000  A8      : 0x00000000  A9      : 0x98d28953  
A10     : 0x0000000d  A11     : 0x00000000  A12     : 0x00000003  A13     : 0x0000ff00  
A14     : 0x00ff0000  A15     : 0xff000000  SAR     : 0x00000015  EXCCAUSE: 0x0000001d  
EXCVADDR: 0x98d28953  LBEG    : 0x4009273c  LEND    : 0x40092741  LCOUNT  : 0x00000000  


Backtrace: 0x40092725:0x3ffd0810 0x400ef2b7:0x3ffd0830 0x400ef3ff:0x3ffd0850 0x400d5452:0x3ffd0870 0x400d6ca6:0x3ffd0930 0x400db161:0x3ffd09d0 0x400f2585:0x3ffd0a50

I then went back to the original code after that and that's where I was still getting crashes. Seemed to reoccur on the ENG SPD, PCM VOLT, ENG load, and occasionally trans temp PIDs. Each time whatever PID was queried right before the crash I'd put the MAP PID in that slot since the MAP PID seems to be the most reliable for me.

This is the current pidConfig and display layouts:

const String pidConfig[7][9] = {
  //[pid][data]
  { "ENG Load", "%", "0104", "2", "0", "100", "0", "0", "80" },      //0 = 0104
  { "ECT", "`C", "0105", "1", "0", "120", "3", "0", "99" },          //1 = 0105
  { "MAP", "psi", "010B", "0", "0", "40", "0", "1", "35" },          //2 = 010B
  // { "ENG SPD", "rpm", "010C", "3", "0", "5000", "0", "0", "4000" },  //3 = 010C
  { "MAP#2", "psi", "010B", "0", "0", "40", "0", "1", "35" },          //2 = 010B
  // { "PCM Volt", "volt", "0142", "4", "0", "16", "1", "1", "15" },    //4 = 0142
  { "MAP#2", "psi", "010B", "0", "0", "40", "0", "1", "35" },          //2 = 010B
#ifdef FORD_T5
  { "IAT", "`C", "010F", "1", "0", "120", "3", "0", "99" },  //5 = 015C
#else
  { "Oil Temp", "`C", "015C", "1", "0", "120", "3", "0", "99" },     //5 = 015C
#endif
#ifdef FORD_T5
  { "TFT", "`C", "221674", "6", "0", "120", "3", "0", "99" }  //6 = 221674 for FORD T5
#else
  { "Trans Temp", "`C", "221E1C", "5", "0", "120", "3", "1", "99" }  //6 = 221E1C for FORD T6+
#endif

};
const uint8_t pidInCell[8][7] = {
  //[layout][cellNo]
  //the last cell must be 3 (engine speed) to check engine off
  { 2, 2, 3, 4, 5, 4, 4 },  //layout 0 -> 6 cell {load,map,engspd,coolant,oil,tft,pcmvolt
  { 0, 2, 3, 1, 5, 6, 4 },  //layout 1 -> 6 cell {load,map,engspd,coolant,oil,tft,pcmvolt

And here's the log from that attempt. On display 0 it is stable. I end up in the config menu then back out again and then switching to layout 1 it crashes again seemingly on PID 0104/ENG load.

010B
41 0B 63 


010B
41 0B 63 


010B
CAN ERROR


015C
NO DATA


010B
41 0B 62 


010B
41 0B 63 


010B
41 0B 63 


010B
CAN ERROR


010B
41 0B 63 


010B
41 0B 63 


010B
41 0B 63 


010B
41 0B 63 


010B
41 0B 63 


010B
41 0B 62 


010B
41 0B 63 


010B
41 0B 63 


010B
CAN ERROR


010B
CAN ERROR


010B
CAN ERROR


010B
41 0B 63 


010B
41 0B 63 


010B
41 0B 62 


010B
CAN ERROR


010B
41 0B 63 


Backlight -> dim
010B
41 0B 62 


010B
41 0B 63 


010B
41 0B 63 


010B
41 0B 63 


015C
NO DATA


010B
41 0B 63 


010B
41 0B 63 

.......

-2.2°c
-2.2°c
-1.7°c
-1.7°c
-1.7°c
-1.7°c
-1.7°c
-2.2°c
-1.7°c
-1.7°c
-1.7°c
Display layout -> 0
010B
41 0B 63 


010B
41 0B 63 


-0.6°c
010B
CAN ERROR


010B
41 0B 62 


Display layout -> 1
0104
41 04 00 
41 04 00 
41 04 00 


Guru Meditation Error: Core  1 panic'ed (StoreProhibited). Exception was unhandled.

Core  1 register dump:
PC      : 0x40092728  PS      : 0x00060c30  A0      : 0x800ef03a  A1      : 0x3ffd0790  
A2      : 0xbb9eb0c9  A3      : 0x3ffea250  A4      : 0x00000003  A5      : 0x0000ff00  
A6      : 0x00ff0000  A7      : 0xff000000  A8      : 0x00000000  A9      : 0xbb9eb0c9  
A10     : 0x0000000d  A11     : 0x00000000  A12     : 0x00000003  A13     : 0x0000ff00  
A14     : 0x00ff0000  A15     : 0xff000000  SAR     : 0x00000015  EXCCAUSE: 0x0000001d  
EXCVADDR: 0xbb9eb0c9  LBEG    : 0x4009273c  LEND    : 0x40092741  LCOUNT  : 0x00000000 

@VaAndCob
Copy link
Owner

VaAndCob commented Nov 4, 2024

I notice from the response
010B
41 0B 62

010B
41 0B 63

010B
41 0B 63

010B
CAN ERROR

Display layout -> 1
0104
41 04 00
41 04 00
41 04 00

//----------------------------------

it's like repeatedly reading 010B but sometimes the adaptor gives CAN ERROR or
0104 adaptor returned 41 04 00 for 3 times.

this is my guess, it could be ELM327 adaptor that return data that make esp32 crash.
so I have some few way to clarify the cause.

  1. try compiled firmware
    I'd like you to try this firmware.
    https://github.com/VaAndCob/ESP32-OBD2-Gauge/blob/main/sketch/firmware/VaAndCobOBD2Gauge_T6_nogenuine.bin

it proved that it works (no compiling needed), with this firmware, you can read a few simple PIDs so if you are still facing the crashing problem. It'd be the vehicle or ELM327 adaptor.

  1. Test on another car
    if possible, I'd like you to try your ELM327 adaptor with your firmware on another car too (recommend OBD2 Canbus compatible)
    to be sure that the ELM327 adaptor works well

  2. Handle error or different response from ELM327
    In the original code, we handle errors with "NO DATA\r\n" response from the adaptor, but your adaptor returns something else too (CAN ERROR or something else that I don't know (space, control characters etc..)
    so you have to screen the error and let the correct response data format be calculated as "41 0x aa bb"

I hope this help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants