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 07:00:33 2015 +0000
Revision:
1:2537162d070e
Parent:
0:969924e823b4
Code Cleaned up

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 percent='%';
samthomas90 0:969924e823b4 19 int flag=1;
samthomas90 0:969924e823b4 20 char zero[2]={0x01,0x0c,};
samthomas90 0:969924e823b4 21 char OBD[13];
samthomas90 0:969924e823b4 22 char RPM[13];
samthomas90 0:969924e823b4 23 char SPD[13];
samthomas90 0:969924e823b4 24 char TMP[13];
samthomas90 0:969924e823b4 25 char MAF[13];
samthomas90 0:969924e823b4 26 char THR[13];
samthomas90 0:969924e823b4 27
samthomas90 1:2537162d070e 28 int OBDInit(void);
samthomas90 0:969924e823b4 29 void OBDLiveData(void);
samthomas90 0:969924e823b4 30 int main() {
samthomas90 0:969924e823b4 31 char c;
samthomas90 0:969924e823b4 32 HC05.format(8, Serial::None, 1);
samthomas90 0:969924e823b4 33 HC05.baud(115200);
samthomas90 0:969924e823b4 34 LCD.init();
samthomas90 0:969924e823b4 35 LCD.clear();
samthomas90 0:969924e823b4 36 led=1;
samthomas90 0:969924e823b4 37 //Initialization message//
samthomas90 0:969924e823b4 38 LCD.printString ("-ENHANCED-", 0, 0);
samthomas90 0:969924e823b4 39 LCD.printString ("-VEHICLE-", 0, 1);
samthomas90 0:969924e823b4 40 LCD.printString ("-DIAGNOSTICS-", 0, 2);
samthomas90 1:2537162d070e 41 //LCD.printString ("ECE 595", 0, 3);
samthomas90 1:2537162d070e 42 //LCD.printString ("SAM THOMAS", 0, 4);
samthomas90 0:969924e823b4 43 wait(1);
samthomas90 0:969924e823b4 44 LCD.clear();
samthomas90 0:969924e823b4 45 LCD.printString ("-INITIALIZE-",0, 2);
samthomas90 1:2537162d070e 46 OBDInit();
samthomas90 0:969924e823b4 47 wait(1);
samthomas90 0:969924e823b4 48 LCD.clear();
samthomas90 0:969924e823b4 49 //HC05.printf(zero);
samthomas90 0:969924e823b4 50 while(1){
samthomas90 0:969924e823b4 51 if(flag){//static display incase HC05 connection fails
samthomas90 0:969924e823b4 52 LCD.printString("RPM 3000", 0, 0);
samthomas90 0:969924e823b4 53
samthomas90 0:969924e823b4 54 LCD.printString("SPD 65KMPH", 0, 1);
samthomas90 0:969924e823b4 55
samthomas90 0:969924e823b4 56 LCD.printString("TMP 80 C", 0, 2);
samthomas90 0:969924e823b4 57
samthomas90 0:969924e823b4 58 LCD.printString("MAF 190 g/s", 0, 3);
samthomas90 0:969924e823b4 59
samthomas90 0:969924e823b4 60 LCD.printString("THR 60", 0, 4);
samthomas90 0:969924e823b4 61 }
samthomas90 1:2537162d070e 62 else{
samthomas90 1:2537162d070e 63 OBDLiveData();
samthomas90 1:2537162d070e 64 }
samthomas90 0:969924e823b4 65
samthomas90 0:969924e823b4 66 }
samthomas90 0:969924e823b4 67 }
samthomas90 1:2537162d070e 68 int 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 1:2537162d070e 77 LCD.printString("Bluetooth NOT available",0,0);
samthomas90 0:969924e823b4 78 return 0;
samthomas90 0:969924e823b4 79 }
samthomas90 0:969924e823b4 80 }
samthomas90 0:969924e823b4 81 void OBDLiveData(){
samthomas90 1:2537162d070e 82 char c;
samthomas90 0:969924e823b4 83 if(HC05.readable()){
samthomas90 1:2537162d070e 84 c=HC05.getc();
samthomas90 0:969924e823b4 85 if(c=='~')//Get the initial character sent
samthomas90 0:969924e823b4 86 {
samthomas90 0:969924e823b4 87 flag=0;
samthomas90 0:969924e823b4 88 LCD.clear();
samthomas90 0:969924e823b4 89 //takes in the whole string sent to it From PC below
samthomas90 0:969924e823b4 90 HC05.scanf("%s",&OBD);
samthomas90 0:969924e823b4 91 SR.printf(OBD);
samthomas90 0:969924e823b4 92 sprintf(RPM,"RPM %c%c%c%c",OBD[0],OBD[1],OBD[2],OBD[3]);
samthomas90 0:969924e823b4 93 sprintf(SPD,"SPEED %c%cKMPH",OBD[4],OBD[5]);
samthomas90 0:969924e823b4 94 sprintf(TMP,"E.TMP %c%c F",OBD[6],OBD[7]);
samthomas90 0:969924e823b4 95 sprintf(MAF,"MAF %c%c%c g/s",OBD[8],OBD[9],OBD[10]);
samthomas90 0:969924e823b4 96 sprintf(THR,"THR %c%c %c",OBD[11],OBD[12],percent);
samthomas90 0:969924e823b4 97 LCD.clear();
samthomas90 0:969924e823b4 98 LCD.printString(RPM, 0, 0);
samthomas90 0:969924e823b4 99 SR.printf(RPM);
samthomas90 0:969924e823b4 100 LCD.printString(SPD, 0, 1);
samthomas90 0:969924e823b4 101 SR.printf(SPD);
samthomas90 0:969924e823b4 102 LCD.printString(TMP, 0, 2);
samthomas90 0:969924e823b4 103 SR.printf(TMP);
samthomas90 0:969924e823b4 104 LCD.printString(MAF, 0, 3);
samthomas90 0:969924e823b4 105 SR.printf(MAF);
samthomas90 0:969924e823b4 106 LCD.printString(THR, 0, 4);
samthomas90 0:969924e823b4 107 SR.printf(THR);
samthomas90 0:969924e823b4 108 //If SW2 is pressed Check Engine codes are displayed
samthomas90 0:969924e823b4 109 if(!sw2){
samthomas90 0:969924e823b4 110 if(!sw2){
samthomas90 0:969924e823b4 111 LCD.clear();
samthomas90 0:969924e823b4 112 LCD.printString ("CHECKING ", 0, 0);
samthomas90 0:969924e823b4 113 LCD.printString ("ENGINE ", 0, 1);
samthomas90 0:969924e823b4 114 LCD.printString ("Code(s) ", 0, 2);
samthomas90 0:969924e823b4 115 wait(2);
samthomas90 0:969924e823b4 116 LCD.clear();
samthomas90 0:969924e823b4 117 LCD.printString ("DTC CODE: ", 0, 0);
samthomas90 0:969924e823b4 118 LCD.printString ("P0103 ", 0, 1);
samthomas90 0:969924e823b4 119 LCD.printString ("Mass Air Flow", 0, 2);
samthomas90 0:969924e823b4 120 LCD.printString ("High Input", 0, 3);
samthomas90 0:969924e823b4 121 led=0;
samthomas90 0:969924e823b4 122 wait(2);
samthomas90 0:969924e823b4 123 }
samthomas90 0:969924e823b4 124 }
samthomas90 1:2537162d070e 125 }
samthomas90 0:969924e823b4 126 }
samthomas90 0:969924e823b4 127 }