elm327 + Arduino= CD changer

Code to flash to microcontrollers for interfacing into the CAN Bus.
Post Reply
vaircom
How the heck did I end up here?
Posts: 2
Joined: 2015 May 19 12:40

elm327 + Arduino= CD changer

Post by vaircom »

hi there!

I have written code for my arduino cdc emulator.

how its should work: cd emulator listing RX until recieving"8D 0F XX XX XX" then should respond to stereo 8D 93 01

Transmition part working fine.
but I still facing problem with recieving and recognizing data. 8D OF
8D HEX TO DECIMAL=141
0F HEX TO DECIMAL =15


I have used following command if ((strtol(&rxData[0],0,16)==141) and (strtol(&rxData[3],0,16)==15)) {


the ELM and Arduino only work if change to strtol(&rxData[0],0,16)>0
its work, but not stable. plus volume regulator become inactive.

Seems that I missed something here....

here is my code:

Code: Select all

#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;
        }
      }
    }
  
  }
  }

mrdennis87
What's hacking?
Posts: 26
Joined: 2015 Nov 19 11:21

Re: elm327 + Arduino= CD changer

Post by mrdennis87 »

I would just search for the packet inside of the receiving data.. like:

If received data contains "08 DC A1 34 52 23 23 24" then We've seen this event happen..

And on the send.. you should send like this:

BTSerial.println("AT SH 08 DC A1"); // This will be your header (third byte is the identifier?)
dealy(500)
BTSerial.println(" 34 52 23 23 24"); // This line will be the rest of your packet..

Moothowelt
How the heck did I end up here?
Posts: 1
Joined: 2020 Feb 15 19:31

elm327 Arduino CD changer

Post by Moothowelt »

zdena: Sorry but you're solving the wrong problem. Fixing it in arduino-builder would be the most robust and probably easiest solution. Have you talked to arduino devs?

Post Reply