|
Forum Index : Microcontroller and PC projects : Auto CAN Bus Interface via MM?
| Author | Message | ||||
| Andrew_G Guru Joined: 18/10/2016 Location: AustraliaPosts: 872 |
Hi, I (and my mechanics) have spent months tracking a problem with my beloved car, "the beast" (a 1997 VS Holden Statesman V8 - 250k, barely run in). It would have been easier to diagnose with on-board access to the fault codes via the CAN bus (I think it uses OBD1 but I'm not yet sure). Are any of you aware of MM and MMBasic projects that would enable me to access the codes (and potentially other data) off the bus? (there are lot of expensive products for mechanics and workshops (which my mechanics have) but I am more interested in a DIY approach - if possible). Thanks, Andrew |
||||
| lew247 Guru Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
ODB2 dignostic tester (click this) IT's a lot cheaper than anything you can build, works great and you can get software for your android phone that interfaces with it and not only tells you the code problems and other information but you can also clear the faults from the ecu Works with all OBD-II compliant vehicles I've had one for a few years and it's great EDIT: and its great for anything OBD-II EDIT 2: IF you use the car make/model search on the page it says "This item does not fit Holden Statesman 1997 VS [1995-1999] Saloon" However it will and does work as confirmed HERE |
||||
| CaptainBoing Guru Joined: 07/09/2016 Location: United KingdomPosts: 2171 |
+1 Bluetooth to your moby is the way to go. Search your favourite App store for "Torque Lite" (free version) will show the codes etc on the run and gives basic performance graphs etc. there are other options including paid that will give enhanced data but I have never needed anything more. It does allow you to selectively clear fault codes too. There was a version of MMBasic that supported CAN (V4.something? maybe see here as a thing to get you going? : http://www.thebackshed.com/forum/forum_posts.asp?TID=4702 I think it was for MaxiMite) and you can get CANBUS interface modules cheaply on ebay so if you still want to go down that route it is do-able. I wouldn't recommend using an old version of the language but CAN can be programmed reasonably easily... maybe someone on here has CFunctions for it |
||||
| lew247 Guru Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
You can also get the full version of Torque off certain sites - and it works great - does everything you'll ever need The only thing it doesn't do is tell you what the fault codes mean, but you can look that up on google, you'll have your phone with you anyway to run the app |
||||
| JohnS Guru Joined: 18/11/2011 Location: United KingdomPosts: 4126 |
+1 on an elm327 You can get BT, WiFi & USB versions - pick which suits you. If you need help with codes etc post 'em... Don't just clear them as you'll lose data and may cause further trouble. Even if / when no codes, at least check fuel trims (LTFTs) parked with a hot engine. Should be near zero. John |
||||
| CaptainBoing Guru Joined: 07/09/2016 Location: United KingdomPosts: 2171 |
OBDII generic fault codes 2017-09-14_113945_OBDII_Generic.zip you'll probably still end up googling to find more info but this is a quick get-you-going list |
||||
| Andrew_G Guru Joined: 18/10/2016 Location: AustraliaPosts: 872 |
Many thanks for your replies. Yes the ELM327 looks interesting. Do any of you know if the USB version sends out a usable (eg serial?) data stream? You helped me change my search to "CANBUS", rather than "CAN BUS", which yielded much more useful results. The material on here looks a little dated and more complicated than I had hoped eg there is reference to "CANVIEW.BAS" but I couldn't see any BASIC code (but plenty of C - ugh). Cheers, Andrew (PS "the beast" is running well now with a new crankshaft position sensor (new distributor) at no charge from the service people (JustService - in Moorrabbin, Melbourne)) |
||||
| JohnS Guru Joined: 18/11/2011 Location: United KingdomPosts: 4126 |
The common USB elm327 has the DLC (OBD connector) on one end and a USB A on the other. You can plug it into a PC and fire up either specific OBD software or a terminal emulator (e.g. Windows HyperTerminal, Linux minicom or screen or ...) and talk straight to it. (It's what some call a virtual COM port.) A typical car now has several OBD-style interfaces at the DLC, on the defined and often on the reserved pins. It really helps to have the car's electrical diagrams. E.g. a car I had a while back had ISO-9141 K-line (pin 7), Ford's SCP (pins 2 & 10) and CAN (6 & 14). An elm327 can talk to the standard ones but only one at a time (you can switch between them should you wish to). Note: you typically need the car's ignition on (or engine on) to power the DLC and thus the elm. There are excellent data sheets on the elm site Elm Electronics It's a bit like the modems of old, with AT... commands. The USB version (elm327) is basically a serial-USB chip connected to the elm chip. You can get the basic elm chip from elm (choice of protocols) or take apart a USB elm327 if you just want direct access to the serial data. The elm site even has Gerbers (or links to them), schematics, etc. John |
||||
| Andrew_G Guru Joined: 18/10/2016 Location: AustraliaPosts: 872 |
John, thanks. That's just what I wanted to hear. I want to be able to download the fault codes via the ELM327 device (on the rare occasion there is a fault) OR capture and display other data. The main data I am looking to capture is the speed - I have made a nifty little display of digital speed via a GPS. A button press shows the current and average speed since the last button press. We have several "Point to Point" speed detection sites that measure your average speed over x km - x varies from 2 to 50+ km. They read your number plate and send the fine in the mail (the allowance is only 2kph). The GPS is good except I go through a couple of tunnels and it all drops out. By capturing the vehicle speedometer it adds another check. (I might even go back to Traffic Engineering 101 and look at Space Mean Speed vs Time Mean Speed). Thanks again, Andrew. |
||||
| JohnS Guru Joined: 18/11/2011 Location: United KingdomPosts: 4126 |
Speed is easy. It may well read a bit different to the dash (speedo) as usually those over-read. Speed is PID 0D (hex) e.g. see OBD PIDs (That page refers to modes but that's not their official name.) Any OBD app will typically show it but it's quite easy by hand / by own program. GPS and OBD speeds may differ not least due to GPS issues but also your wheel (tyre) size varies with wear, pressure etc. Not usually a big issue... John |
||||
| Andrew_G Guru Joined: 18/10/2016 Location: AustraliaPosts: 872 |
Hi again, it is NOT a big deal as I only spent less than $20, and the beast is running well, but: The Elm327 (USB) device arrived a few days ago and has some drivers and software "ScanTool.net v1.21" on a CD. I can't get it to fire up and configure the comm port (it locks in the main menu). At that price the seller is likely to stick to their fine print "all care and no responsibility . . ." for the s/w. The only Torque s/w I can see is for phones etc. (rather than an old laptop running XP). I've tried Hyperterminal (which I'm comfortable with) but can't get any response to AT commands. If I could crack hyperterminal I'd have a chance of reading speed etc. Any comments/suggestions? (as I say above NOT a big deal) Cheers, Andrew |
||||
| retepsnikrep Senior Member Joined: 31/12/2007 Location: United KingdomPosts: 134 |
I think building your own OBDII reader from scratch is more fun. First of all read the wiki about the OBDII protocol and what to expect. I used picbasic pro in my projects to program bare 12F683 & 16F886 pics and later 18F2680 can enabled pics for OBDII KLine and later canbus work... This KLine example below might give you a few clues and will probably translate fairly easily into Maximite basic.. Once you get started and have something working with KLine stuff then you can read up about canbus which is a very different much more complicated beast.. The ELM327 datasheets and example schematics were very useful to build the basic hardware interface to the OBDII port 12v KLine. (You just need an NPN transistor, base current limit resistor and and pull up resistor IIRC) I obviously did not use the elm chip itself but programmed my own microcontroller. '------- Picbasic Pro Compiler version PIC12F683 - 040911 - V0.06 Alpha ------- '-------------- Note this software requires the MPASM assembler ---------------- '------------------------------------------------------------------------------- '**************************** General Information ****************************** 'This module carries no warranty or guarantee of any kind! It is used at 'your own risk, and I make no claims as to it's suitability for a particular 'function. Prospective users must evaluate the system before using it, and no 'liability will be entertained by myself in any shape or form whatsoever. 'The modules and software have been produced at low cost for the benefit of 'the EV & electronic community. Be aware that undisclosed vehicle 'modifications can lead to invalidated insurance and warranty issues. You the 'end user remain fully liable for any modifications made to your vehicle. '** PIC12F683 Pinouts FLASH 2048 (words) SRAM 128 (bytes) EEPROM 256 (bytes) ** ' Top ' _____ '(+ VCC Supply) +Ve -1| ^ |8- -Ve (- GND Supply) '(H Line Out) GP5 -2| 6 |7- GP0 (ICSPD & K Line In) '(Button In & Logger Out) GP4 -3| 8 |6- GP1 (ICSPC & K Line Out) '(H Line In & MCLR Reset) GP3 -4| 3 |5- GP2 (Lcd Display Out) ' ----- 'KLine 12V OBDII I/O 10400 Baud Serin2 Mode = 76, Serout2 Mode = 16460 '***** PIC12F683 ICSP In circuit serial Programming Pinouts 5 Pin Sil 0.1" ***** '1) MCLR '2) +5V '3) GND '4) Data '5) Clock '************************ Display Module Specification ************************* ' 0) Sparkfun 16x2 Serial Display White on Black 5V Part Number : LCD-09395 '************************ Gauge Module Specification *************************** 'Board Supply Voltage Max 16V CPU Speed 8mhz with internal resonator '******************************************************************************* '********************** Program Size 1210 out of 2048 Words ******************** '******************************************************************************* ' _OBD REQUEST_ __ OBD DATA RESPONSE ___ ___ OBD DTC RESPONSE ______ ' / \ / \ / \ ' Header M P C Header M P DATA BYTES C Header M DATA BYTES C ' | O I R | O I __|____ R | O __|__________ R ' | D D C | D D / \ C | D / \ C ' _| _ E _| _ E A B C D _| _ E A B C D E F ' / \ / \ / \ 'Send 68 6A F1 01 05 C9 Recd 48 6B 0A 41 05 xx xx 48 6B 0A 43 xx xx xx xx xx xx xx '------------------------------ General configuration -------------------------- #config __config _FCMEN_ON & _IESO_ON & _BOD_OFF & _CPD_OFF & _CP_OFF & _MCLRE_OFF & _PWRTE_OFF & _WDT_OFF & _INTOSCIO #ENDCONFIG Define OSC 8 'Set PBP processor speed to 8 Mhz INTCON = %00000000 'Clear Interrupts OSCCON = %01110101 'Sets internal osc to 8 Mhz (Default) and stable CMCON0 = %00000111 'Comparators off TRISIO = %00011010 'Set Pin GPIO.1, GPIO.3 & GPIO.4 as Inputs ANSEL = %01011000 'Set AN3 as Analog Input fosc / 16 ADCON0 = %00001101 'Turns A/D on, A/D reads (AN3), left justify and Vref=Vdd 'T1CON = %00110000 '$30 = Prescaler 1:8, TMR1 OFF 'Debug is used as it is the fastest and smallest serial routine to drive the Lcd display DEFINE DEBUG_REG GPIO 'Set Debug pin port DEFINE DEBUG_BIT 2 'Set Debug pin bit for Lcd Display GPIO.2 DEFINE DEBUG_BAUD 9600 'Set Debug baud rate 9600 approx 960 cps DEFINE DEBUG_MODE 0 'Set Debug mode: 0 = true, 1 = inverted (T=True Idle High)(N=Inverted Idle Low) Define ADC_BITS 8 'Set number of bits in result Define ADC_CLOCK 3 'Set Clock source (3 = rc) DEFINE ADC_SAMPLEUS 50 'Set sampling time in uS '******************************************************************************* 'Variables Constants and I/O definitions '------------------------ Variables 16bit -------------------------------------- Result var WORD 'Returned Data from PID request '------------------- Variables 8bit -------------------------------------------- Dtc var BYTE[5] 'Array for DTC codes display 5 bytes i.e. "P1447" as ASCII D var BYTE[5] 'OBDII Rxd Data 6 Bytes Array 0-5 D[0] to D[5] H1 var BYTE 'OBDII Rxd Header Byte 1 H2 var BYTE 'OBDII Rxd Header Byte 2 H3 var BYTE 'OBDII Rxd Header Byte 3 M1 var BYTE 'OBDII Rxd Mode Byte P1 var BYTE 'OBDII Rxd Pid Byte C1 var BYTE 'OBDII Rxd Checksum Byte Pid var BYTE 'OBDII Txd PID Request Byte 0-255 Pids (Parameter ID's) ChkSum var BYTE 'OBDII Txd Checksum Byte Key var BYTE 'Returned Button Value (0-5) 5 = No key pressed Gen var BYTE 'Gen is a General Use Byte variable (0-255) Lcd var BYTE 'Lcd Type EEprom Address (0 = SparkFun) (10 = TextStar) HighB var BYTE 'DTC HighB Byte LowB var BYTE 'DTC Low Byte L01 VAR BYTE 'Lcd Serial Control Code Clear L02 VAR BYTE 'Lcd Serial Control Code Clear L11 VAR BYTE 'Lcd Serial Control Code Line 1 L12 VAR BYTE 'Lcd Serial Control Code Line 1 L13 VAR BYTE 'Lcd Serial Control Code Line 1 L14 VAR BYTE 'Lcd Serial Control Code Line 1 L21 VAR BYTE 'Lcd Serial Control Code Line 2 L22 VAR BYTE 'Lcd Serial Control Code Line 2 L23 VAR BYTE 'Lcd Serial Control Code Line 2 L24 VAR BYTE 'Lcd Serial Control Code Line 2 '------------------- Variables 1bit -------------------------------------------- 'Config Byte (Bit Assingment) Note * (Default for all bits is 1 after program download) 'ErrorFlag VAR Config.Bit0 'BCM Data Error Flag (1 = Data error) (0 = Data ok) '--------------------- Constants ----------------------------------------------- '------------------ Pins used for I/O and designations ------------------------- '---------------------- Digital high/low Inputs/Outputs ------------------------ KLineIn var GPIO.0 'K Line In & ICSP Data Line KLineOut var GPIO.1 'K Line Out & ICSP Clock Line LcdPin var GPIO.2 'Serial Lcd Display HLineIn var GPIO.3 'H Line In & Master Clear line MCLR 'Button var GPIO.4 'Joy Button Input & Data Logger Output HLineOut var GPIO.5 'H Line Out '------------------------------ Main Program ----------------------------------- 'Load EEPROM with Text Data & Lcd Control Data (256 bytes) Area above Addr 240 reserved for gauge data 'If PID = $04 then TextStart = 0 : Result = (D[0]*100)/255 'Engine Load 0 to 100% 'If PID = $05 then TextStart = xx : Result = D[0]-40 'Engine Water Temp -40 to +215C 'If PID = $0A then TextStart = xx : Result = D[0]*3 'Fuel Pressure 0 to 765 kPa 'If PID = $0B then TextStart = xx : Result = D[0] 'Intake MAP 0 to 255kPa 'If PID = $0C then TextStart = xx : Result = ((D[0]*256)+D[1])/4'Engine Rpm 0 to 16,383 rpm 'if PID = $0D then TextStart = xx : Result = D[0] 'Vehicle Speed 0 to 255 kmh 'If PID = $0E then TextStart = xx : Result = (D[0]/2)-64 'Timing Advance -64 to +63.5 'If PID = $0F then TextStart = xx : Result = D[0]-40 'Air Intake Temp -40 to +215C 'If PID = $10 then TextStart = xx : Result = ((D[0]*256)+D[1])/100'MAF Air Flow Rate 0 to 655.35g/s 'If PID = $11 then TextStart = xx : Result = (D[0]*100)/255 'Throttle 0 to 100% 'If PID = $15 then TextStart = xx : Result = D[0]/2 'O2 Sensor Bank1 Voltage 0 to 1.28V 'If PID = $2C then TextStart = xx : Result = (D[0]*100)/255 'Commanded EGR 0 to 100% 'If PID = $33 then TextStart = xx : Result = D[0] 'Barometric Pressure 0 to 255kPa ' L O A D W T E M P M A P R P M M P H A D V A T E M P M A F 'EEPROM 0, [76,79,65,68,87,84,69,77,80,77,65,80,82,80,77,77,80,72,65,68,86,65,84,69,77,80,77,65,70] EEPROM 246, [254,1,254,128,254,128,254,192,254,192] 'SparkFun Lcd Control Codes '************************************************************************************************************** 'OBDII Gauge Main Program Start: 'Start of Program Low KLineOut 'Set K Line High (1) Default Condition Low HLineOut 'Set H Line High (1) Default Condition high LcdPin 'Set LcdPin high for later data transfer Clear 'Clear All Variables Lcd = 246 'Set EEprom Address Default Lcd As Sparkfun PID = 5 'Set Start Up PID to Engine Temp $05 Read Lcd,L01,L02,L11,L12,L13,L14,L21,L22,L23,L24 'Load Lcd Control Codes from EEprom pause 3000 'Pause for 3 seconds wait for lcd ModeSelect: DEBUG L01,L02,"Mode OBD=D" 'Display pause 2000 ModeLoop: 'Check if a button is pressed Push = 0 Up = 1 Right = 2 Down = 3 Left = 4 No Key = 5 Gosub KeyPress 'Gosub KeyPress Routine 5 = No Key Pressed if Key = 3 then ObdiiInit 'If Key = 3 (Down) goto OBDII INIT goto ModeLoop 'Goto ModeLoop '************** OBDII MODE *********** ObdiiInit: 'Initialise OBDII Bus with Bit Bang Routine DEBUG L01,L02,"Starting OBDII" 'Slow Init Send 0x33 (00110011) at rate of 5 baud (LSB) with a Start Bit and a Stop bit. (200ms per bit) High KLineOut 'Set K line low (0) Pause 200 'Pause 200ms (1 bit) low KLineOut 'Set K line high (1) pause 400 'Pause 400ms (2 bits) High KLineOut 'Set K line low (0) pause 400 'Pause 400ms (2 bits) low KLineOut 'Set K line high (1) pause 400 'Pause 400ms (2 bits) High KLineOut 'Set K line low (0) pause 400 'Pause 400ms (2 bits) low KLineOut 'Set K line high (1) Pause 400 'Pause 400ms used if not going to rxd init bytes $55 $08 $08 SEROUT2 KLineOut, 16460,[$F7] 'Send 1 data byte on K Line Inverted Mode SERIN2 KLineIn, 76, 100, ModeSelect, [Gen] 'Receive 1 data byte on K Line. Starts 35ms after end of txd above if Gen <> $CC then ModeSelect 'If OBDII Bus initialisation failed then ret to Mode Menu ObdiiMode: 'ODBIIMODE Menu DEBUG L01,L02,"OBD DTC=U CDTC=D MO=P" 'Display pause 2000 'Pause 2000ms '************** PID Routine Displays 4 OBDII Parameters *********** ObdiiLoop: 'OBDII Loop Label 'Check if a button is pressed Push = 0 Up = 1 Right = 2 Down = 3 Left = 4 No Key = 5 Gosub KeyPress 'Gosub KeyPress Routine 5 = No Key Pressed if Key = 0 then ModeSelect 'If Key = 0 (Press) goto ModeSelect if Key = 1 then gosub ReadObdDtc 'If Key = 1 (Up) gosub ReadObdDtc if Key = 3 then gosub ClearObdDtc 'If Key = 3 (Down) gosub ClearObdDtc Debug L11,L12,L13,L14 'Set Display to Line 0, Column 0 PID = $05 'Set Coolant Temp PID gosub PidDisplay 'Gosub PIDDISPLAY Routine PID = $0F 'Set Intake Temp PID gosub PIDDISPLAY 'Gosub PIDDISPLAY Routine Debug L21,L22,L23,L24 'Set Display to Line 1, Column 0 PID = $04 'Set Engine Load PID gosub PIDDISPLAY 'Gosub PIDDISPLAY Routine PID = $15 'Set O2 Sensor PID gosub PIDDISPLAY 'Gosub PIDDISPLAY Routine goto ObdiiLoop 'Goto ObdiiLoop PIDDISPLAY: 'PID Data Retrieval & Display Routine ChkSum = $68 + $6A + $F1 + $01 + PID 'Calculate Mode 1 CheckSum Byte SEROUT2 KLineOut, 16460,[$68,$6A,$F1,$01,PID,ChkSum] 'Txd PID Request on K Line Inverted Mode SERIN2 KLineIn, 76, 100, EndPid,[H1,H2,H3,M1,P1,D[0],D[1],D[2],D[3],C1] 'Rxd OBDII Data EndPid: 'Jumps when data missing or stops for 100ms Result = 0 'Clear Data Word If PID = $04 then 'Engine Load 0 to 100% Debug "Lod" Result = (D[0]*100)/255 endif If PID = $05 then 'Engine Water Temp -40 to +215C Debug "WdC" Result = D[0]-40 endif ' If PID = $0A then 'Fuel Pressure 0 to 765 kPa ' Debug "Ful" ' Result = D[0]*3 ' endif ' If PID = $0B then 'Intake MAP 0 to 255kPa ' Debug "Map" ' Result = D[0] ' endif ' If PID = $0C then 'Engine Rpm 0 to 16,383 rpm ' Debug "Rpm" ' Result = ((D[0]*256)+D[1])/4 ' endif ' if PID = $0D then 'Vehicle Speed 0 to 255 kmh ' Debug "Mph" ' Result = D[0] ' endif ' If PID = $0E then 'Timing Advance -64 to +63.5 ' Debug "Ign" ' Result = (D[0]/2)-64 ' endif If PID = $0F then 'Air Intake Temp -40 to +215C Debug "IdC" Result = D[0]-40 endif ' If PID = $10 then 'MAF Air Flow Rate 0 to 655.35g/s ' Debug "Maf" ' Result = ((D[0]*256)+D[1])/100 ' endif ' If PID = $11 then 'Throttle 0 to 100% ' Debug "Thr" ' Result = (D[0]*100)/255 ' endif If PID = $15 then 'O2 Sensor Bank1 Voltage 0 to 1.28V Debug "O2V" Result = D[0]/2 endif ' If PID = $2C then 'Commanded EGR 0 to 100% ' Debug "Egr" ' Result = (D[0]*100)/255 ' endif ' If PID = $33 then 'Barometric Pressure 0 to 255kPa ' Debug "Bar" ' Result = D[0] ' endif DEBUG 32,#Result,32 'Display PID Evaluation Result Return 'Return '************** Display OBDII DTC Routine *********** ReadObdDtc: 'Gets upto 3 DTC Codes and displays them for Gen = 0 to 5 'Start 6 Byte Loop d[Gen] = 0 'Clear DTC store bytes next 'Repeat Loop SEROUT2 KLineOut, 16460,[$68,$6A,$F1,$03,$C6] 'Txd DTC Request on K Line Inverted Mode SERIN2 KLineIn, 76, 500, EndObdDtc,[H1,H2,H3,M1,D[0],D[1],D[2],D[3],D[4],D[5],C1] 'Rxd DTC Data EndObdDtc: 'Jumps when data missing or stops for 500ms DEBUG L01,L02 'Clear LCD if M1 <> $43 then DEBUG "No DTC's Set" 'Display pause 3000 'Pause for 3 seconds return 'Return to main program endif Debug "DTC " 'Display HighB = 0 'Set High Byte for first DTC LowB = 1 'Set Low Byte for first DTC Gosub EvaluateObdDtc 'Gosub Evaluate first Dtc DEBUG L21,L22,L23,L24 'Set Display to 2nd line HighB = 2 'Set High Byte for Second DTC LowB = 3 'Set Low Byte for Second DTC Gosub EvaluateObdDtc 'Gosub Evaluate second Dtc Debug 32 'Display one space HighB = 4 'Set High Byte for Third DTC LowB = 5 'Set Low Byte for Third DTC Gosub EvaluateObdDtc 'Gosub Evaluate Third Dtc pause 5000 'Pause for 5 seconds DEBUG L01,L02 'Clear LCD return 'Return to main program EvaluateObdDtc: 'Evaluate and extract Dtc from returned Data Bytes (2) Gen = (D[HighB] & %11000000) >> 6 'Gen now 0-3 (borrow Diag[1] for this op) Lookup Gen, [32,19,18,37], Dtc[0] 'Now extract the next four "digits" in the same way. Dtc[1] = D[HighB] & %00110000 'Isolate bits 4,5 Dtc[1] = Dtc[1] >> 4 'Shift down to bits 0,1 Dtc[2] = D[HighB] & %00001111 'Isolate bits 0-3 Dtc[3] = D[LowB] & %11110000 'Isolate upper four bits Dtc[3] = Dtc[3] >> 4 'Shift down Dtc[4] = D[LowB] & %00001111 'Isolate lower four bits For Gen = 0 to 4 'Start Loop to Display 5 characters of Dtc Debug (Dtc[Gen] + 48) 'Sends Ascii Value Next return 'Return to Main Program '************** CLEAR OBDII DTC Routine *********** ClearObdDtc: 'Clear OBDII DTC's Routine DEBUG L01,L02 'Clear LCD SEROUT2 KLineOut, 16460,[$68,$6A,$F1,$04,$C7] 'Clear DTC's Request on K Line Inverted Mode SERIN2 KLineIn, 76, 500, EndClearObdDtc,[H1,H2,H3,M1,C1] 'Clear DTC Response EndClearObdDtc: 'Jumps when data missing or stops for 500ms If M1 = $44 then 'If M1 = $44 then DTC's Cleared OK DEBUG "DTC Cleared OK" 'Display else DEBUG "No DTC or Fail" 'Display endif pause 3000 'Pause for 3 seconds DEBUG L01,L02 'Clear LCD return 'Return to Main Program '************* Get Key Press ************ 'Check if a button is pressed Push = 0 Up = 1 Right = 2 Down = 3 Left = 4 No Key = 5 KeyPress: 'Evaluate Key Pressed ADCIN 3, Gen 'Read Button ADC input if Gen > 234 then key = 5 'If No key pressed then key = 5 if Gen < 235 then key = 4 'Test if button 4 pressed if Gen < 192 then key = 3 'Test if button 3 pressed if Gen < 150 then key = 2 'Test if button 2 pressed if Gen < 107 then key = 1 'Test if button 1 pressed if Gen < 64 then key = 0 'Test if button 0 pressed return 'Return to Main Program 'Mode 3: (no PID required) A request for this mode returns a list of the DTCs that have been set. 'The list is encapsulated using the ISO 15765-2 protocol. 'If there are two or fewer DTC's (4 bytes) they are returned in an ISO-TP Single Frame (SF). 'Three or more DTCs in the list are reported in multiple frames, 'with the exact count of frames dependent on the communication type and addressing details. 'Each trouble code requires 2 bytes to describe. 'The text description of a trouble code may be decoded as follows. 'The first character in the trouble code is determined by the first two bits in the first byte: 'A7 A6 First DTC character '-- -- ------------------- ' 0 0 P - Powertrain ' 0 1 C - Chassis ' 1 0 B - Body ' 1 1 U - Network 'The four following digits are BCD encoded. 'The second character in the DTC is a number defined by 'A5 A4 Second DTC character '-- -- -------------------- ' 0 0 0 ' 0 1 1 ' 1 0 2 ' 1 1 3 'The third character in the DTC is a number defined by 'A3 A2 A1 A0 Third DTC character '-- -- -- -- ------------------- ' 0 0 0 0 0 ' 0 0 0 1 1 ' 0 0 1 0 2 ' 0 0 1 1 3 ' 0 1 0 0 4 ' 0 1 0 1 5 ' 0 1 1 0 6 ' 0 1 1 1 7 ' 1 0 0 0 8 ' 1 0 0 1 9 'The fourth and fifth characters are defined in the same way as the third, 'but using bits B7..B4 and B3..B0. The resulting five-character code should 'look something like "U0158" and can be looked up in a table of OBD-II DTCs. 'Diag VAR BYTE[5] ' Array for complete message 'DTC_High VAR Byte ' Upper byte of message 'DTC_Low VAR Byte ' Lower byte of message 'i VAR BYTE ' General purpose 'Get the top two bits of the high byte and shift it down so 'it becomes 0-3. Then convert to the correct character. 'i = (DTC_High & %11000000) >> 6 ' Temp now 0-3 (borrow Diag[1] for this op) 'Lookup i, [32,19,18,37], Diag[0] 'Now extract the next four "digits" in the same way. 'Diag[1] = DTC_High & %00110000 ' Isolate bits 4,5 'Diag[1] = Diag[1] >> 4 ' Shift down to bits 0,1 'Diag[2] = DTC_High & %00001111 ' Isolate bits 0-3 'Diag[3] = DTC_Low & %11110000 ' Isolate upper four bits 'Diag[3] = Diag[3] >> 4 ' Shift down 'Diag[4] = DTC_Low & %00001111 ' Isolate lower four bits 'Now, if Diag[0] is 32 we add 48 to it and it becomes 80 which 'is the ASCII code for "U". If Diag[1] is 2 we add 48 to that 'so it becomes 50 which is the ASCII code for "2" and so on. 'HSEROUT["Error code: "] 'For i = 0 to 4 'HSEROUT[Diag + 48] 'Next Gen1 Honda Insights. |
||||
| CaptainBoing Guru Joined: 07/09/2016 Location: United KingdomPosts: 2171 |
thanks for that code - very interesting |
||||
| JohnS Guru Joined: 18/11/2011 Location: United KingdomPosts: 4126 |
You don't say which kind you bought (USB? BT? WiFi?). Either way, commonly they default to 38400 or 9600 and if relevant 8N1. I use Linux but have encountered HyperTerminal - not enough to know about setting baud rates etc. scantool should work but of course requires the com port # and settings. My feeling is your problem is Windows. However, the car won't normally provide power unless the engine is running (or the ign pos before that). John |
||||
| Andrew_G Guru Joined: 18/10/2016 Location: AustraliaPosts: 872 |
retepsnikrep - WOW & thanks! I'm a fair way off yet but as I get closer your code will help as a real example of how to do it John - it is the USB version. After two half-days in the car I can confirm that the only s/w to offer any hope is Tera Term (at 38400 on my port #29). I can talk to the Elm but have no evidence of talking to the car yet. I'm not sure how best to confirm that? The following AT commands seem to work (based on the Elm manual): AT I - outputs "ELM327 v1.5" AT Z - flashes the LEDs and outputs "ELM327 v1.5" AT L1 - turns linefeeds on, L0 = off AT @1 AT RV - gave successive readings of 3, 3.5 and 4V (each with the engine running!) I hope to try again this weekend. Cheers, Andrew |
||||
| JohnS Guru Joined: 18/11/2011 Location: United KingdomPosts: 4126 |
You're just fighting Windows then. My ATRV is 10 or so volts higher. I'm puzzled how yours can be so low. Stick with the elm datasheet. It shows how to get data from PCM, how to choose the interface it talks on, etc. If your car is definitely CAN there are not many variants to tell the elm to use. John |
||||
| Andrew_G Guru Joined: 18/10/2016 Location: AustraliaPosts: 872 |
Thanks John. I'll report back when I have more success. Cheers, Andrew |
||||
| JohnS Guru Joined: 18/11/2011 Location: United KingdomPosts: 4126 |
If you just want to get codes etc - using Windows - then just run any of the many Windows apps that work with an elm327. You just have to fight Windows a bit like with so many other things. If you want to get involved with your car at a lower level - from a 'mite maybe - you can either go the whole way with CAN chips etc or buy the elm327 as a device (or I suppose remove it from the housing & disconnect its USB-serial port chip). You might want to use a meter on your DLC (car's OBD port) and at least check voltages for sanity. John |
||||
| Andrew_G Guru Joined: 18/10/2016 Location: AustraliaPosts: 872 |
Thanks all for your patience. Yes John it is (partially) a Windows issue but also the car may not be OBDII compliant. I managed to prise my wife's Windows10 machine away from her long enough to plug it in. The software worked (it just hangs on my XP laptop). I could easily set the port but it reported back that the connection was not OBDII compliant (if you recall my car is NOT on the list of compatible vehicles). This with the engine running. I'll chalk this up to experience. Cheers, Andrew |
||||
| The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |