This question follows a previous question where I was asking about how to communicate with an ELM327 through a HC-05 from a Photon 2. Thanks to @ScruffR 's help I got to the point where I could make the two devices to communicate. However, I am not getting the response I was hoping for.
Below is the code I am using:
#include "Particle.h"
SYSTEM_MODE(AUTOMATIC);
int EnPin = D2;
String ReturnValue = "";
void setup() {
Serial.begin(9600);
Serial1.begin(38400);
delay(1000);
Serial.println("Initializing...");
pinMode(EnPin, OUTPUT);
digitalWrite(EnPin, HIGH);
delay(100);
getSetAtCommand("AT+RESET");
getSetAtCommand("AT");
getSetAtCommand("AT+CMODE=0");
getSetAtCommand("AT+ROLE=1");
getSetAtCommand("AT+BIND=1CA1,35,698DC5");
getSetAtCommand("AT+PAIR=1CA1,35,698DC5,15");
getSetAtCommand("AT+LINK=1CA1,35,698DC5");
delay(500);
getSetAtCommand("AT+STATE?");
delay(1000);
digitalWrite(EnPin, LOW);
delay(500);
getSetAtCommand("AT+RESET");
delay(500);
// change baud rate //
Serial.println("Changing baud rate...");
Serial1.end();
delay(1000);
Serial1.begin(9600);
delay(2000);
//////////////////////
Serial.println("Initializing ELM327...");
SendELM327Command("ATZ", 2000);
SendELM327Command("ATE0", 2000); // Echo Off
Serial.println("ELM327 initialized.");
}
void loop() {
SendELM327Command("010C", 2000);
}
void getSetAtCommand(String command) {
Serial.print(command + ": ");
String added_command = command + "\r\n";
Serial1.print(added_command);
delay(1500);
while (Serial1.available()) {
Serial.write(Serial1.read());
}
}
void SendELM327Command(String command, int iDelay){
String Response = "";
Serial.print(command + ": ");
Serial1.println(command);
delay(iDelay);
while (Serial1.available()) {
Serial.write(Serial1.read());
}
Serial.println("");
}
The response I am getting is: 010C7F 10 79.
It is supposed to show the RPM but I am not sure what that means. According to the examples I found (for other platforms) I was supposed to receive something along the lines of:
41 0C 1A F8
Besides, turning on the engine does not seem to have any effect on the response received. Is there anything obvious that I am doing wrong or maybe I am use the wrong approach?