Software serial problem -> K-wire without ELM

I`m trying to make a k-wire interface without the elm chip.(it is not av. in my country)
I used this schematic and info fromhttp://blog.perquin.com/blog/category/odbii/.

So, to init the k-wire (fast way) I need to :

  1. Wait for 300ms with K line high.
  2. Pull K line low for 25 +/- 1 ms
  3. Let K line rise high and wait 25ms
  4. init serial connection to 10400 baud, 8N1, 1=0Volt 0=12Volt, least significant bit first
  5. send package c1 33 f1 81 66 33=dest, f1=our tester id, 81=start comms
  6. wait for response 83 f1 01 c1 e9 8f ae 01=physical address, c1=response ok (7f=fail), e9=kb1, 8f=kb2

My idea was

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX

void fastinit(){
  Serial.println("F init start");
  digitalWrite(11,HIGH);
  delay(299);//(fast init 300 ms)
  digitalWrite(11,LOW);
  delay(25);
  digitalWrite(11,HIGH);
  delay(25);
  mySerial.begin(10400);
  mySerial.write("c1 33 f1 81 66");
  Serial.println("F init end");
}

void setup()  
{
  // Open serial communications and wait for port to open:
  Serial.begin(57600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  Serial.println("Setup");
  fastinit();
  
}

void loop() // run over and over
{
  if (mySerial.available())
    Serial.write(mySerial.read());
  if (Serial.available())
    mySerial.write(Serial.read());
}

For some random reason, i don`t get anything.

  mySerial.begin(10400);

Are you sure that that speed is supported?

  mySerial.write("c1 33 f1 81 66");

It's unlikely that the device is expecting a string. Most likely, it is expecting 5 bytes, with values 0xc1, 0x33, etc.

Are you asking if 10400 is supported by the arduino or the K-wire?

Is this how i should send that string?

/////
mySerial.write(0x31);
delay(20);
mySerial.write("next");
//etc?

Are you asking if 10400 is supported by the arduino or the K-wire?

I'm asking if SoftwareSerial supports that speed.

Is this how i should send that string?

You shouldn't be sending a string.

byte crap[] = { 0xc1, ox33, 0xf1, 0x81, 0x66 };
mySerial.write(crap, 5);

PaulS:

Is this how i should send that string?

You shouldn't be sending a string.

byte crap[] = { 0xc1, ox33, 0xf1, 0x81, 0x66 };

mySerial.write(crap, 5);

He needs the 20 ms inter-byte timing for OBDII, so perhaps (using delay())..

byte crap[] = { 0xc1, ox33, 0xf1, 0x81, 0x66 };
  for (int i = 0; i < 5, i++) {
    mySerial.write(crap, i);
  }

so perhaps (using delay())..

I don't see a delay().

PaulS:

so perhaps (using delay())..

I don't see a delay().

You have to squint a bit. Here, I'll enlarge it:

byte crap[] = { 0xc1, ox33, 0xf1, 0x81, 0x66 };
  for (int i = 0; i < 5, i++) {
    mySerial.write(crap, i);
    delay(20);
  }

I don't know why it shrunk so much. :cold_sweat:

I don't know why it shrunk so much.

Thanks. The bigger font helped.

Any luck ? Did it work ?