Top Banner
Arduino-based OBD-II Interface and Data Logger CS 497 Independent Study Ryan Miller Advisor: Prof. Douglas Comer April 26, 2011
30

Arduino-based OBD-II Interface and Data Loggerrvmiller.com/present/CS497_presentation_miller.pdf · Arduino-based OBD-II Interface and Data Logger CS 497 Independent Study Ryan Miller

May 14, 2018

Download

Documents

lykiet
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Arduino-based OBD-II Interface and Data Loggerrvmiller.com/present/CS497_presentation_miller.pdf · Arduino-based OBD-II Interface and Data Logger CS 497 Independent Study Ryan Miller

Arduino-based OBD-II Interface and Data Logger CS 497 Independent Study Ryan Miller

Advisor: Prof. Douglas Comer April 26, 2011

Page 2: Arduino-based OBD-II Interface and Data Loggerrvmiller.com/present/CS497_presentation_miller.pdf · Arduino-based OBD-II Interface and Data Logger CS 497 Independent Study Ryan Miller

Arduino

•  Italy 2005

• ATmega328 microcontroller • 14 digital I/O pins • 16 MHz clock speed • 32 KB memory • About $30 online

Arduino

Hardware

Automotive OBD

ISO Interface

Software

Data

Conclusions

Page 3: Arduino-based OBD-II Interface and Data Loggerrvmiller.com/present/CS497_presentation_miller.pdf · Arduino-based OBD-II Interface and Data Logger CS 497 Independent Study Ryan Miller

Arduino • Program “sketches” in Multi-platform Java-based IDE • Code in C/C++ • Serial Communication (currently USB)

Page 4: Arduino-based OBD-II Interface and Data Loggerrvmiller.com/present/CS497_presentation_miller.pdf · Arduino-based OBD-II Interface and Data Logger CS 497 Independent Study Ryan Miller

Hardware

• Goals of this project:

• Communicate with an automotive engine control unit (ECU) via the Arduino

• Gather and record instantaneous data that is reported by the vehicle

Arduino

Hardware

Automotive OBD

ISO Interface

Software

Data

Conclusions

?

Page 5: Arduino-based OBD-II Interface and Data Loggerrvmiller.com/present/CS497_presentation_miller.pdf · Arduino-based OBD-II Interface and Data Logger CS 497 Independent Study Ryan Miller

Hardware • Vehicles produced in the U.S. after 1996 are required to have an OBD-II (on-board diagnostic) connector

Page 6: Arduino-based OBD-II Interface and Data Loggerrvmiller.com/present/CS497_presentation_miller.pdf · Arduino-based OBD-II Interface and Data Logger CS 497 Independent Study Ryan Miller

Hardware • OBD-II Interface • Very simple connection for most applications • Most important pins •  K-Line •  Ground •  +12V

Page 7: Arduino-based OBD-II Interface and Data Loggerrvmiller.com/present/CS497_presentation_miller.pdf · Arduino-based OBD-II Interface and Data Logger CS 497 Independent Study Ryan Miller

Hardware • Open-source project called “OBDuino” offered the interface schematic (which is fortunate, because I am not an EE major)

Page 8: Arduino-based OBD-II Interface and Data Loggerrvmiller.com/present/CS497_presentation_miller.pdf · Arduino-based OBD-II Interface and Data Logger CS 497 Independent Study Ryan Miller

Hardware • Open-source project called “OBDuino” offered the interface schematic (which is fortunate, because I am not an EE major)

Page 9: Arduino-based OBD-II Interface and Data Loggerrvmiller.com/present/CS497_presentation_miller.pdf · Arduino-based OBD-II Interface and Data Logger CS 497 Independent Study Ryan Miller

Hardware •  Freescale MC33290 handles the tricky parts • K-Line, Ground, and +12V go in

• Serial Tx/Rx come out

Page 10: Arduino-based OBD-II Interface and Data Loggerrvmiller.com/present/CS497_presentation_miller.pdf · Arduino-based OBD-II Interface and Data Logger CS 497 Independent Study Ryan Miller

