Skip to content

Commit 7aaa025

Browse files
committed
Initial work to provide basic read / write operations for interfacing with an ELM327 OBD-II interface.
0 parents  commit 7aaa025

15 files changed

+509
-0
lines changed

.gitignore

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
*.py[cod]
2+
venv
3+
*.so
4+
*.egg
5+
*.egg-info
6+
dist
7+
build
8+
eggs
9+
parts
10+
bin
11+
var
12+
sdist
13+
develop-eggs
14+
.installed.cfg
15+
lib64
16+
venv*
17+
__pycache__
18+
pip-log.txt
19+
.coverage
20+
.tox
21+
nosetests.xml
22+
*.mo
23+
.project
24+
.pydevproject
25+
.idea

.travis.yml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
language: python
2+
python:
3+
- "2.7"
4+
- "3.4"
5+
- "pypy"
6+
install: "pip install ."
7+
script: "python setup.py nosetests"

LICENSE.txt

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2014 HUB-OLOGY
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.rst

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
|build| |version| |wheel|
2+
3+
ShadeTree OBD
4+
=============
5+
6+
ShadeTree OBD provides easy access to ELM327 OBD-II Interfaces in Python.
7+
It's been successfully used with ELM327 OBD-II bluetooth scanners and the Raspberry Pi to create portable automotive
8+
OBD-II logging devices. Data can be captured during test drives for later analysis. It may also be used as part of
9+
routine driving to gather information to determine an optimal vehicle maintenance schedule. Continuous logging may
10+
also help with vehicle troubleshooting when problems occur.
11+
12+
This library was originally developed as a teaching tool to help the best rural problem solvers get excited about
13+
computing via their existing passion for automotive work.
14+
15+
The library is still under development. Initial work focused on reading from and writing to ELM327 OBD-II interfaces.
16+
Work is ongoing to build more tools and services around the core library.
17+
18+
Installation
19+
------------
20+
21+
Install using pip_
22+
23+
.. code-block:: bash
24+
25+
$ pip install shadetree
26+
27+
Quick start
28+
-----------
29+
30+
.. code-block:: python
31+
32+
import shadetree
33+
34+
35+
Supported Python Versions
36+
-------------------------
37+
38+
ShadeTree OBD makes every effort to ensure smooth operation with these Python interpreters:
39+
40+
* 2.7+
41+
* 3.4+
42+
* PyPy
43+
44+
License
45+
-------
46+
47+
See LICENSE_ for details.
48+
49+
.. _pip: https://pypi.python.org/pypi/pip
50+
.. _LICENSE: LICENSE.txt
51+
52+
.. |version| image:: https://badge.fury.io/py/shadetree.svg
53+
:target: https://pypi.python.org/pypi/shadetree/
54+
55+
.. |build| image:: https://api.travis-ci.org/hub-ology/shadetree.svg
56+
:target: https://travis-ci.org/hub-ology/shadetree
57+
58+
.. |wheel| image:: https://pypip.in/wheel/shadetree/badge.png
59+
:target: https://pypi.python.org/pypi/shadetree/

setup.cfg

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[wheel]
2+
universal = 1

setup.py

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
"""
2+
ShadeTree OBD
3+
-------------
4+
5+
A Python library to help the Shade Tree Mechanic easily interface with OBD-II scanners
6+
7+
ShadeTree OBD is distributed under the MIT License.
8+
"""
9+
from setuptools import setup
10+
11+
12+
setup(
13+
name="shadetree",
14+
version="0.1",
15+
license="MIT",
16+
author="HUB-OLOGY",
17+
author_email="[email protected]",
18+
url="http://hub-ology.org",
19+
download_url = 'https://github.com/corbinbs/shadetree/tarball/0.1',
20+
description="ShadeTree OBD",
21+
long_description=__doc__,
22+
packages=["shadetree", "shadetree.obd"],
23+
scripts=["bin/shadetree"],
24+
zip_safe=False,
25+
include_package_data=True,
26+
platforms="any",
27+
install_requires=[
28+
"pyserial>=2.7"
29+
],
30+
tests_require=[
31+
"nose"
32+
],
33+
test_suite = 'nose.collector',
34+
keywords = ['obd', 'obdii', 'automotive'],
35+
classifiers=[
36+
"Development Status :: 3 - Alpha",
37+
"Environment :: Web Environment",
38+
"Intended Audience :: Developers",
39+
"Intended Audience :: Education",
40+
"License :: OSI Approved :: MIT License",
41+
"Operating System :: OS Independent",
42+
"Programming Language :: Python",
43+
"Programming Language :: Python :: 2.7",
44+
"Programming Language :: Python :: 3.4",
45+
"Programming Language :: Python :: Implementation :: PyPy",
46+
"Topic :: Communications",
47+
"Topic :: Scientific/Engineering :: Information Analysis",
48+
"Topic :: Software Development :: Libraries :: Python Modules",
49+
"Topic :: System :: Logging",
50+
"Topic :: Utilities"
51+
]
52+
)

