ODB-II not work on mega 2560

Inquiry and support for Freematics products
Morogorn
Posts: 2
Joined: Thu Oct 12, 2017 9:20 pm

ODB-II not work on mega 2560

Postby Morogorn » Thu Oct 12, 2017 9:56 pm

Greetings,

I use "Freematics OBD-II UART Adapter V2 (for Arduino)" on my arduino mega 2560.

RED Power -> VIN
BLACK GND -> GND
White RX -> D0
Green TX -> D1

I use this code:
#include <OBD2UART.h>

COBD obd;

void setup(){
Serial.begin(9600);
Serial.println("Setup.start");
// we'll use the debug LED as output
pinMode(13, OUTPUT);
// start communication with OBD-II adapter
obd.begin();
// initiate OBD-II connection until success
while (!obd.init()){
Serial.print(".");
};
Serial.println("Setup.end");
}

void loop(){
int value;
// save engine RPM in variable 'value', return true on success
if (obd.readPID(PID_RPM, value)) {
// light on LED on Arduino board when the RPM exceeds 3000
if(value > 3000){
Serial.println("3000");
digitalWrite(13, HIGH );
}else{
digitalWrite(13, LOW);
}

}
}

When start the engine, the blue light's Freematics module is power on, some time later, it power off...

And arduino's serial output is:

Setup.start
......................

I have test with 3 arduino mega, all have the same result.

My vehicle is WV Up 2017.

What is wrong?

Best regards

stanley
Site Admin
Posts: 610
Joined: Sat Mar 01, 2014 3:15 am

Re: ODB-II not work on mega 2560

Postby stanley » Thu Oct 12, 2017 10:16 pm

Looks like the adapter failed to connect to OBD of your car. Make sure your car has a supported protocol. You can try manually set a protocol by setting argument of init().

Morogorn
Posts: 2
Joined: Thu Oct 12, 2017 9:20 pm

Re: ODB-II not work on mega 2560

Postby Morogorn » Fri Oct 13, 2017 12:01 am

@stanley, thanks for your reply:

Now work, shared infor:

For ARDUINO MEGA 2560 on VW UP 2017

RED Power -> VIN
BLACK GND -> GND
White RX -> D18
Green TX -> D19

[OBD2UART.cpp]
byte COBD::begin(){
Serial.println("COBD::begin");
//long baudrates[] = {2000000,1000000,500000,250000,230400,115200,74880,57600,38400,19200,9600,4800,2400,1200,600,300};
long baudrates[] = {38400};
byte version = 0;
for (byte n = 0; n < sizeof(baudrates) / sizeof(baudrates[0]); n++) {
Serial.println("n[" + (String) n + "] baud[" + (String) baudrates[n] + "]");
#ifndef ESP32
OBDUART.begin(baudrates[n]);
#else
OBDUART.begin(baudrates[n], SERIAL_8N1, 16, 17);
#endif
version = getVersion();
if (version != 0) break;
OBDUART.end();
}
return version;
}

stanley
Site Admin
Posts: 610
Joined: Sat Mar 01, 2014 3:15 am

Re: ODB-II not work on mega 2560

Postby stanley » Sun Oct 15, 2017 11:21 am

So fixed by manually setting serial baudrate. Good to know.


Return to “Freematics Products”

Who is online

Users browsing this forum: No registered users and 3 guests