Hardware

OBD-II

Page 11: Arduino-based OBD-II Interface and Data Loggerrvmiller.com/present/CS497_presentation_miller.pdf · Arduino-based OBD-II Interface and Data Logger CS 497 Independent Study Ryan Miller

Software

• A few functions to perform:

•  Initialize ISO connection

• Request data from vehicle’s ECU

• Display the result on the LCD and record the value to retrieve later

Arduino

Hardware

Automotive OBD

ISO Interface

Software

Data

Conclusions

Page 12: Arduino-based OBD-II Interface and Data Loggerrvmiller.com/present/CS497_presentation_miller.pdf · Arduino-based OBD-II Interface and Data Logger CS 497 Independent Study Ryan Miller

Software •  Initialization: •  Starts by “bit-banging” 0x33 at 5 baud •  i.e.

0 0 1 1 0 0 1 1

200ms pause = 1.6 seconds

Page 13: Arduino-based OBD-II Interface and Data Loggerrvmiller.com/present/CS497_presentation_miller.pdf · Arduino-based OBD-II Interface and Data Logger CS 497 Independent Study Ryan Miller

Software •  Initialization: •  Starts by “bit-banging” 0x33 at 5 baud •  Code:

byte  b  =  0x33;    for  (byte  mask  =  0x01;  mask;  mask  <<=  1)  {  

 if  (b  &  mask)  //  Choose  bit      digitalWrite(K_OUT,  HIGH);  //  Send  1    else      digitalWrite(K_OUT,  LOW);  //  Send  0        delay(200);  

}  

Page 14: Arduino-based OBD-II Interface and Data Loggerrvmiller.com/present/CS497_presentation_miller.pdf · Arduino-based OBD-II Interface and Data Logger CS 497 Independent Study Ryan Miller

Software • Then you can start 10.4 kbps communication and perform these steps to finish initialization:

Page 15: Arduino-based OBD-II Interface and Data Loggerrvmiller.com/present/CS497_presentation_miller.pdf · Arduino-based OBD-II Interface and Data Logger CS 497 Independent Study Ryan Miller

Software • Parameter IDs (PIDs) • SAE J1979 standard

• Examples:

PID Bytes Description Formula

0x0C 2 Engine RPM ((A*256)+B)/4

0x0D 1 Vehicle Speed (km/h) A

0x11 1 Throttle Position (%) A*100/255

0x3F 2 Catalyst Temp (B2, S2) ((A*256)+B)/10 - 40

Page 16: Arduino-based OBD-II Interface and Data Loggerrvmiller.com/present/CS497_presentation_miller.pdf · Arduino-based OBD-II Interface and Data Logger CS 497 Independent Study Ryan Miller

Software • Steps:

1.  Request PID with hex value 2.  Continuously read data from ISO until successful

checksum or timeout 3.  Convert returned value with formula 4.  Display / record value and repeat

Page 17: Arduino-based OBD-II Interface and Data Loggerrvmiller.com/present/CS497_presentation_miller.pdf · Arduino-based OBD-II Interface and Data Logger CS 497 Independent Study Ryan Miller

Software 1. Request PID with hex value

Index Value Description

0 0x68 SAE J1979 standard

1 0x6A OBD-II request

2 0xF1 Off-board tool

3 0x01 Mode 1 PIDs

4 pid Hex value for PID requested

5 Checksum Computed from message

byte  message[6];  

for  (int  i  =  0;  i  <  6;  i++)    iso_write_byte(message[i]);  

Page 18: Arduino-based OBD-II Interface and Data Loggerrvmiller.com/present/CS497_presentation_miller.pdf · Arduino-based OBD-II Interface and Data Logger CS 497 Independent Study Ryan Miller

Software 2. Continuously read data from ISO until successful checksum or timeout

Byte(s) Description

0 Message Header 1

1 Message Header 2

2 Source Address

3 – 9 Data (up to 7 bytes)

Final byte Checksum

byte  buf[11];  

