Skip to content

Commit

Permalink
Dev (#16)
Browse files Browse the repository at this point in the history
* Allow user-specified protocol in begin()

* Allow user-specified protocol in begin()

* Update library.properties

* Update README.md

* Update library.properties
  • Loading branch information
PowerBroker2 authored Apr 20, 2020
1 parent 32da4c4 commit 806a6e1
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 18 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,23 @@ void loop()
}
```
# List of OBD Protocols:
```C++
const char AUTOMATIC = '0';
const char SAE_J1850_PWM_41_KBAUD = '1';
const char SAE_J1850_PWM_10_KBAUD = '2';
const char ISO_9141_5_BAUD_INIT = '3';
const char ISO_14230_5_BAUD_INIT = '4';
const char ISO_14230_FAST_INIT = '5';
const char ISO_15765_11_BIT_500_KBAUD = '6';
const char ISO_15765_29_BIT_500_KBAUD = '7';
const char ISO_15765_11_BIT_250_KBAUD = '8';
const char ISO_15765_29_BIT_250_KBAUD = '9';
const char SAE_J1939_29_BIT_250_KBAUD = 'A';
const char USER_1_CAN = 'B';
const char USER_2_CAN = 'C';
```

# List of standard PIDs:
```C++
const uint8_t SUPPORTED_PIDS_1_20 = 0; // 0x00 - bit encoded
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=ELMDuino
version=2.0.12
version=2.1.0
author=PowerBroker2 <gitstuff2@gmail.com>
maintainer=PowerBroker2 <gitstuff2@gmail.com>
sentence=Arduino library to easily interface with the common OBDII scanner: ELM327
Expand Down
34 changes: 18 additions & 16 deletions src/ELMduino.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


/*
bool ELM327::begin(Stream &stream)
bool ELM327::begin(Stream &stream, char protocol)
Description:
------------
Expand All @@ -14,13 +14,15 @@
-------
* Stream &stream - Pointer to Serial port connected
to ELM327
* char protocol - Protocol ID to specify the
ELM327 to communicate with the ECU over
Return:
-------
* bool - Whether or not the ELM327 was propperly
initialized
*/
bool ELM327::begin(Stream &stream)
bool ELM327::begin(Stream &stream, char protocol)
{
elm_port = &stream;

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

// try to connect
if (!initializeELM())
if (!initializeELM(protocol))
return false;

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


/*
bool ELM327::initializeELM()
bool ELM327::initializeELM(char protocol)
Description:
------------
* Initializes ELM327
Inputs:
-------
* void
* char protocol - Protocol ID to specify the
ELM327 to communicate with the ECU over
Return:
-------
Expand All @@ -60,13 +63,14 @@ bool ELM327::begin(Stream &stream)
* 0 - Automatic
* 1 - SAE J1850 PWM (41.6 kbaud)
* 2 - SAE J1850 PWM (10.4 kbaud)
* 4 - ISO 9141-2 (5 baud init)
* 5 - ISO 14230-4 KWP (5 baud init)
* 6 - ISO 14230-4 KWP (fast init)
* 7 - ISO 15765-4 CAN (11 bit ID, 500 kbaud)
* 8 - ISO 15765-4 CAN (29 bit ID, 500 kbaud)
* 9 - ISO 15765-4 CAN (11 bit ID, 250 kbaud)
* A - ISO 15765-4 CAN (29 bit ID, 250 kbaud)
* 3 - ISO 9141-2 (5 baud init)
* 4 - ISO 14230-4 KWP (5 baud init)
* 5 - ISO 14230-4 KWP (fast init)
* 6 - ISO 15765-4 CAN (11 bit ID, 500 kbaud)
* 7 - ISO 15765-4 CAN (29 bit ID, 500 kbaud)
* 8 - ISO 15765-4 CAN (11 bit ID, 250 kbaud)
* 9 - ISO 15765-4 CAN (29 bit ID, 250 kbaud)
* A - SAE J1939 CAN (29 bit ID, 250* kbaud)
* B - User1 CAN (11* bit ID, 125* kbaud)
* C - User2 CAN (11* bit ID, 50* kbaud)
Expand Down Expand Up @@ -151,8 +155,7 @@ void ELM327::formatQueryArray(uint16_t service, uint32_t pid)


/*
void ELM327::upper(char string[],
uint8_t buflen)
void ELM327::upper(char string[], uint8_t buflen)
Description:
------------
Expand All @@ -168,8 +171,7 @@ void ELM327::formatQueryArray(uint16_t service, uint32_t pid)
-------
* void
*/
void ELM327::upper(char string[],
uint8_t buflen)
void ELM327::upper(char string[], uint8_t buflen)
{
for (uint8_t i = 0; i < buflen; i++)
{
Expand Down
22 changes: 21 additions & 1 deletion src/ELMduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,26 @@



//-------------------------------------------------------------------------------------//
// Protocol IDs
//-------------------------------------------------------------------------------------//
const char AUTOMATIC = '0';
const char SAE_J1850_PWM_41_KBAUD = '1';
const char SAE_J1850_PWM_10_KBAUD = '2';
const char ISO_9141_5_BAUD_INIT = '3';
const char ISO_14230_5_BAUD_INIT = '4';
const char ISO_14230_FAST_INIT = '5';
const char ISO_15765_11_BIT_500_KBAUD = '6';
const char ISO_15765_29_BIT_500_KBAUD = '7';
const char ISO_15765_11_BIT_250_KBAUD = '8';
const char ISO_15765_29_BIT_250_KBAUD = '9';
const char SAE_J1939_29_BIT_250_KBAUD = 'A';
const char USER_1_CAN = 'B';
const char USER_2_CAN = 'C';




//-------------------------------------------------------------------------------------//
// PIDs (https://en.wikipedia.org/wiki/OBD-II_PIDs)
//-------------------------------------------------------------------------------------//
Expand Down Expand Up @@ -268,7 +288,7 @@ class ELM327



bool begin(Stream& stream);
bool begin(Stream& stream, char protocol='0');
bool initializeELM(char protocol='0');
void flushInputBuff();
uint32_t findResponse();
Expand Down

0 comments on commit 806a6e1

Please sign in to comment.