shadetree/__init__.py

Whitespace-only changes.

shadetree/elm327.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
#AT command strings
3+
RESET_COMMAND = "AT Z"
4+
ECHO_OFF_COMMAND = "AT E0"
5+
ECHO_ON_COMMAND = "AT E1"
6+
BATTERY_VOLTAGE_COMMAND = "AT RV"
7+
SELECT_PROTOCOL_COMMAND = "AT SP 0"
8+
9+
10+
#TODO: externalize configuration settings
11+
DEFAULT_BAUDRATE = 38400
12+
DEFAULT_BYTESIZE = 8
13+
#This seems to be the most common port used when combining an ELM327 bluetooth OBDII scanner with a Raspberry Pi
14+
#Will make this more general purpose later on. Main focus now is specific use with ELM327 bluetooth on Raspberry Pi
15+
DEFAULT_PORTNAME = '/dev/rfcomm0'
16+
DEFAULT_STOPBITS = 1
17+
DEFAULT_TIMEOUT = 3
18+
19+
DEFAULT_RETRIES = 10

shadetree/obd/__init__.py

Whitespace-only changes.

shadetree/obd/commands.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from shadetree.obd import modes
2+
from shadetree.obd import pids
3+
4+
VEHICLE_ID_NUMBER_COMMAND = '{0} {1}'.format(modes.VEHICLE_INFORMATION_DATA, pids.VEHICLE_IDENTIFICATION_NUMBER)
5+
ECU_NAME_COMMAND = '{0} {1}'.format(modes.VEHICLE_INFORMATION_DATA, pids.ECU_NAME)
6+
FUEL_TYPE_COMMAND = '{0} {1}'.format(modes.CURRENT_DATA, pids.FUEL_TYPE)
7+
8+
CLEAR_TROUBLE_CODES_COMMAND = '{0}'.format(modes.CLEAR_TROUBLE_CODES_AND_VALUES)
9+
10+
CURRENT_ENGINE_COOLANT_TEMP_COMMAND = '{0} {1}'.format(modes.CURRENT_DATA, pids.ENGINE_COOLANT_TEMPERATURE)
11+
CURRENT_ENGINE_OIL_TEMP_COMMAND = '{0} {1}'.format(modes.CURRENT_DATA, pids.ENGINE_OIL_TEMPERATURE)
12+
CURRENT_ENGINE_RPM = '{0} {1}'.format(modes.CURRENT_DATA, pids.ENGINE_RPM)

shadetree/obd/fuel_type.py

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
#Mode 01 PID 51 returns a value for the vehicle's fuel type
3+
4+
FUEL_TYPE_DESCRIPTION = {
5+
0: 'Not Available',
6+
1: 'Gasoline',
7+
2: 'Methanol',
8+
3: 'Ethanol',
9+
4: 'Diesel',
10+
5: 'Liquefied petroleum gas (LPG)',
11+
6: 'Compressed natural gas (CNG)',
12+
7: 'Propane',
13+
8: 'Electric',
14+
9: 'Bifuel running Gasoline',
15+
10: 'Bifuel running Methanol',
16+
11: 'Bifuel running Ethanol',
17+
12: 'Bifuel running Liquefied petroleum gas (LPG)',
18+
13: 'Bifuel running Compressed natural gas (CNG)',
19+
14: 'Bifuel running Propane',
20+
15: 'Bifuel running Electricity',
21+
16: 'Bifuel running electric and combustion engine',
22+
17: 'Hybrid gasoline',
23+
18: 'Hybrid Ethanol',
24+
19: 'Hybrid Diesel',
25+
20: 'Hybrid Electric',
26+
21: 'Hybrid running electric and combustion engine',
27+
22: 'Hybrid Regenerative',
28+
23: 'Bifuel running diesel'
29+
}

