This Project allows for you to see live engine data from your vehicle on the LCD display. Utilizing K64F platform,Nokia 5110 LCD and HC05 Bluetooth hardware to interface with an In-Vehicle ELM327 Bluetooth dongle connected to the OBDII port. The K64F system will query the ELM327 device for live engine data and display it onscreen.

Dependencies:   mbed N5110

Committer:
samthomas90
Date:
Tue May 12 03:32:11 2015 +0000
Revision:
0:969924e823b4
Child:
1:2537162d070e
Initial Commit-Mode 3 Work in progress

Who changed what in which revision?

UserRevisionLine numberNew contents of line
samthomas90 0:969924e823b4 1 /*
samthomas90 0:969924e823b4 2 Enhanced Vehicle Diagnostics
samthomas90 0:969924e823b4 3 ELM327 Version Utilizing HC-05 Bluetooth hardware and ELM327
samthomas90 0:969924e823b4 4 */
samthomas90 0:969924e823b4 5 #include "mbed.h"
samthomas90 0:969924e823b4 6 #include "N5110.h"
samthomas90 0:969924e823b4 7 #include <string>
samthomas90 0:969924e823b4 8 using namespace std;
samthomas90 0:969924e823b4 9
samthomas90 0:969924e823b4 10 N5110 LCD(PTB2,PTD0,PTB9,PTB3,PTD2,PTD1,PTD0);
samthomas90 0:969924e823b4 11 Serial HC05(PTC17,PTC16);
samthomas90 0:969924e823b4 12 Serial SR(USBTX,USBRX);
samthomas90 0:969924e823b4 13
samthomas90 0:969924e823b4 14 DigitalIn sw2(SW2);
samthomas90 0:969924e823b4 15 DigitalIn sw3(SW3);
samthomas90 0:969924e823b4 16 DigitalOut led(LED_RED);
samthomas90 0:969924e823b4 17
samthomas90 0:969924e823b4 18 char OBD[3];
samthomas90 0:969924e823b4 19
samthomas90 0:969924e823b4 20 char percent='%';
samthomas90 0:969924e823b4 21 int flag=1;
samthomas90 0:969924e823b4 22 char OBD[]={0x01}
samthomas90 0:969924e823b4 23 char zero[2]={0x01,0x0c,};
samthomas90 0:969924e823b4 24 char OBD[13];
samthomas90 0:969924e823b4 25 char RPM[13];
samthomas90 0:969924e823b4 26 char SPD[13];
samthomas90 0:969924e823b4 27 char TMP[13];
samthomas90 0:969924e823b4 28 char MAF[13];
samthomas90 0:969924e823b4 29 char THR[13];
samthomas90 0:969924e823b4 30
samthomas90 0:969924e823b4 31 void OBDInit(void);
samthomas90 0:969924e823b4 32 void OBDLiveData(void);
samthomas90 0:969924e823b4 33 int main() {
samthomas90 0:969924e823b4 34 char c;
samthomas90 0:969924e823b4 35 HC05.format(8, Serial::None, 1);
samthomas90 0:969924e823b4 36 HC05.baud(115200);
samthomas90 0:969924e823b4 37 LCD.init();
samthomas90 0:969924e823b4 38 LCD.clear();
samthomas90 0:969924e823b4 39 led=1;
samthomas90 0:969924e823b4 40 //Initialization message//
samthomas90 0:969924e823b4 41 LCD.printString ("-ENHANCED-", 0, 0);
samthomas90 0:969924e823b4 42 LCD.printString ("-VEHICLE-", 0, 1);
samthomas90 0:969924e823b4 43 LCD.printString ("-DIAGNOSTICS-", 0, 2);
samthomas90 0:969924e823b4 44 LCD.printString ("ECE 595", 0, 3);
samthomas90 0:969924e823b4 45 LCD.printString ("SAM THOMAS", 0, 4);
samthomas90 0:969924e823b4 46 wait(1);
samthomas90 0:969924e823b4 47 LCD.clear();
samthomas90 0:969924e823b4 48 LCD.printString ("-INITIALIZE-",0, 2);
samthomas90 0:969924e823b4 49
samthomas90 0:969924e823b4 50 wait(1);
samthomas90 0:969924e823b4 51 LCD.clear();
samthomas90 0:969924e823b4 52 //HC05.printf(zero);
samthomas90 0:969924e823b4 53 while(1){
samthomas90 0:969924e823b4 54 if(flag){//static display incase HC05 connection fails
samthomas90 0:969924e823b4 55 LCD.printString("RPM 3000", 0, 0);
samthomas90 0:969924e823b4 56
samthomas90 0:969924e823b4 57 LCD.printString("SPD 65KMPH", 0, 1);
samthomas90 0:969924e823b4 58
samthomas90 0:969924e823b4 59 LCD.printString("TMP 80 C", 0, 2);
samthomas90 0:969924e823b4 60
samthomas90 0:969924e823b4 61 LCD.printString("MAF 190 g/s", 0, 3);
samthomas90 0:969924e823b4 62
samthomas90 0:969924e823b4 63 LCD.printString("THR 60", 0, 4);
samthomas90 0:969924e823b4 64 }
samthomas90 0:969924e823b4 65
samthomas90 0:969924e823b4 66 }
samthomas90 0:969924e823b4 67 }
samthomas90 0:969924e823b4 68 void OBDInit(){
samthomas90 0:969924e823b4 69 if(HC05.readable()){
samthomas90 0:969924e823b4 70 HC05.printf("ATZ\r");
samthomas90 0:969924e823b4 71 HC05.printf("ATSP0\r");
samthomas90 0:969924e823b4 72 HC05.printf("0100\r");
samthomas90 0:969924e823b4 73 return 1;
samthomas90 0:969924e823b4 74 }
samthomas90 0:969924e823b4 75 else
samthomas90 0:969924e823b4 76 {
samthomas90 0:969924e823b4 77 LCD.printString("Bluetooth NOT available");
samthomas90 0:969924e823b4 78 return 0;
samthomas90 0:969924e823b4 79 }
samthomas90 0:969924e823b4 80 }
samthomas90 0:969924e823b4 81 void OBDLiveData(){
samthomas90 0:969924e823b4 82 if(HC05.readable()){
samthomas90 0:969924e823b4 83 c =HC05.getc();
samthomas90 0:969924e823b4 84
samthomas90 0:969924e823b4 85
samthomas90 0:969924e823b4 86 //SR.putc(c);
samthomas90 0:969924e823b4 87 if(c=='~')//Get the initial character sent
samthomas90 0:969924e823b4 88 {
samthomas90 0:969924e823b4 89 flag=0;
samthomas90 0:969924e823b4 90 //for(int i=0;i<14:i++){
samthomas90 0:969924e823b4 91 LCD.clear();
samthomas90 0:969924e823b4 92 //takes in the whole string sent to it From PC below
samthomas90 0:969924e823b4 93 HC05.scanf("%s",&OBD);
samthomas90 0:969924e823b4 94 //OBD[i]=HC05.getc();
samthomas90 0:969924e823b4 95 //}
samthomas90 0:969924e823b4 96 SR.printf(OBD);
samthomas90 0:969924e823b4 97 sprintf(RPM,"RPM %c%c%c%c",OBD[0],OBD[1],OBD[2],OBD[3]);
samthomas90 0:969924e823b4 98 sprintf(SPD,"SPEED %c%cKMPH",OBD[4],OBD[5]);
samthomas90 0:969924e823b4 99 sprintf(TMP,"E.TMP %c%c F",OBD[6],OBD[7]);
samthomas90 0:969924e823b4 100 sprintf(MAF,"MAF %c%c%c g/s",OBD[8],OBD[9],OBD[10]);
samthomas90 0:969924e823b4 101 sprintf(THR,"THR %c%c %c",OBD[11],OBD[12],percent);
samthomas90 0:969924e823b4 102 LCD.clear();
samthomas90 0:969924e823b4 103 LCD.printString(RPM, 0, 0);
samthomas90 0:969924e823b4 104 SR.printf(RPM);
samthomas90 0:969924e823b4 105 LCD.printString(SPD, 0, 1);
samthomas90 0:969924e823b4 106 SR.printf(SPD);
samthomas90 0:969924e823b4 107 LCD.printString(TMP, 0, 2);
samthomas90 0:969924e823b4 108 SR.printf(TMP);
samthomas90 0:969924e823b4 109 LCD.printString(MAF, 0, 3);
samthomas90 0:969924e823b4 110 SR.printf(MAF);
samthomas90 0:969924e823b4 111 LCD.printString(THR, 0, 4);
samthomas90 0:969924e823b4 112 SR.printf(THR);
samthomas90 0:969924e823b4 113 //If SW2 is pressed Check Engine codes are displayed
samthomas90 0:969924e823b4 114 if(!sw2){
samthomas90 0:969924e823b4 115 if(!sw2){
samthomas90 0:969924e823b4 116 LCD.clear();
samthomas90 0:969924e823b4 117 LCD.printString ("CHECKING ", 0, 0);
samthomas90 0:969924e823b4 118 LCD.printString ("ENGINE ", 0, 1);
samthomas90 0:969924e823b4 119 LCD.printString ("Code(s) ", 0, 2);
samthomas90 0:969924e823b4 120 wait(2);
samthomas90 0:969924e823b4 121 LCD.clear();
samthomas90 0:969924e823b4 122 LCD.printString ("DTC CODE: ", 0, 0);
samthomas90 0:969924e823b4 123 LCD.printString ("P0103 ", 0, 1);
samthomas90 0:969924e823b4 124 LCD.printString ("Mass Air Flow", 0, 2);
samthomas90 0:969924e823b4 125 LCD.printString ("High Input", 0, 3);
samthomas90 0:969924e823b4 126 led=0;
samthomas90 0:969924e823b4 127 wait(2);
samthomas90 0:969924e823b4 128 }
samthomas90 0:969924e823b4 129 }
samthomas90 0:969924e823b4 130 }
samthomas90 0:969924e823b4 131
samthomas90 0:969924e823b4 132 }
samthomas90 0:969924e823b4 133
samthomas90 0:969924e823b4 134 }