SlideShare a Scribd company logo
1 of 17
Download to read offline
ELM327 OBD II
An overview of the ELM327 microcontroller
Marco Cuoci
OBD II / EOBD Bus
• OBD stands for On Board Diagnostics
• The OBD bus interconnects sensors and control systems
inside the car
• By law, the OBD must cover all emission relevant
components
• According to the SAE J1962 standard all OBD compliant
vehicles must have a standard connector near the driver’s
seat
• Usually, queries on the bus can just fetch information (no
modify)
Marco Cuoci
ELM327 Microcontroller
• Provides a level of abstraction from the underlying OBD II protocol
Hexadecimal queries and responses are mapped to strings
• Connects directly to the car’s OBD connector
• Presents information via a UART interface
Usually sent to a Bluetooth or Wi-Fi antenna
• Supports a plethora of protocols for the underlying OBD system
Marco Cuoci
ELM327 OBD Interface
• Queries on the OBD bus are
structured hexadecimal values
• One byte to identify the MODE
Ex 01 is current, 03 is to request
trouble codes…
• One to three bytes to identify
the PID (Parameter ID)
As defined in this table
Supported OBD protocols
• SAE J1850 PWM (41.6 kbit/s)
• SAE J1850 VPW (10.4 kbit/s)
• ISO 9141-2 (5 baud init, 10.4 kbit/s)
• ISO 14230-4 KWP (5 baud init, 10.4 kbit/s)
• ISO 14230-4 KWP (fast init, 10.4 kbit/s)
• ISO 15765-4 CAN (11 bit ID, 500 kbit/s)
• ISO 15765-4 CAN (29 bit ID, 500 kbit/s)
• ISO 15765-4 CAN (11 bit ID, 250 kbit/s)
• ISO 15765-4 CAN (29 bit ID, 250 kbit/s)
• SAE J1939 (250kbit/s)
• SAE J1939 (500kbit/s)
Marco Cuoci
ELM327 UART Interface
• The ELM 327 can be accessed by UART at baud rates 9600 or 38400
Fortunately for us, usually the UART interface is wired to an antenna
• The microcontroller acts as an interpreter
Strings sent via the UART interface are converted into hexadecimal data packets
• It can be programmed to do various tasks by issuing an “AT” command
Any query starting with “AT” is directed to the microcontroller, otherwise it is
assumed to be a query for the OBD bus
Marco Cuoci
Querying the ELM327
• In order to query the ELM327, an appropriate instruction set must be
used
There is an AT instruction set for commands directed at the ELM
As well as an OBD instruction set for commands meant for the OBD bus
• Commands are to be sent as strings, terminated by a carriage return
Spaces are ignored
• The command is interpreted and routed to its destination according
to the negotiated protocol
Marco Cuoci
Querying the ELM327
• When the microcontroller receives a response from the OBD bus, it
will wait approx. 200ms before returning
Diagnostic (mode 03-09) queries involve multiple components
The time can be cut to near-zero by issuing the “AT AT2” command
• The value is then returned as a string via the UART interface
Marco Cuoci
A practical example: Overview
• Use an Arduino to communicate over Bluetooth to the ELM327 device
and project real time data to a transparent glass piece using a LCD
• The Arduino should make contextual decisions on what to display
according to the vehicle’s status
Marco Cuoci
A practical example: Hardware Issues
• First problem: How do mirrors work
Mirrors reverse the image, if we were to project directly from the LCD to
the glass piece, we would have an inverted view of the values
Solution: Use two mirrors to reverse the image twice
• Second problem: Apparently having loose cables on the
dashboard of a car is not a good idea
During testing, poor road condition was enough for jumper wires to
come off the breadboard, breaking the circuit and crashing the software
Solution: 50% duct tape, 50% good capable friends
Marco Cuoci
A practical example: Documentation
• Three sets of documentations were used for the project
OBD Instruction Set from the Wikipedia page
ELM Instruction Set from Sparkfun site
ELM Datasheet from ELM electronics site
• Two header files containing definitions for the needed commands
were then produced following the instructions from these documents
ELM327_defines.h
OBD_defines.h
Marco Cuoci
A practical example: Bluetooth Pairing
• For this project the HC-05 Bluetooth module was used
• The Arduino acts as Master, while the ELM327 acts as a slave
• Pairing the HC-05 to the ELM327 requires booting the HC-05 into
command mode and sending “AT” commands from a computer
Marco Cuoci
A practical example: Encoding the data
• The ELM327 accepts strings terminated by a carriage return
• Arduino compilers support C++
• We can make use of the Arduino String library
Handled automatically
Concatenation is an easy supported operation (+)
• Strings are then sent over the Bluetooth interface via the Wire library
Use Wire.println() function for an automatic carriage return at the end
Marco Cuoci
A practical example: Decoding the data
• Data is sent from the ELM327 to the Arduino in string format
• The original command is sent back too as an acknowledgment
• Unnecessary data needs to be cleaned from the response
Use String.replace()
• The string is a hexadecimal number
Use strtol() to convert to a long decimal from a hexadecimal string
• Beware! Different commands have different response lengths!
Marco Cuoci
A practical example: Encoder/Decoder Code
• Transmission is easy
• In order to receive, the data
needs to be ready
• The device returns one byte per
call
• Output may include previous
command or error codes
//Standard query, get packet string
String ELMQuery(String query,int timeout) {
String tmpRXString="";
byte tmpByte = 0;
bool waiting = true;
unsigned long startTime = millis();
//TX
Serial.println(query);
//RX
while(waiting){
if (millis()-startTime>timeout){return -1;}
else if{Serial.available() > 0}{waiting = false;}
delay(10);
}
while(Serial.available() > 0) {
tmpByte = 0;
tmpByte = Serial.read();
tmpRXString = tmpRXString + char(tmpByte);
}
tmpRXString.replace(command,"");
tmpRXString.replace(" ","");
tmpRXString.replace("OK","");
//Errors on the bus mapped to empty string
tmpRXString.replace("STOPPED","");
tmpRXString.replace("SEARCHING","");
tmpRXString.replace("NO DATA","");
tmpRXString.replace("?","");
tmpRXString.replace(",","");
return tmpRXString;
}Marco Cuoci
A practical example: OBD Value Formatting
• OBD values are encoded
according to well defined
formulas
Temperatures are shifted 40 degrees
Celsius up in order to avoid having a
sign bit
RPM is calculated with a .25
granularity
//Value formatting according to OBD formulas
long HandleELMMessage(long payload, String query){
long res = 0;
switch(query){
case OBD_SPEED:
res = payload
break;
case OBD_RPM:
res = payload/4;
break;
case OBD_FUEL_LEVEL:
case OBD_LOAD:
res = payload*100/255;
break;
case OBD_COOLANT:
case OBD_OIL_TEMP:
res = payload-40;
break;
}
return res;
}
Marco Cuoci
A practical example: Program Logic
• We want a real time device
Poll only few devices at a time
• Some data don’t change
frequently
Temperatures and fuel
• Query different devices with
different frequencies
//Print speed and advise if gear shift is necessary
case 4:
resultNMBR = ELMMessagePayload(ELMQuery(OBD_SPEED,1000),OBD_SPEED);
if (resultNMBR < 10){
lcd.noDisplay();
break;
} else {
lcd.display();
}
resultSTR = StringifyELMMEssage(resultNMBR,OBD_SPEED);
lcd.setCursor(6,0);
lcd.print(resultSTR+" ");
//
resultNMBR = ELMMessagePayload(ELMQuery(OBD_RPM,1000),OBD_RPM);
lcd.setCursor(0,0);
lcd.print(" ");
if (resultNMBR > RPM_MAX){
lcd.setCursor(0,0);
lcd.print("*UP*");
} else if (resultNMBR < RPM_MIN){
lcd.setCursor(0,0);
lcd.print("*DN*");
} else {
resultSTR = StringifyELMMEssage(resultNMBR,OBD_RPM);
lcd.setCursor(0,1);
lcd.print(resultSTR.substring(1,3));
}
state = 5;
break;
Marco Cuoci
Thanks for your attention