shadetree/obd/modes.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#OBD Modes (described in OBD-II standard SAE J1979)
2+
CURRENT_DATA = "01"
3+
FREEZE_FRAME_DATA = "02"
4+
REQUEST_TROUBLE_CODES = "03"
5+
CLEAR_TROUBLE_CODES_AND_VALUES = "04"
6+
OXYGEN_SENSOR_DATA = "05"
7+
SYSTEM_MONITORING_DATA = "06"
8+
PENDING_TROUBLE_CODES = "07"
9+
CONTROL_OPERATION = "08"
10+
VEHICLE_INFORMATION_DATA = "09"
11+
PERMANENT_TROUBLE_CODES = "0A"
12+
13+
DEFAULT_OBD_MODE = CURRENT_DATA

shadetree/obd/pids.py

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Information about OBD-II PIDs
2+
# http://en.wikipedia.org/wiki/OBD-II_PIDs
3+
4+
#PID hex codes
5+
PIDS_SUPPORTED_00_20 = "00"
6+
MONITOR_STATUS_SINCE_DTC_CLEARED = "01"
7+
FREEZE_DTC = "02"
8+
VEHICLE_IDENTIFICATION_NUMBER = "02"
9+
FUEL_SYSTEM_STATUS = "03"
10+
CALCULATED_ENGINE_LOAD = "04"
11+
ENGINE_COOLANT_TEMPERATURE = "05"
12+
SHORT_TERM_FUEL_TRIM_BANK_1 = "06"
13+
LONG_TERM_FUEL_TRIM_BANK_1 = "07"
14+
SHORT_TERM_FUEL_TRIM_BANK_2 = "08"
15+
LONG_TERM_FUEL_TRIM_BANK_2 = "09"
16+
FUEL_PRESSURE = "0A"
17+
ECU_NAME = "0A"
18+
INTAKE_MANIFOLD_PRESSURE = "0B"
19+
ENGINE_RPM = "0C"
20+
VEHICLE_SPEED = "0D"
21+
TIMING_ADVANCE = "0E"
22+
INTAKE_AIR_TEMPERATURE = "0F"
23+
MAF_AIR_FLOW = "10"
24+
THROTTLE_POSITION = "11"
25+
26+
#TODO: Oxygen sensors
27+
28+
AUXILIARY_INPUT_STATUS = "1E"
29+
ENGINE_RUN_TIME_SINCE_START = "1F"
30+
PIDS_SUPPORTED_21_40 = "20"
31+
DISTANCE_TRAVELED_WITH_MIL_ON = "21"
32+
33+
FUEL_RAIL_PRESSURE = "23"
34+
35+
COMMANDED_EGR = "2C"
36+
EGR_ERROR = "2D"
37+
COMMANDED_EVAPORATIVE_PURGE = "2E"
38+
FUEL_LEVEL_INPUT = "2F"
39+
DISTANCE_TRAVELED_SINCE_CODES_CLEARED = "31"
40+
EVAP_SYSTEM_VAPOR_PRESSURE = "32"
41+
BAROMETRIC_PRESSURE = "33"
42+
43+
PIDS_SUPPORTED_41_60 = "40"
44+
CONTROL_MODULE_VOLTAGE = "41"
45+
ABSOLUTE_LOAD_VALUE = "42"
46+
AMBIENT_AIR_TEMPERATURE = "46"
47+
48+
TIME_RUN_WITH_MIL_ON = "4D"
49+
TIME_SINCE_TROUBLE_CODES_CLEARED = "4E"
50+
51+
FUEL_TYPE = "51"
52+
ETHANOL_FUEL_PERCENTAGE = "52"
53+
54+
RELATIVE_ACCELERATOR_PEDAL_POSITION = "5A"
55+
HYBRID_BATTERY_PACK_REMAINING_LIFE = "5B"
56+
ENGINE_OIL_TEMPERATURE = "5C"
57+
FUEL_INJECTION_TIMING = "5D"
58+
ENGINE_FUEL_RATE = "5E"
59+
60+
61+
PIDS_SUPPORTED_61_80 = "60"
62+
ENGINE_PERCENT_TORQUE = "64"
63+
64+
#TODO: remaining PIDs

0 commit comments

Comments
 (0)