Page 19: Arduino-based OBD-II Interface and Data Loggerrvmiller.com/present/CS497_presentation_miller.pdf · Arduino-based OBD-II Interface and Data Logger CS 497 Independent Study Ryan Miller

Software 3. Convert returned value with formula ie.:

PID Bytes Description Formula

0x0C 2 Engine RPM ((A*256)+B)/4

double  rpm;    rpm  =  ((double)buf[0]  *  256)  +  (double)buf[1])  /  4.0;  

Page 20: Arduino-based OBD-II Interface and Data Loggerrvmiller.com/present/CS497_presentation_miller.pdf · Arduino-based OBD-II Interface and Data Logger CS 497 Independent Study Ryan Miller

Software 4. Record/display value and repeat •  Displaying on an LCD screen:

LiquidCrystal  lcd;    lcd.print(rpm);    

Page 21: Arduino-based OBD-II Interface and Data Loggerrvmiller.com/present/CS497_presentation_miller.pdf · Arduino-based OBD-II Interface and Data Logger CS 497 Independent Study Ryan Miller

Software 4. Record/display value and repeat •  Writing to an SD card:

File  log;    log.print(rpm);    

Page 22: Arduino-based OBD-II Interface and Data Loggerrvmiller.com/present/CS497_presentation_miller.pdf · Arduino-based OBD-II Interface and Data Logger CS 497 Independent Study Ryan Miller

Software • One last note on PIDs…

• This gives you the rate of air in grams / second

PID Bytes Description Formula

0x10 2 Mass Air Flow Rate ((A*256)+B)/100

Page 23: Arduino-based OBD-II Interface and Data Loggerrvmiller.com/present/CS497_presentation_miller.pdf · Arduino-based OBD-II Interface and Data Logger CS 497 Independent Study Ryan Miller

Software •  You can convert into

• And then use vehicle speed to convert to

or MPG

g airs

gal gasolineh

milesgal gasoline

Page 24: Arduino-based OBD-II Interface and Data Loggerrvmiller.com/present/CS497_presentation_miller.pdf · Arduino-based OBD-II Interface and Data Logger CS 497 Independent Study Ryan Miller

Data

• Scanned four PIDs over a 20-minute interval every 1-2 seconds

• Vehicle Speed

• Engine RPM

• Engine Coolant

• Calculated MPG

Arduino

Hardware

Automotive OBD

ISO Interface

Software

Data

Conclusions

Page 25: Arduino-based OBD-II Interface and Data Loggerrvmiller.com/present/CS497_presentation_miller.pdf · Arduino-based OBD-II Interface and Data Logger CS 497 Independent Study Ryan Miller

Data

mph

Page 26: Arduino-based OBD-II Interface and Data Loggerrvmiller.com/present/CS497_presentation_miller.pdf · Arduino-based OBD-II Interface and Data Logger CS 497 Independent Study Ryan Miller

Data

mph rpm

Page 27: Arduino-based OBD-II Interface and Data Loggerrvmiller.com/present/CS497_presentation_miller.pdf · Arduino-based OBD-II Interface and Data Logger CS 497 Independent Study Ryan Miller

Data

°C

Page 28: Arduino-based OBD-II Interface and Data Loggerrvmiller.com/present/CS497_presentation_miller.pdf · Arduino-based OBD-II Interface and Data Logger CS 497 Independent Study Ryan Miller

Data

mph °C

Page 29: Arduino-based OBD-II Interface and Data Loggerrvmiller.com/present/CS497_presentation_miller.pdf · Arduino-based OBD-II Interface and Data Logger CS 497 Independent Study Ryan Miller

Conclusions

• Embedded computing is ubiquitous

• Massive amounts of data generated by everyday machines

• Elec. Engineering and CS can come together to make some pretty cool things

Arduino

Hardware

Automotive OBD

ISO Interface

Software

Data

Conclusions

Page 30: Arduino-based OBD-II Interface and Data Loggerrvmiller.com/present/CS497_presentation_miller.pdf · Arduino-based OBD-II Interface and Data Logger CS 497 Independent Study Ryan Miller

Questions?