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
ODB-II not work on mega 2560
Re: ODB-II not work on mega 2560
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().
Re: ODB-II not work on mega 2560
@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;
}
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;
}
Re: ODB-II not work on mega 2560
So fixed by manually setting serial baudrate. Good to know.