Go Down

Topic: Corrupted device with wrong manipulation? (Read 684 times) previous topic - next topic

laremy

Hi everyone,

I have an OBD2 Uart adapter commanded on Freematics. My problem is the following (I begin with Arduino)

1) First I connected the adapter to my Arduino UNO (Rx/Tx) and when uploading I had that :

avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x00
An error occurred while uploading the sketch

2) Then I did some bad manipulation instead of connecting the adapter to Rx/Tx, I connected to A2 A3 and uploaded the same sketch => nothing happened

3) Then retried with Rx/Tx connection and had that (no more 0x00) :


avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x41
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x54
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x49
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x0d
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x41
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x54
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x49
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x0d
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x41
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x54
An error occurred while uploading the sketch

Do you think that I corrupted the Adapter with step 2?

I know now that Rx/Tx do not have to be connected while uploading, so I did it and then reconnected the Adapter to Rx/Tx and instead of having in the serial monitor :

"the right text....." I have a succession of
ATZ
ATZ
ATE0
ATH0
010D
ATR
ATZ
ATZ
ATE0
ATH0
010D
ATR
ATZ
ATZ
ATE0
ATH0
010D
ATR

I am using com3 with the good baud rate (115200 in my case)

I do not understand what is it happening?

1) Did I corrupt the adapter with my wrong manipulation (the light of the adapter still works when I connect it)
2) Is it the sketch (right compilation but problem with the reading in the serial monitor)
3) Any other idea?

If you need more detail,
Feel free to ask me

Kind regards

Laurent

pylon

Quote
1) Did I corrupt the adapter with my wrong manipulation (the light of the adapter still works when I connect it)
Probably not.

Quote
2) Is it the sketch (right compilation but problem with the reading in the serial monitor)
I don't know, you didn't post the sketch.

Quote
3) Any other idea?
Provide the necessary information. No links to used hardware, no wiring diagram, no code (always post complete code!), that way we cannot really help you.

And if you post code, don't forget the code tags! (that's the </> button in the editor)

Coding Badly


@laremy, please do not cross-post.  Other thread removed.


laremy

I apologize. Thank you for your information, I will try do my best to explain my problem and follow your advice :

1) I have an OBD2 Uart adapter V2.1 commanded on Freematics : datasheet https://freematics.com/store/index.php?route=product/product&path=20&product_id=83 and library https://github.com/stanleyhuangyc/ArduinoOBD/tree/master/libraries/OBD2UART

2) As you can see in the datasheet, the adapter allows to collect information (= PIDs mode 1) of my car by connecting it to the OBD2 plug of my car.

3) My car uses the European protocol ISO 9141-2, you can see on the datasheet that this protocol is normally supported by the adapter.

3) PIDs are defined here : https://en.wikipedia.org/wiki/OBD-II_PIDs

4) So to collect the PIDs, I uploaded the example sketch of the library (OBD2 Uart library, link above). This example allows to collect some PIDs :

Code: [Select]
*************************************************************************
* Testing sketch for Freematics OBD-II UART Adapter V1/V2/V2.1
* Performs AT command-set test
* Reads and prints several OBD-II PIDs value
* Reads and prints motion sensor data if available
* Distributed under BSD
* Visit https://freematics.com/products for more product information
* Written by Stanley Huang <stanley@freematics.com.au>
*************************************************************************/

#include <OBD2UART.h>

// On Arduino Leonardo, Micro, MEGA or DUE, hardware serial can be used for output as the adapter occupies Serial1
// On Arduino UNO and those have no Serial1, we use software serial for output as the adapter uses Serial
#ifdef ARDUINO_AVR_UNO
#include <SoftwareSerial.h>
SoftwareSerial mySerial(A2, A3);
#else
#define mySerial Serial
#endif

#if defined(ESP32) && !defined(Serial1)
HardwareSerial Serial1(1);
#endif

COBD obd;
bool hasMEMS;