More Related Content

Recently uploaded

How To Troubleshoot Mercedes Blind Spot Assist Inoperative Error
How To Troubleshoot Mercedes Blind Spot Assist Inoperative ErrorHow To Troubleshoot Mercedes Blind Spot Assist Inoperative Error
How To Troubleshoot Mercedes Blind Spot Assist Inoperative ErrorAndres Auto Service
 
Vip Mumbai Call Girls Mira Road Call On 9920725232 With Body to body massage ...
Vip Mumbai Call Girls Mira Road Call On 9920725232 With Body to body massage ...Vip Mumbai Call Girls Mira Road Call On 9920725232 With Body to body massage ...
Vip Mumbai Call Girls Mira Road Call On 9920725232 With Body to body massage ...amitlee9823
 
83778-77756 ( HER.SELF ) Brings Call Girls In Laxmi Nagar
83778-77756 ( HER.SELF ) Brings Call Girls In Laxmi Nagar83778-77756 ( HER.SELF ) Brings Call Girls In Laxmi Nagar
83778-77756 ( HER.SELF ) Brings Call Girls In Laxmi Nagardollysharma2066
 
一比一原版(PU学位证书)普渡大学毕业证学历认证加急办理
一比一原版(PU学位证书)普渡大学毕业证学历认证加急办理一比一原版(PU学位证书)普渡大学毕业证学历认证加急办理
一比一原版(PU学位证书)普渡大学毕业证学历认证加急办理ezgenuh
 
Escorts Service Rajajinagar ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Rajajinagar ☎ 7737669865☎ Book Your One night Stand (Bangalore)Escorts Service Rajajinagar ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Rajajinagar ☎ 7737669865☎ Book Your One night Stand (Bangalore)amitlee9823
 
Majestic Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore Es...
Majestic Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore Es...Majestic Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore Es...
Majestic Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore Es...amitlee9823
 
8377087607, Door Step Call Girls In Majnu Ka Tilla (Delhi) 24/7 Available
8377087607, Door Step Call Girls In Majnu Ka Tilla (Delhi) 24/7 Available8377087607, Door Step Call Girls In Majnu Ka Tilla (Delhi) 24/7 Available
8377087607, Door Step Call Girls In Majnu Ka Tilla (Delhi) 24/7 Availabledollysharma2066
 
Sanjay Nagar Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalor...
Sanjay Nagar Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalor...Sanjay Nagar Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalor...
Sanjay Nagar Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalor...amitlee9823
 
Top Rated Call Girls Mumbai Central : 9920725232 We offer Beautiful and sexy ...
Top Rated Call Girls Mumbai Central : 9920725232 We offer Beautiful and sexy ...Top Rated Call Girls Mumbai Central : 9920725232 We offer Beautiful and sexy ...
Top Rated Call Girls Mumbai Central : 9920725232 We offer Beautiful and sexy ...amitlee9823
 
BOOK FARIDABAD CALL GIRL(VIP Sunny Leone) @8168257667 BOOK 24/7
BOOK FARIDABAD CALL GIRL(VIP Sunny Leone) @8168257667 BOOK  24/7BOOK FARIDABAD CALL GIRL(VIP Sunny Leone) @8168257667 BOOK  24/7
BOOK FARIDABAD CALL GIRL(VIP Sunny Leone) @8168257667 BOOK 24/7Hyderabad Escorts Agency
 
FULL NIGHT — 9999894380 Call Girls In Jagat Puri | Delhi
FULL NIGHT — 9999894380 Call Girls In Jagat Puri | DelhiFULL NIGHT — 9999894380 Call Girls In Jagat Puri | Delhi
FULL NIGHT — 9999894380 Call Girls In Jagat Puri | DelhiSaketCallGirlsCallUs
 
➥🔝 7737669865 🔝▻ pathankot Call-girls in Women Seeking Men 🔝pathankot🔝 Esc...
➥🔝 7737669865 🔝▻ pathankot Call-girls in Women Seeking Men  🔝pathankot🔝   Esc...➥🔝 7737669865 🔝▻ pathankot Call-girls in Women Seeking Men  🔝pathankot🔝   Esc...
➥🔝 7737669865 🔝▻ pathankot Call-girls in Women Seeking Men 🔝pathankot🔝 Esc...nirzagarg
 
Connaught Place, Delhi Call girls :8448380779 Model Escorts | 100% verified
Connaught Place, Delhi Call girls :8448380779 Model Escorts | 100% verifiedConnaught Place, Delhi Call girls :8448380779 Model Escorts | 100% verified
Connaught Place, Delhi Call girls :8448380779 Model Escorts | 100% verifiedDelhi Call girls
 
