OBD reader

Dependencies:   mbed

Committer:
rtgree01
Date:
Mon Jan 31 05:18:42 2011 +0000
Revision:
0:60212cabf694

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rtgree01 0:60212cabf694 1 /*
rtgree01 0:60212cabf694 2
rtgree01 0:60212cabf694 3 mbed Can-Bus demo
rtgree01 0:60212cabf694 4
rtgree01 0:60212cabf694 5 This program is to demonstrate the CAN-bus capability of the mbed module.
rtgree01 0:60212cabf694 6
rtgree01 0:60212cabf694 7 http://www.skpang.co.uk/catalog/product_info.php?products_id=741
rtgree01 0:60212cabf694 8
rtgree01 0:60212cabf694 9 v1.0 July 2010
rtgree01 0:60212cabf694 10
rtgree01 0:60212cabf694 11 ********************************************************************************
rtgree01 0:60212cabf694 12
rtgree01 0:60212cabf694 13 WARNING: Use at your own risk, sadly this software comes with no guarantees.
rtgree01 0:60212cabf694 14 This software is provided 'free' and in good faith, but the author does not
rtgree01 0:60212cabf694 15 accept liability for any damage arising from its use.
rtgree01 0:60212cabf694 16
rtgree01 0:60212cabf694 17 ********************************************************************************
rtgree01 0:60212cabf694 18
rtgree01 0:60212cabf694 19
rtgree01 0:60212cabf694 20 */
rtgree01 0:60212cabf694 21
rtgree01 0:60212cabf694 22 #include "mbed.h"
rtgree01 0:60212cabf694 23 #include "ecu_reader.h"
rtgree01 0:60212cabf694 24 #include "globals.h"
rtgree01 0:60212cabf694 25
rtgree01 0:60212cabf694 26
rtgree01 0:60212cabf694 27 ecu_reader obdii(CANSPEED_500); //Create object and set CAN speed
rtgree01 0:60212cabf694 28
rtgree01 0:60212cabf694 29 int main() {
rtgree01 0:60212cabf694 30
rtgree01 0:60212cabf694 31 char buffer[20];
rtgree01 0:60212cabf694 32
rtgree01 0:60212cabf694 33 pc.printf("\n\rCAN-bus demo...");
rtgree01 0:60212cabf694 34
rtgree01 0:60212cabf694 35 while(1) { // Main CAN loop
rtgree01 0:60212cabf694 36 led2 = 1;
rtgree01 0:60212cabf694 37 wait(0.1);
rtgree01 0:60212cabf694 38 led2 = 0;
rtgree01 0:60212cabf694 39 wait(0.1);
rtgree01 0:60212cabf694 40
rtgree01 0:60212cabf694 41 if(obdii.request(ENGINE_RPM,buffer) == 1) // Get engine rpm and display on LCD
rtgree01 0:60212cabf694 42 {
rtgree01 0:60212cabf694 43 pc.printf("%s\n\r", buffer);
rtgree01 0:60212cabf694 44 }
rtgree01 0:60212cabf694 45
rtgree01 0:60212cabf694 46 if(obdii.request(ENGINE_COOLANT_TEMP,buffer) == 1)
rtgree01 0:60212cabf694 47 {
rtgree01 0:60212cabf694 48 pc.printf("%s\n\r", buffer);
rtgree01 0:60212cabf694 49 }
rtgree01 0:60212cabf694 50
rtgree01 0:60212cabf694 51 if(obdii.request(VEHICLE_SPEED,buffer) == 1)
rtgree01 0:60212cabf694 52 {
rtgree01 0:60212cabf694 53 pc.printf("%s\n\r", buffer);
rtgree01 0:60212cabf694 54 }
rtgree01 0:60212cabf694 55
rtgree01 0:60212cabf694 56 if(obdii.request(THROTTLE,buffer) ==1 )
rtgree01 0:60212cabf694 57 {
rtgree01 0:60212cabf694 58 pc.printf("%s\n\r", buffer);
rtgree01 0:60212cabf694 59 }
rtgree01 0:60212cabf694 60
rtgree01 0:60212cabf694 61 if(obdii.request(MAF_SENSOR,buffer) ==1 )
rtgree01 0:60212cabf694 62 {
rtgree01 0:60212cabf694 63 pc.printf("%s\n\r", buffer);
rtgree01 0:60212cabf694 64 }
rtgree01 0:60212cabf694 65
rtgree01 0:60212cabf694 66 if(obdii.request(O2_VOLTAGE,buffer) ==1 )
rtgree01 0:60212cabf694 67 {
rtgree01 0:60212cabf694 68 pc.printf("%s\n\r", buffer);
rtgree01 0:60212cabf694 69 }
rtgree01 0:60212cabf694 70 }
rtgree01 0:60212cabf694 71 }