void testATcommands()
{
    static const char cmds[][6] = {"ATZ\r", "ATI\r", "ATH0\r", "ATRV\r", "0100\r", "010C\r", "0902\r"};
    char buf[128];

    for (byte i = 0; i < sizeof(cmds) / sizeof(cmds[0]); i++) {
        const char *cmd = cmds[i];
        mySerial.print("Sending ");
        mySerial.println(cmd);
        if (obd.sendCommand(cmd, buf, sizeof(buf))) {
            char *p = strstr(buf, cmd);
            if (p)
                p += strlen(cmd);
            else
                p = buf;
            while (*p == '\r') p++;
            while (*p) {
                mySerial.write(*p);
                if (*p == '\r' && *(p + 1) != '\r')
                    mySerial.write('\n');
                p++;
            }
            mySerial.println();
        } else {
            mySerial.println("Timeout");
        }
        delay(1000);
    }
    mySerial.println();
}

void readPIDSingle()
{
    int value;
    mySerial.print('[');
    mySerial.print(millis());
    mySerial.print(']');
    mySerial.print("RPM=");
    if (obd.readPID(PID_RPM, value)) {
      mySerial.print(value);
    }
    mySerial.println();
}

void readPIDMultiple()
{
    static const byte pids[] = {PID_SPEED, PID_ENGINE_LOAD, PID_THROTTLE, PID_COOLANT_TEMP};
    int values[sizeof(pids)];
    if (obd.readPID(pids, sizeof(pids), values) == sizeof(pids)) {
      mySerial.print('[');
      mySerial.print(millis());
      mySerial.print(']');
      for (byte i = 0; i < sizeof(pids) ; i++) {
        mySerial.print((int)pids[i] | 0x100, HEX);
        mySerial.print('=');
        mySerial.print(values[i]);
        mySerial.print(' ');
       }
       mySerial.println();
    }
}

void readBatteryVoltage()
{
  mySerial.print('[');
  mySerial.print(millis());
  mySerial.print(']');
  mySerial.print("Battery:");
  mySerial.print(obd.getVoltage(), 1);
  mySerial.println('V');
}

void readMEMS()
{
  int16_t acc[3] = {0};
  int16_t gyro[3] = {0};
  int16_t mag[3] = {0};
  int16_t temp = 0;

  if (!obd.memsRead(acc, gyro, mag, &temp)) return;

  mySerial.print('[');
  mySerial.print(millis());
  mySerial.print(']');

  mySerial.print("ACC:");
  mySerial.print(acc[0]);
  mySerial.print('/');
  mySerial.print(acc[1]);
  mySerial.print('/');
  mySerial.print(acc[2]);

  mySerial.print(" GYRO:");
  mySerial.print(gyro[0]);
  mySerial.print('/');
  mySerial.print(gyro[1]);
  mySerial.print('/');
  mySerial.print(gyro[2]);

  mySerial.print(" MAG:");
  mySerial.print(mag[0]);
  mySerial.print('/');
  mySerial.print(mag[1]);
  mySerial.print('/');
  mySerial.print(mag[2]);

  mySerial.print(" TEMP:");
  mySerial.print((float)temp / 10, 1);
  mySerial.println("C");
}

void setup()
{
  mySerial.begin(115200);
  while (!mySerial);
 
  for (;;) {
    delay(1000);
    byte version = obd.begin();
    mySerial.print("Freematics OBD-II Adapter ");
    if (version > 0) {
      mySerial.println("detected");
      mySerial.print("OBD firmware version ");
      mySerial.print(version / 10);
      mySerial.print('.');
      mySerial.println(version % 10);
      break;
    } else {
      mySerial.println("not detected");
    }
  }

  // send some commands for testing and show response for debugging purpose
  testATcommands();

  hasMEMS = obd.memsInit();
  mySerial.print("MEMS:");
  mySerial.println(hasMEMS ? "Yes" : "No");
 
  // initialize OBD-II adapter
  do {
    mySerial.println("Connecting...");
  } while (!obd.init());
  mySerial.println("OBD connected!");

  char buf[64];
  if (obd.getVIN(buf, sizeof(buf))) {
      mySerial.print("VIN:");
      mySerial.println(buf);
  }
 
  uint16_t codes[6];
  byte dtcCount = obd.readDTC(codes, 6);
  if (dtcCount == 0) {
    mySerial.println("No DTC");
  } else {
    mySerial.print(dtcCount);
    mySerial.print(" DTC:");
    for (byte n = 0; n < dtcCount; n++) {
      mySerial.print(' ');
      mySerial.print(codes[n], HEX);
    }
    mySerial.println();
  }
  delay(5000);
}

