Skip to content

Commit

Permalink
1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
aster94 committed Jan 13, 2019
1 parent b2d6019 commit 5f818a8
Show file tree
Hide file tree
Showing 9 changed files with 399 additions and 205 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ Many IC could be used as interface, for example:
- MC33199
- operational amplifiers/level shifter/transistors (**not recommended**)

### Tested Vehicles
- Suzuki GSX-R 600 L1 (2011)
### List of Vehicles

| Motorbike | Year | Tested |
| ------------- |---------- |------- |
| GSX-R600 | 2011 | ✔️ |


# Usage
Expand All @@ -36,7 +39,7 @@ First of all go to [PIDs.h](/src/PIDs.h) and decomment (delete the `//` symbols)


### Installation
Simply add this from the Arduino/PlatformIO Library Manager or download this repository and add it to your library folder
Simply search for `KWP2000` in the Arduino/PlatformIO Library Manager or download this repository and add it to your library folder


### Development
Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
- test on other bikes
- discover new PIDs

#### 1.1.0 - jan 13, 2019
- added `readTroubleCodes()` and `clearTroubleCodes()`
- small fixes

#### 1.0.0 - jan 10, 2019
- version promoted for pubblication on the arduino library manager
- code cleaner
Expand Down
69 changes: 49 additions & 20 deletions documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
`define `[`request_ok`](#_p_i_ds_8h_1a78ce7705e54cbaa84ea562d4049227d2) |
`enum `[`error_enum`](#_k_w_p2000_8cpp_1ae7c16c55057fcaccff98f9725ba4d4ab) | This is a a collection of possible ECU Errors.
`enum `[`debug_enum`](#_k_w_p2000_8h_1ad078f8d8e69df174a8cac511c1c069ab) | Collection of possible debug levels.
`enum `[`trouble_codes`](#_k_w_p2000_8h_1ae4ad9c20cc20b9cee99316ffe2a90f95) | Used by `readTroubleCodes()`
`class `[`KWP2000`](#class_k_w_p2000) |

## Members
Expand Down Expand Up @@ -103,6 +104,16 @@ DEBUG_LEVEL_NONE |
DEBUG_LEVEL_DEFAULT |
DEBUG_LEVEL_VERBOSE |

#### `enum `[`trouble_codes`](#_k_w_p2000_8h_1ae4ad9c20cc20b9cee99316ffe2a90f95)

Used by `readTroubleCodes()`

Values | Descriptions
--------------------------------|---------------------------------------------
READ_TOTAL |
READ_ONLY_ACTIVE |
READ_ALL |

# class `KWP2000`

## Summary
Expand All @@ -114,22 +125,24 @@ DEBUG_LEVEL_VERBOSE |
`public void `[`setDebugLevel`](#class_k_w_p2000_1a606cca606a1dbf4bf10f4d5ae858c51c)`(const uint8_t debug_level)` | Change the debug level.
`public void `[`disableDebug`](#class_k_w_p2000_1a5e260665c48d5496b8f36a4366da801c)`()` | Disable the debug.
`public void `[`enableDealerMode`](#class_k_w_p2000_1abe3d7b98a45212a2a01136c435ec86cd)`(const uint8_t dealer_pin)` | Only for Suzuki: Enable the Dealer Mode.
`public void `[`dealerMode`](#class_k_w_p2000_1a1286399e7b04b99c4d52255becd49e54)`(const uint8_t dealer_mode)` | Enable/Disable the Dealer Mode.
`public void `[`dealerMode`](#class_k_w_p2000_1a1286399e7b04b99c4d52255becd49e54)`(const uint8_t dealer_mode)` | Only for Suzuki: Enable/Disable the Dealer Mode.
`public int8_t `[`initKline`](#class_k_w_p2000_1a525959756a83655e27c2f857aee22c7b)`()` | Inizialize the the communication through the K-Line.
`public int8_t `[`stopKline`](#class_k_w_p2000_1afe923cc38efb6d547d496ce8902f3d29)`()` | Close the communication with the motorbike.
`public void `[`requestSensorsData`](#class_k_w_p2000_1a0e0ce92a0eeafd35ccf4ac3655725d0c)`()` | Send a request to the ECU asking for data from all the sensors, to see them you can use `[printSensorsData()](#class_k_w_p2000_1ab9135d21a343e0e90f0527f4ab22b531)`
`public void `[`readTroubleCodes`](#class_k_w_p2000_1ad734605d8fcfb79cb04efb8595203b3a)`(const uint8_t which)` | Read the Diagnostic Trouble Codes (DTC) from the ECU.
`public void `[`clearTroubleCodes`](#class_k_w_p2000_1a311058a52c716a44efe8e32843467162)`(const uint8_t code)` | Clear the DTC from the ECU.
`public void `[`keepAlive`](#class_k_w_p2000_1aa3f5ac744841d4207190444b30436023)`(uint16_t time)` | Keep the connection through the K-Line alive.
`public int8_t `[`handleRequest`](#class_k_w_p2000_1ab12d216d5ccab1d197c6847783ac2125)`(const uint8_t to_send,const uint8_t send_len)` | This function is part of the core of the library. You just need to give a PID and it will generate the header, calculate the checksum and try to send the request with error hadling options.
`public int8_t `[`handleRequest`](#class_k_w_p2000_1ad11d8664b91f417a94528a8f92dd8d4d)`(const uint8_t to_send,const uint8_t send_len,const uint8_t try_once)` | This function is the core of the library. You just need to give a PID and it will generate the header, calculate the checksum and try to send the request. Then it will check if the response is correct and if now it will try to send the request another two times, all is based on the ISO14230.
`public void `[`accessTimingParameter`](#class_k_w_p2000_1a953906eda48ecaea0d1ad8a2f1b0e8d5)`(const uint8_t read_only)` | Ask and print the Timing Parameters from the ECU.
`public void `[`resetTimingParameter`](#class_k_w_p2000_1ab9246be67a37784274c444801878edb3)`()` | Reset the Timing Parameters to the default settings from the ECU.
`public void `[`changeTimingParameter`](#class_k_w_p2000_1abd42cfde45d2f41846915b58dfe9c15e)`(uint32_t new_atp,const uint8_t new_atp_len)` | Change the Timing Parameters to custom ones.
`public void `[`changeTimingParameter`](#class_k_w_p2000_1a3ccc4ebcea810e12b2ceb63c9a4858a0)`(uint32_t new_atp,const uint8_t new_atp_len)` | Change the Timing Parameters to custom ones.
`public void `[`printStatus`](#class_k_w_p2000_1afefd32e48fc101c9b2307aa9a2c498b2)`(uint16_t time)` | Print a rich and useful set of information about the ECU status and errors.
`public void `[`printSensorsData`](#class_k_w_p2000_1ab9135d21a343e0e90f0527f4ab22b531)`()` | Print all the sensors data from the ECU, you need to run `[requestSensorsData()](#class_k_w_p2000_1a0e0ce92a0eeafd35ccf4ac3655725d0c)` before.
`public void `[`printLastResponse`](#class_k_w_p2000_1aead234d1c8fd1d0fa0ed0ff66ce478bf)`()` | Print the last response received from the ECU.
`public int8_t `[`getStatus`](#class_k_w_p2000_1ae52be2a2e5b21646da2bfcdc595b15f4)`()` | Get the connection status.
`public int8_t `[`getError`](#class_k_w_p2000_1a2b1b535611064e42990ebfe292c3f53a)`()` | This say you only if there are/aren't errors, to see them use `[printStatus()](#class_k_w_p2000_1afefd32e48fc101c9b2307aa9a2c498b2)`
`public void `[`resetError`](#class_k_w_p2000_1a44fbde61c33c7cbe7b7abc881735c595)`()` | Reset the errors from the ECU, use with caution.
`public uint8_t `[`getGPS`](#class_k_w_p2000_1a8981e2ea9bc9f222518e913965146b7e)`()` | Get* the ECU value you need: GPS, RPM, SPEED, TPS, IAP, IAT, ECT, STPS, more coming.
`public uint8_t `[`getGPS`](#class_k_w_p2000_1a8981e2ea9bc9f222518e913965146b7e)`()` | Get* the ECU sensor value you need GPS: Gear Position Sensor RPM: Right Per Minutes SPEED: speed of the bike TPS: Throttle Position Sensor IAP: Intake Air Pressure IAT: Intake Air Temperature ECT: Engine Coolant Temperature STPS: Secondary Throttle Position Sensor.
`public uint8_t `[`getRPM`](#class_k_w_p2000_1a89113f189900e5d00a34ef48b144a3e4)`()` |
`public uint8_t `[`getSPEED`](#class_k_w_p2000_1a456e9b164d6eaa2ed3eea97ded4cb7a5)`()` |
`public uint8_t `[`getTPS`](#class_k_w_p2000_1aeb492557cd6d2fc085201b9c831c1051)`()` |
Expand All @@ -149,7 +162,7 @@ Constructor for the [KWP2000](#class_k_w_p2000) class.

* `k_out_pin` The TX pin of this serial

* `kline_baudrate` The baudrate for the kline (defaut to 10400)
* `kline_baudrate` Optional, defaut to `10400`. The baudrate for the kline,

#### `public void `[`enableDebug`](#class_k_w_p2000_1a35cce1caf07fbdc9338ef8a68f87f0d4)`(HardwareSerial * debug_serial,const uint8_t debug_level,const uint32_t debug_baudrate)`

Expand All @@ -158,9 +171,9 @@ Enable the debug of the communication.
#### Parameters
* `debug_serial` The Serial port you will use for the debug information

* `debug_level` Default: `DEBUG_LEVEL_DEFAULT` The verbosity of the debug
* `debug_level` Optional, default to `DEBUG_LEVEL_DEFAULT`. The verbosity of the debug

* `debug_baudrate` Default: `115200` The baudrate for the debug
* `debug_baudrate` Optional, default to `115200`. The baudrate for the debug

#### `public void `[`setDebugLevel`](#class_k_w_p2000_1a606cca606a1dbf4bf10f4d5ae858c51c)`(const uint8_t debug_level)`

Expand All @@ -182,7 +195,7 @@ Only for Suzuki: Enable the Dealer Mode.

#### `public void `[`dealerMode`](#class_k_w_p2000_1a1286399e7b04b99c4d52255becd49e54)`(const uint8_t dealer_mode)`

Enable/Disable the Dealer Mode.
Only for Suzuki: Enable/Disable the Dealer Mode.

#### Parameters
* `dealer_mode` Choose between true/false
Expand All @@ -192,50 +205,66 @@ Enable/Disable the Dealer Mode.
Inizialize the the communication through the K-Line.

#### Returns
int8_t return `0` until the connection is not established, then `true` if there aren't any errors, a `negative number` otherwise
`0` until the connection is not established, then `true` if there aren't any errors, a `negative number` otherwise

#### `public int8_t `[`stopKline`](#class_k_w_p2000_1afe923cc38efb6d547d496ce8902f3d29)`()`

Close the communication with the motorbike.

#### Returns
int8_t return `0` until the connection is not closed, then `true` if there aren't any errors, a `negative number` otherwise
`0` until the connection is not closed, then `true` if there aren't any errors, a `negative number` otherwise

#### `public void `[`requestSensorsData`](#class_k_w_p2000_1a0e0ce92a0eeafd35ccf4ac3655725d0c)`()`

Send a request to the ECU asking for data from all the sensors, to see them you can use `[printSensorsData()](#class_k_w_p2000_1ab9135d21a343e0e90f0527f4ab22b531)`

#### `public void `[`readTroubleCodes`](#class_k_w_p2000_1ad734605d8fcfb79cb04efb8595203b3a)`(const uint8_t which)`

Read the Diagnostic Trouble Codes (DTC) from the ECU.

#### Parameters
* `which` Optional, default to `READ_ONLY_ACTIVE`. One of the values from the `trouble_codes` enum

#### `public void `[`clearTroubleCodes`](#class_k_w_p2000_1a311058a52c716a44efe8e32843467162)`(const uint8_t code)`

Clear the DTC from the ECU.

#### Parameters
* `code` Optional. Only the passed `code` will be cleared

#### `public void `[`keepAlive`](#class_k_w_p2000_1aa3f5ac744841d4207190444b30436023)`(uint16_t time)`

Keep the connection through the K-Line alive.

#### Parameters
* `time` It is calculated automatically to be a safe interval
* `time` Optional. It is calculated automatically to be a safe interval

#### `public int8_t `[`handleRequest`](#class_k_w_p2000_1ab12d216d5ccab1d197c6847783ac2125)`(const uint8_t to_send,const uint8_t send_len)`
#### `public int8_t `[`handleRequest`](#class_k_w_p2000_1ad11d8664b91f417a94528a8f92dd8d4d)`(const uint8_t to_send,const uint8_t send_len,const uint8_t try_once)`

This function is part of the core of the library. You just need to give a PID and it will generate the header, calculate the checksum and try to send the request with error hadling options.
This function is the core of the library. You just need to give a PID and it will generate the header, calculate the checksum and try to send the request. Then it will check if the response is correct and if now it will try to send the request another two times, all is based on the ISO14230.

#### Parameters
* `to_send` The PID you want to send, see PID.h for more detail

* `send_len` The lenght of the PID (use `sizeof` to get it)

* `try_once` Optional, default to `false`. Choose if you want to try to send the request 3 times in case of error

#### Returns
int8_t return `true` if the request has been sent and a correct response has been received, a `negative number` otherwise
`true` if the request has been sent and a correct response has been received, a `negative number` otherwise

#### `public void `[`accessTimingParameter`](#class_k_w_p2000_1a953906eda48ecaea0d1ad8a2f1b0e8d5)`(const uint8_t read_only)`

Ask and print the Timing Parameters from the ECU.

#### Parameters
* `read_only` Default: `true` this avoid the possibility to unintentionally change them
* `read_only` Optional, default to `true`. This avoid the possibility to unintentionally change them

#### `public void `[`resetTimingParameter`](#class_k_w_p2000_1ab9246be67a37784274c444801878edb3)`()`

Reset the Timing Parameters to the default settings from the ECU.

#### `public void `[`changeTimingParameter`](#class_k_w_p2000_1abd42cfde45d2f41846915b58dfe9c15e)`(uint32_t new_atp,const uint8_t new_atp_len)`
#### `public void `[`changeTimingParameter`](#class_k_w_p2000_1a3ccc4ebcea810e12b2ceb63c9a4858a0)`(uint32_t new_atp,const uint8_t new_atp_len)`

Change the Timing Parameters to custom ones.

Expand All @@ -249,7 +278,7 @@ Change the Timing Parameters to custom ones.
Print a rich and useful set of information about the ECU status and errors.

#### Parameters
* `time` Default: `2000ms` the time between one print and the other
* `time` Optional, default to `2000`milliseconds. The time between one print and the other

#### `public void `[`printSensorsData`](#class_k_w_p2000_1ab9135d21a343e0e90f0527f4ab22b531)`()`

Expand All @@ -264,22 +293,22 @@ Print the last response received from the ECU.
Get the connection status.

#### Returns
int8_t It could be `true` or `false`
It could be `true` or `false`

#### `public int8_t `[`getError`](#class_k_w_p2000_1a2b1b535611064e42990ebfe292c3f53a)`()`

This say you only if there are/aren't errors, to see them use `[printStatus()](#class_k_w_p2000_1afefd32e48fc101c9b2307aa9a2c498b2)`

#### Returns
int8_t It could be `true` or `false`
It could be `true` or `false`

#### `public void `[`resetError`](#class_k_w_p2000_1a44fbde61c33c7cbe7b7abc881735c595)`()`

Reset the errors from the ECU, use with caution.

#### `public uint8_t `[`getGPS`](#class_k_w_p2000_1a8981e2ea9bc9f222518e913965146b7e)`()`

Get* the ECU value you need: GPS, RPM, SPEED, TPS, IAP, IAT, ECT, STPS, more coming.
Get* the ECU sensor value you need GPS: Gear Position Sensor RPM: Right Per Minutes SPEED: speed of the bike TPS: Throttle Position Sensor IAP: Intake Air Pressure IAT: Intake Air Temperature ECT: Engine Coolant Temperature STPS: Secondary Throttle Position Sensor.

#### Returns
The sensor value from the ECU
Expand Down
4 changes: 4 additions & 0 deletions examples/basic_working/basic_working.ino
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ void loop()
ECU.dealerMode(dealer_status);
break;

case 'D':
ECU.readTroubleCodes();
break;

case 's':
ECU.requestSensorsData();
ECU.printSensorsData();
Expand Down
6 changes: 5 additions & 1 deletion keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ dealerMode KEYWORD2
initKline KEYWORD2
stopKline KEYWORD2
requestSensorsData KEYWORD2
readTroubleCodes KEYWORD2
clearTroubleCodes KEYWORD2
keepAlive KEYWORD2

handleRequest KEYWORD2
Expand Down Expand Up @@ -50,4 +52,6 @@ getSTPS KEYWORD2
DEBUG_LEVEL_NONE LITERAL1
DEBUG_LEVEL_DEFAULT LITERAL1
DEBUG_LEVEL_VERBOSE LITERAL1
maybe LITERAL1
READ_TOTAL LITERAL1
READ_ONLY_ACTIVE LITERAL1
READ_ALL LITERAL1
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=KWP2000
version=1.0.0
version=1.1.0
author=Vincenzo G.
maintainer=Vincenzo G.
sentence=A library that makes interfacing with motorbikes a breeze.
Expand Down
Loading

0 comments on commit 5f818a8

Please sign in to comment.