Skip to content

Commit 806a6e1

Browse files
authored
Dev (#16)
* Allow user-specified protocol in begin() * Allow user-specified protocol in begin() * Update library.properties * Update README.md * Update library.properties
1 parent 32da4c4 commit 806a6e1

4 files changed

Lines changed: 57 additions & 18 deletions

File tree

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,23 @@ void loop()
5959
}
6060
```
6161
62+
# List of OBD Protocols:
63+
```C++
64+
const char AUTOMATIC = '0';
65+
const char SAE_J1850_PWM_41_KBAUD = '1';
66+
const char SAE_J1850_PWM_10_KBAUD = '2';
67+
const char ISO_9141_5_BAUD_INIT = '3';
68+
const char ISO_14230_5_BAUD_INIT = '4';
69+
const char ISO_14230_FAST_INIT = '5';
70+
const char ISO_15765_11_BIT_500_KBAUD = '6';
71+
const char ISO_15765_29_BIT_500_KBAUD = '7';
72+
const char ISO_15765_11_BIT_250_KBAUD = '8';
73+
const char ISO_15765_29_BIT_250_KBAUD = '9';
74+
const char SAE_J1939_29_BIT_250_KBAUD = 'A';
75+
const char USER_1_CAN = 'B';
76+
const char USER_2_CAN = 'C';
77+
```
78+
6279
# List of standard PIDs:
6380
```C++
6481
const uint8_t SUPPORTED_PIDS_1_20 = 0; // 0x00 - bit encoded

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=ELMDuino
2-
version=2.0.12
2+
version=2.1.0
33
author=PowerBroker2 <gitstuff2@gmail.com>
44
maintainer=PowerBroker2 <gitstuff2@gmail.com>
55
sentence=Arduino library to easily interface with the common OBDII scanner: ELM327

src/ELMduino.cpp

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
/*
7-
bool ELM327::begin(Stream &stream)
7+
bool ELM327::begin(Stream &stream, char protocol)
88
99
Description:
1010
------------
@@ -14,13 +14,15 @@
1414
-------
1515
* Stream &stream - Pointer to Serial port connected
1616
to ELM327
17+
* char protocol - Protocol ID to specify the
18+
ELM327 to communicate with the ECU over
1719
1820
Return:
1921
-------
2022
* bool - Whether or not the ELM327 was propperly
2123
initialized
2224
*/
23-
bool ELM327::begin(Stream &stream)
25+
bool ELM327::begin(Stream &stream, char protocol)
2426
{
2527
elm_port = &stream;
2628

@@ -29,7 +31,7 @@ bool ELM327::begin(Stream &stream)
2931
return false;
3032

3133
// try to connect
32-
if (!initializeELM())
34+
if (!initializeELM(protocol))
3335
return false;
3436

3537
return true;
@@ -39,15 +41,16 @@ bool ELM327::begin(Stream &stream)
3941

4042

4143
/*
42-
bool ELM327::initializeELM()
44+
bool ELM327::initializeELM(char protocol)
4345
4446
Description:
4547
------------
4648
* Initializes ELM327
4749
4850
Inputs:
4951
-------
50-
* void
52+
* char protocol - Protocol ID to specify the
53+
ELM327 to communicate with the ECU over
5154
5255
Return:
5356
-------
@@ -60,13 +63,14 @@ bool ELM327::begin(Stream &stream)
6063
* 0 - Automatic
6164
* 1 - SAE J1850 PWM (41.6 kbaud)
6265
* 2 - SAE J1850 PWM (10.4 kbaud)
63-
* 4 - ISO 9141-2 (5 baud init)
64-
* 5 - ISO 14230-4 KWP (5 baud init)
65-
* 6 - ISO 14230-4 KWP (fast init)
66-
* 7 - ISO 15765-4 CAN (11 bit ID, 500 kbaud)
67-
* 8 - ISO 15765-4 CAN (29 bit ID, 500 kbaud)
68-
* 9 - ISO 15765-4 CAN (11 bit ID, 250 kbaud)
69-
* A - ISO 15765-4 CAN (29 bit ID, 250 kbaud)
66+
* 3 - ISO 9141-2 (5 baud init)
67+
* 4 - ISO 14230-4 KWP (5 baud init)
68+
* 5 - ISO 14230-4 KWP (fast init)
69+
* 6 - ISO 15765-4 CAN (11 bit ID, 500 kbaud)
70+
* 7 - ISO 15765-4 CAN (29 bit ID, 500 kbaud)
71+
* 8 - ISO 15765-4 CAN (11 bit ID, 250 kbaud)
72+
* 9 - ISO 15765-4 CAN (29 bit ID, 250 kbaud)
73+
* A - SAE J1939 CAN (29 bit ID, 250* kbaud)
7074
* B - User1 CAN (11* bit ID, 125* kbaud)
7175
* C - User2 CAN (11* bit ID, 50* kbaud)
7276
@@ -151,8 +155,7 @@ void ELM327::formatQueryArray(uint16_t service, uint32_t pid)
151155

152156

153157
/*
154-
void ELM327::upper(char string[],
155-
uint8_t buflen)
158+
void ELM327::upper(char string[], uint8_t buflen)
156159
157160
Description:
158161
------------
@@ -168,8 +171,7 @@ void ELM327::formatQueryArray(uint16_t service, uint32_t pid)
168171
-------
169172
* void
170173
*/
171-
void ELM327::upper(char string[],
172-
uint8_t buflen)
174+
void ELM327::upper(char string[], uint8_t buflen)
173175
{
174176
for (uint8_t i = 0; i < buflen; i++)
175177
{

src/ELMduino.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,26 @@
44

55

66

7+
//-------------------------------------------------------------------------------------//
8+
// Protocol IDs
9+
//-------------------------------------------------------------------------------------//
10+
const char AUTOMATIC = '0';
11+
const char SAE_J1850_PWM_41_KBAUD = '1';
12+
const char SAE_J1850_PWM_10_KBAUD = '2';
13+
const char ISO_9141_5_BAUD_INIT = '3';
14+
const char ISO_14230_5_BAUD_INIT = '4';
15+
const char ISO_14230_FAST_INIT = '5';
16+
const char ISO_15765_11_BIT_500_KBAUD = '6';
17+
const char ISO_15765_29_BIT_500_KBAUD = '7';
18+
const char ISO_15765_11_BIT_250_KBAUD = '8';
19+
const char ISO_15765_29_BIT_250_KBAUD = '9';
20+
const char SAE_J1939_29_BIT_250_KBAUD = 'A';
21+
const char USER_1_CAN = 'B';
22+
const char USER_2_CAN = 'C';
23+
24+
25+
26+
727
//-------------------------------------------------------------------------------------//
828
// PIDs (https://en.wikipedia.org/wiki/OBD-II_PIDs)
929
//-------------------------------------------------------------------------------------//
@@ -268,7 +288,7 @@ class ELM327
268288

269289

270290

271-
bool begin(Stream& stream);
291+
bool begin(Stream& stream, char protocol='0');
272292
bool initializeELM(char protocol='0');
273293
void flushInputBuff();
274294
uint32_t findResponse();

0 commit comments

Comments
 (0)