Can I use Arduino OBD library with "custom" software serial or it needs to be used with hardware UART only? For example if I have D5 and D6 pin as RX and TX in my code hooked on OBD board, how do I initialize OBD library from there?
This is the OBD library that I'm referring to.
And I'm using this Allpro OBD board.
Update Actually I would be satisfied with a answer how to know when entire response from the board is received, because this way is way too messy:
void getResponse(void){
while(obdSerial.available()){
Serial.write(obdSerial.read());
}
}
Here I don't know when the message is received. And if I try to use example from Sparkfun obd-ii-uart-hookup-guide (different board doe) I ended up in infinite-loop since the board never return \r
, if I send ELM command to use \n
as terminator, and if I disable ELM to echo the command so that I use just one getResponse
call I get some readings, but not all the time, I ended up in infinite-loop again.
-
What / where is an Arduino OBD library? What does its documentation say?Majenko– Majenko2016年06月04日 15:35:49 +00:00Commented Jun 4, 2016 at 15:35
-
Sorry I have updated my question with links.ShP– ShP2016年06月04日 15:43:17 +00:00Commented Jun 4, 2016 at 15:43
1 Answer 1
That library is hard-coded to use the single Hardware Serial device on the Arduino Uno or the second Hardware Serial1 device on other boards.
#ifndef OBDUART
#if defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168P__)
#define OBDUART Serial
#else
#define OBDUART Serial1
#endif
#endif
You can edit the library's header file OBD.h
to define your own serial port though:
#include <SoftwareSerial.h>
extern SoftwareSerial mySerialPort;
#define OBDUART mySerialPort
And then in your sketch create the mySerialPort
SoftwareSerial object.
-
I have updated my question again, sorry :) I would really appreciate if you can take another look. But thanks for this one, this is also something that I needed.ShP– ShP2016年06月04日 15:50:58 +00:00Commented Jun 4, 2016 at 15:50