Rekha Agarkar Escorts Service Kollam ❣️ 7014168258 ❣️ High Cost Unlimited Har...
Rekha Agarkar Escorts Service Kollam ❣️ 7014168258 ❣️ High Cost Unlimited Har...Rekha Agarkar Escorts Service Kollam ❣️ 7014168258 ❣️ High Cost Unlimited Har...
Rekha Agarkar Escorts Service Kollam ❣️ 7014168258 ❣️ High Cost Unlimited Har...nirzagarg
 
John Deere 335 375 385 435 Service Repair Manual
John Deere 335 375 385 435 Service Repair ManualJohn Deere 335 375 385 435 Service Repair Manual
John Deere 335 375 385 435 Service Repair ManualExcavator
 
➥🔝 7737669865 🔝▻ Bhiwandi Call-girls in Women Seeking Men 🔝Bhiwandi🔝 Escor...
➥🔝 7737669865 🔝▻ Bhiwandi Call-girls in Women Seeking Men  🔝Bhiwandi🔝   Escor...➥🔝 7737669865 🔝▻ Bhiwandi Call-girls in Women Seeking Men  🔝Bhiwandi🔝   Escor...
➥🔝 7737669865 🔝▻ Bhiwandi Call-girls in Women Seeking Men 🔝Bhiwandi🔝 Escor...amitlee9823
 
John deere 425 445 455 Maitenance Manual
John deere 425 445 455 Maitenance ManualJohn deere 425 445 455 Maitenance Manual
John deere 425 445 455 Maitenance ManualExcavator
 
Vip Mumbai Call Girls Colaba Call On 9920725232 With Body to body massage wit...
Vip Mumbai Call Girls Colaba Call On 9920725232 With Body to body massage wit...Vip Mumbai Call Girls Colaba Call On 9920725232 With Body to body massage wit...
Vip Mumbai Call Girls Colaba Call On 9920725232 With Body to body massage wit...amitlee9823
 

Recently uploaded (20)

How To Troubleshoot Mercedes Blind Spot Assist Inoperative Error
How To Troubleshoot Mercedes Blind Spot Assist Inoperative ErrorHow To Troubleshoot Mercedes Blind Spot Assist Inoperative Error
How To Troubleshoot Mercedes Blind Spot Assist Inoperative Error
 
Vip Mumbai Call Girls Mira Road Call On 9920725232 With Body to body massage ...
Vip Mumbai Call Girls Mira Road Call On 9920725232 With Body to body massage ...Vip Mumbai Call Girls Mira Road Call On 9920725232 With Body to body massage ...
Vip Mumbai Call Girls Mira Road Call On 9920725232 With Body to body massage ...
 
83778-77756 ( HER.SELF ) Brings Call Girls In Laxmi Nagar
83778-77756 ( HER.SELF ) Brings Call Girls In Laxmi Nagar83778-77756 ( HER.SELF ) Brings Call Girls In Laxmi Nagar
83778-77756 ( HER.SELF ) Brings Call Girls In Laxmi Nagar
 
一比一原版(PU学位证书)普渡大学毕业证学历认证加急办理
一比一原版(PU学位证书)普渡大学毕业证学历认证加急办理一比一原版(PU学位证书)普渡大学毕业证学历认证加急办理
一比一原版(PU学位证书)普渡大学毕业证学历认证加急办理
 
Escorts Service Rajajinagar ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Rajajinagar ☎ 7737669865☎ Book Your One night Stand (Bangalore)Escorts Service Rajajinagar ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Rajajinagar ☎ 7737669865☎ Book Your One night Stand (Bangalore)
 
Majestic Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore Es...
Majestic Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore Es...Majestic Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore Es...
Majestic Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore Es...
 
8377087607, Door Step Call Girls In Majnu Ka Tilla (Delhi) 24/7 Available
8377087607, Door Step Call Girls In Majnu Ka Tilla (Delhi) 24/7 Available8377087607, Door Step Call Girls In Majnu Ka Tilla (Delhi) 24/7 Available
8377087607, Door Step Call Girls In Majnu Ka Tilla (Delhi) 24/7 Available
 
Sanjay Nagar Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalor...
Sanjay Nagar Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalor...Sanjay Nagar Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalor...
Sanjay Nagar Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalor...
 
