Car Stereo ELM327 and Arduino Mini

Hi all!
I trying to build my own CD changer emulator.
the way how Stereo communicating with emulator is quite simple: CD changer waiting for “8D 0F XX XX XX” and should respond as “8D 94 01” and then “8D 93 01”

however the code below doesn’t recognize “8D 0F XX XX XX”…

connection diagram is: (Car Stereo to J1850 to ELM to Arduino 7,8)

#include <SoftwareSerial.h>
SoftwareSerial BTSerial(7, 8); // TX | RX
//char character;
//char DATAFROMMAFON=0;
char rxData[20];
char rxIndex=0;
int led = 13;


void setup()
{
Serial.begin(38400);
BTSerial.begin(38400);

if (BTSerial.available())
Serial.write(BTSerial.read());
if (Serial.available())
//BTSerial.flush();
BTSerial.write(Serial.read());

BTSerial.write("ATL1");
BTSerial.println();
delay (500);
BTSerial.write("ATH1");
BTSerial.println();
delay (500);
BTSerial.write("ATS1");
BTSerial.println();
delay (500);
BTSerial.write("ATAL");
BTSerial.println();
delay (500);
BTSerial.write("ATE0");
BTSerial.println();
delay (500);
Serial.println("ATMA"); //J1850
BTSerial.println();
delay (500);

 if (BTSerial.available() > 0) {
    BTSerial.println("ATSH8D9301");// Hi Im CD changer!
    BTSerial.println();
   delay(50);
    BTSerial.println("0000"); 
    BTSerial.println();
    delay(200);\
    


 }
}


 void loop() {// run over and over
  
  
  BTSerial.flush();

    getResponse();
getResponse();// 


       if ((strtol(&rxData[0],0,16)==141) and (strtol(&rxData[3],0,16)==15)) { 
    digitalWrite(13, HIGH);
    
    BTSerial.println("ATSH8D9301");// 
    BTSerial.println();
   delay(20);
    BTSerial.println("0000"); //п
    BTSerial.println();
    delay(150);


 }
  }
  
  
  
 
   
void getResponse(void){

  char inChar=0;
  {  
    while(inChar != '\r'){
      if(BTSerial.available() > 0){
        if(BTSerial.peek() == '\r'){
          inChar=BTSerial.read();
          rxData[rxIndex]='\0';
          rxIndex=0;
        }
        else {
          inChar = BTSerial.read();
          rxData[rxIndex++]=inChar;
        }
      }
    }
  
  }
  }

Likely need to Serial.write(hexData); out, so

Serialwrite(0x8D);
Serialwrite(0x93);
Serialwrite(0x01);

Put the data in an array, and loop thru array as needed:

for (x=0; x<3; x=x+1){
Serialwrite(dataArray[x]);
}

CrossRoads
thanks for replay!

still looking how to resolve this part:

Rx receiving “8D 0F 20 90”
Frame header: 8D equal to 141

Data byte: 0F equal to 15

if ((strtol(&rxData[0],0,16)==141) and (strtol(&rxData[3],0,16)==15)) {
digitalWrite(13, HIGH);

I have stolen this part from another OBD project :slight_smile:

Led still dark…

seems that I missed something to identify header and first byte.