void loop()
{
  readPIDSingle();
  readPIDMultiple();
  readBatteryVoltage();
  if (hasMEMS) {
    readMEMS();
  }
}


5) Then I connected the adapter to my Arduino UNO following the datasheet instruction (Black wire => GND, Red wire => 5V, White wire => Arduino Tx and Green => Arduino Rx)

6) After that, I saw my Arduino UNO communicate with my adapter (blue light of the adapter started to blink)

7) I opened the serial monitor (by using 115200 baude rate as indicated in the sketch and in the datasheet). I obtained a succession of AT commands :

ATZ
ATZ
ATE0
ATH0
010D
ATR
ATZ
ATZ
ATE0
ATH0
010D
ATR
ATZ
ATZ
ATE0
ATH0
010D
ATR
....

8) I was surprised because reading the sketch, I thought that I will see PIDs values and text (Freematics OBD2 detected) instead of a succession AT commands.

9) Then I contacted the seller and he said that for him it worked correctly (it is normal to have AT commands)

10) Question : why the sketch does not return PIDs in the serial monitor?

11) After that the seller told me that the adapter will never work with my car because of it is using protocol ISO 9141-2 and the builtin transceiver doesn't support K-Line used by the ISO 9141-2

12) Question: I do not understand why, because in the datasheet it is mentioned that the adapter supports the ISO 9141-2 and in the .h file of the library we can see that the ISO 9141-2 protocol is declared

Hope that you will help me

Many thanks

Laurent

pylon

Quote
I was surprised because reading the sketch, I thought that I will see PIDs values and text (Freematics OBD2 detected) instead of a succession AT commands.
I'm not surprised because what you see is what the Arduino is sending to the OBD device. The result of that communication is available on the pins A2/A3 but you have to attach another serial device (some kind of USB2Serial probably) to these pins to see the results on your PC. Another possibility is to use another type of Arduino (p.e. Leonardo, Mega2560) that has a separate hardware serial interface available, additionally to the connection to the PC.

Quote
Question : why the sketch does not return PIDs in the serial monitor?
See above.

Quote
Question: I do not understand why, because in the datasheet it is mentioned that the adapter supports the ISO 9141-2 and in the .h file of the library we can see that the ISO 9141-2 protocol is declared
The product page clearly states that it supports ISO9141-2 (which is transmitted over the K-line). I don't think that library support is a fact in this regard but if they claim to support the protocol the should do it. But that's just my humble opinion.

laremy

Many thanks

I tested the Australian OBD2 adapter with your suggestion (an Arduino Mega). In fact, the reading in the serial monitor changed. Now I have this :

Freematics OBD-II Adapter not detected
Freematics OBD-II Adapter not detected
Freematics OBD-II Adapter not detected
Freematics OBD-II Adapter not detected
Freematics OBD-II Adapter not detected
Freematics OBD-II Adapter not detected
Freematics OBD-II Adapter not detected
Freematics OBD-II Adapter not detected
Freematics OBD-II Adapter detected
OBD firmware version 1.0
Sending ATZ
ELM327 v1.5
>
Sending ATI
OBD2USART V1.0
>
Sending ATH0
OK
>
Sending ATRV
14.45V
>
Sending 0100
NO DATA
>
Sending 010C
41 0C 0D FF
>
Sending 0902
NO DATA
>

MEMS:Yes
Connecting...
Connecting...
Connecting...
Connecting...
Connecting...
Connecting...
Connecting...
Connecting...
Connecting...
Connecting...
Connecting...
Connecting...
Connecting...
Connecting...
Connecting...
Connecting...
Connecting...
Connecting...
Connecting.

We can see that the adapter does not connect. So, for me as the seller said the builtin transceiver does not support K-Line used by the ISO 9141-2 (in the datasheet the adapter was supposed to support the ISO 9141-2....)

Are you agree with me? So, I ordered a Sparkfun adapter (https://www.sparkfun.com/products/9555). Hope it will work.

Have a nice we

Laurent

pylon

Quote
We can see that the adapter does not connect. So, for me as the seller said the builtin transceiver does not support K-Line used by the ISO 9141-2 (in the datasheet the adapter was supposed to support the ISO 9141-2....)
It can also mean that your car doesn't support ISO 9141-2 correctly or at least not in a way that the ELM chip may detect it automatically. What result do you get if you specify the protocol explicitly in the obd.init() call?

Go Up