Top Rated Call Girls Mumbai Central : 9920725232 We offer Beautiful and sexy ...
Top Rated Call Girls Mumbai Central : 9920725232 We offer Beautiful and sexy ...Top Rated Call Girls Mumbai Central : 9920725232 We offer Beautiful and sexy ...
Top Rated Call Girls Mumbai Central : 9920725232 We offer Beautiful and sexy ...
 
BOOK FARIDABAD CALL GIRL(VIP Sunny Leone) @8168257667 BOOK 24/7
BOOK FARIDABAD CALL GIRL(VIP Sunny Leone) @8168257667 BOOK  24/7BOOK FARIDABAD CALL GIRL(VIP Sunny Leone) @8168257667 BOOK  24/7
BOOK FARIDABAD CALL GIRL(VIP Sunny Leone) @8168257667 BOOK 24/7
 
FULL NIGHT — 9999894380 Call Girls In Jagat Puri | Delhi
FULL NIGHT — 9999894380 Call Girls In Jagat Puri | DelhiFULL NIGHT — 9999894380 Call Girls In Jagat Puri | Delhi
FULL NIGHT — 9999894380 Call Girls In Jagat Puri | Delhi
 
➥🔝 7737669865 🔝▻ pathankot Call-girls in Women Seeking Men 🔝pathankot🔝 Esc...
➥🔝 7737669865 🔝▻ pathankot Call-girls in Women Seeking Men  🔝pathankot🔝   Esc...➥🔝 7737669865 🔝▻ pathankot Call-girls in Women Seeking Men  🔝pathankot🔝   Esc...
➥🔝 7737669865 🔝▻ pathankot Call-girls in Women Seeking Men 🔝pathankot🔝 Esc...
 
(INDIRA) Call Girl Nashik Call Now 8617697112 Nashik Escorts 24x7
(INDIRA) Call Girl Nashik Call Now 8617697112 Nashik Escorts 24x7(INDIRA) Call Girl Nashik Call Now 8617697112 Nashik Escorts 24x7
(INDIRA) Call Girl Nashik Call Now 8617697112 Nashik Escorts 24x7
 
Connaught Place, Delhi Call girls :8448380779 Model Escorts | 100% verified
Connaught Place, Delhi Call girls :8448380779 Model Escorts | 100% verifiedConnaught Place, Delhi Call girls :8448380779 Model Escorts | 100% verified
Connaught Place, Delhi Call girls :8448380779 Model Escorts | 100% verified
 
Rekha Agarkar Escorts Service Kollam ❣️ 7014168258 ❣️ High Cost Unlimited Har...
Rekha Agarkar Escorts Service Kollam ❣️ 7014168258 ❣️ High Cost Unlimited Har...Rekha Agarkar Escorts Service Kollam ❣️ 7014168258 ❣️ High Cost Unlimited Har...
Rekha Agarkar Escorts Service Kollam ❣️ 7014168258 ❣️ High Cost Unlimited Har...
 
John Deere 335 375 385 435 Service Repair Manual
John Deere 335 375 385 435 Service Repair ManualJohn Deere 335 375 385 435 Service Repair Manual
John Deere 335 375 385 435 Service Repair Manual
 
➥🔝 7737669865 🔝▻ Bhiwandi Call-girls in Women Seeking Men 🔝Bhiwandi🔝 Escor...
➥🔝 7737669865 🔝▻ Bhiwandi Call-girls in Women Seeking Men  🔝Bhiwandi🔝   Escor...➥🔝 7737669865 🔝▻ Bhiwandi Call-girls in Women Seeking Men  🔝Bhiwandi🔝   Escor...
➥🔝 7737669865 🔝▻ Bhiwandi Call-girls in Women Seeking Men 🔝Bhiwandi🔝 Escor...
 
Stay Cool and Compliant: Know Your Window Tint Laws Before You Tint
Stay Cool and Compliant: Know Your Window Tint Laws Before You TintStay Cool and Compliant: Know Your Window Tint Laws Before You Tint
Stay Cool and Compliant: Know Your Window Tint Laws Before You Tint
 
John deere 425 445 455 Maitenance Manual
John deere 425 445 455 Maitenance ManualJohn deere 425 445 455 Maitenance Manual
John deere 425 445 455 Maitenance Manual
 
Vip Mumbai Call Girls Colaba Call On 9920725232 With Body to body massage wit...
Vip Mumbai Call Girls Colaba Call On 9920725232 With Body to body massage wit...Vip Mumbai Call Girls Colaba Call On 9920725232 With Body to body massage wit...
Vip Mumbai Call Girls Colaba Call On 9920725232 With Body to body massage wit...
 

Featured

How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationErica Santiago
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellSaba Software
 
Introduction to C Programming Language
Introduction to C Programming LanguageIntroduction to C Programming Language
Introduction to C Programming LanguageSimplilearn
 

Featured (20)

How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
 
Introduction to C Programming Language
Introduction to C Programming LanguageIntroduction to C Programming Language
Introduction to C Programming Language
 

Elm327 obd II - Arduino HUD

  • 1. ELM327 OBD II An overview of the ELM327 microcontroller Marco Cuoci
  • 2. OBD II / EOBD Bus • OBD stands for On Board Diagnostics • The OBD bus interconnects sensors and control systems inside the car • By law, the OBD must cover all emission relevant components • According to the SAE J1962 standard all OBD compliant vehicles must have a standard connector near the driver’s seat • Usually, queries on the bus can just fetch information (no modify) Marco Cuoci
  • 3. ELM327 Microcontroller • Provides a level of abstraction from the underlying OBD II protocol Hexadecimal queries and responses are mapped to strings • Connects directly to the car’s OBD connector • Presents information via a UART interface Usually sent to a Bluetooth or Wi-Fi antenna • Supports a plethora of protocols for the underlying OBD system Marco Cuoci
  • 4. ELM327 OBD Interface • Queries on the OBD bus are structured hexadecimal values • One byte to identify the MODE Ex 01 is current, 03 is to request trouble codes… • One to three bytes to identify the PID (Parameter ID) As defined in this table Supported OBD protocols • SAE J1850 PWM (41.6 kbit/s) • SAE J1850 VPW (10.4 kbit/s) • ISO 9141-2 (5 baud init, 10.4 kbit/s) • ISO 14230-4 KWP (5 baud init, 10.4 kbit/s) • ISO 14230-4 KWP (fast init, 10.4 kbit/s) • ISO 15765-4 CAN (11 bit ID, 500 kbit/s) • ISO 15765-4 CAN (29 bit ID, 500 kbit/s) • ISO 15765-4 CAN (11 bit ID, 250 kbit/s) • ISO 15765-4 CAN (29 bit ID, 250 kbit/s) • SAE J1939 (250kbit/s) • SAE J1939 (500kbit/s) Marco Cuoci
  • 5. ELM327 UART Interface • The ELM 327 can be accessed by UART at baud rates 9600 or 38400 Fortunately for us, usually the UART interface is wired to an antenna • The microcontroller acts as an interpreter Strings sent via the UART interface are converted into hexadecimal data packets • It can be programmed to do various tasks by issuing an “AT” command Any query starting with “AT” is directed to the microcontroller, otherwise it is assumed to be a query for the OBD bus Marco Cuoci
  • 6. Querying the ELM327 • In order to query the ELM327, an appropriate instruction set must be used There is an AT instruction set for commands directed at the ELM As well as an OBD instruction set for commands meant for the OBD bus • Commands are to be sent as strings, terminated by a carriage return Spaces are ignored • The command is interpreted and routed to its destination according to the negotiated protocol Marco Cuoci
  • 7. Querying the ELM327 • When the microcontroller receives a response from the OBD bus, it will wait approx. 200ms before returning Diagnostic (mode 03-09) queries involve multiple components The time can be cut to near-zero by issuing the “AT AT2” command • The value is then returned as a string via the UART interface Marco Cuoci
  • 8. A practical example: Overview • Use an Arduino to communicate over Bluetooth to the ELM327 device and project real time data to a transparent glass piece using a LCD • The Arduino should make contextual decisions on what to display according to the vehicle’s status Marco Cuoci
  • 9. A practical example: Hardware Issues • First problem: How do mirrors work Mirrors reverse the image, if we were to project directly from the LCD to the glass piece, we would have an inverted view of the values Solution: Use two mirrors to reverse the image twice • Second problem: Apparently having loose cables on the dashboard of a car is not a good idea During testing, poor road condition was enough for jumper wires to come off the breadboard, breaking the circuit and crashing the software Solution: 50% duct tape, 50% good capable friends Marco Cuoci
  • 10. A practical example: Documentation • Three sets of documentations were used for the project OBD Instruction Set from the Wikipedia page ELM Instruction Set from Sparkfun site ELM Datasheet from ELM electronics site • Two header files containing definitions for the needed commands were then produced following the instructions from these documents ELM327_defines.h OBD_defines.h Marco Cuoci
  • 11. A practical example: Bluetooth Pairing • For this project the HC-05 Bluetooth module was used • The Arduino acts as Master, while the ELM327 acts as a slave • Pairing the HC-05 to the ELM327 requires booting the HC-05 into command mode and sending “AT” commands from a computer Marco Cuoci
  • 12. A practical example: Encoding the data • The ELM327 accepts strings terminated by a carriage return • Arduino compilers support C++ • We can make use of the Arduino String library Handled automatically Concatenation is an easy supported operation (+) • Strings are then sent over the Bluetooth interface via the Wire library Use Wire.println() function for an automatic carriage return at the end Marco Cuoci
  • 13. A practical example: Decoding the data • Data is sent from the ELM327 to the Arduino in string format • The original command is sent back too as an acknowledgment • Unnecessary data needs to be cleaned from the response Use String.replace() • The string is a hexadecimal number Use strtol() to convert to a long decimal from a hexadecimal string • Beware! Different commands have different response lengths! Marco Cuoci
  • 14. A practical example: Encoder/Decoder Code • Transmission is easy • In order to receive, the data needs to be ready • The device returns one byte per call • Output may include previous command or error codes //Standard query, get packet string String ELMQuery(String query,int timeout) { String tmpRXString=""; byte tmpByte = 0; bool waiting = true; unsigned long startTime = millis(); //TX Serial.println(query); //RX while(waiting){ if (millis()-startTime>timeout){return -1;} else if{Serial.available() > 0}{waiting = false;} delay(10); } while(Serial.available() > 0) { tmpByte = 0; tmpByte = Serial.read(); tmpRXString = tmpRXString + char(tmpByte); } tmpRXString.replace(command,""); tmpRXString.replace(" ",""); tmpRXString.replace("OK",""); //Errors on the bus mapped to empty string tmpRXString.replace("STOPPED",""); tmpRXString.replace("SEARCHING",""); tmpRXString.replace("NO DATA",""); tmpRXString.replace("?",""); tmpRXString.replace(",",""); return tmpRXString; }Marco Cuoci
  • 15. A practical example: OBD Value Formatting • OBD values are encoded according to well defined formulas Temperatures are shifted 40 degrees Celsius up in order to avoid having a sign bit RPM is calculated with a .25 granularity //Value formatting according to OBD formulas long HandleELMMessage(long payload, String query){ long res = 0; switch(query){ case OBD_SPEED: res = payload break; case OBD_RPM: res = payload/4; break; case OBD_FUEL_LEVEL: case OBD_LOAD: res = payload*100/255; break; case OBD_COOLANT: case OBD_OIL_TEMP: res = payload-40; break; } return res; } Marco Cuoci
  • 16. A practical example: Program Logic • We want a real time device Poll only few devices at a time • Some data don’t change frequently Temperatures and fuel • Query different devices with different frequencies //Print speed and advise if gear shift is necessary case 4: resultNMBR = ELMMessagePayload(ELMQuery(OBD_SPEED,1000),OBD_SPEED); if (resultNMBR < 10){ lcd.noDisplay(); break; } else { lcd.display(); } resultSTR = StringifyELMMEssage(resultNMBR,OBD_SPEED); lcd.setCursor(6,0); lcd.print(resultSTR+" "); // resultNMBR = ELMMessagePayload(ELMQuery(OBD_RPM,1000),OBD_RPM); lcd.setCursor(0,0); lcd.print(" "); if (resultNMBR > RPM_MAX){ lcd.setCursor(0,0); lcd.print("*UP*"); } else if (resultNMBR < RPM_MIN){ lcd.setCursor(0,0); lcd.print("*DN*"); } else { resultSTR = StringifyELMMEssage(resultNMBR,OBD_RPM); lcd.setCursor(0,1); lcd.print(resultSTR.substring(1,3)); } state = 5; break; Marco Cuoci
  • 17. Thanks for your attention