Skip to main content

Serial module for handling live sensor data from a vehicle's OBD-II port

Project description

A python module for handling realtime sensor data from OBD-II vehicle ports

This library is forked from:

Dependencies

  • pySerial

  • OBD-II adapter (ELM327 Bluetooth Adapter or ELM327 USB Cable)

Usage

After installing the library, simply import ‘obd’, and create a new OBD connection object. By default, python-OBD will scan for Bluetooth and USB serial ports (in that order), and will pick the first connection it finds. The port can also be specified manually by passing a connection string to the OBD constructor. You can also use the scanSerial helper retrieve a list of connected ports:

import obd

connection = obd.OBD() # create connection object

# OR

connection = obd.OBD("/dev/ttyUSB0") # create connection with USB 0

# OR

ports = obd.scanSerial() # return list of valid USB or RF ports
print ports
connection = obd.OBD(ports[0]) # connect to the first port in the list

Once a connection is made, python-OBD will load a list of the available commands in your car. A “Command” in python-OBD is an object used to query specific information from the vehicle. A command object contains its name, units, codes, and decoding functions. To get the value of a sensor, call the query() function with that sensor’s command as an argument:

import obd

connection = obd.OBD()

for command in connection.supportedCommands:
    print str(command)                      # prints the command name
    response = connection.query(command)    # sends the command, and returns the decoded response
    print response.value, response.unit     # prints the data and units returned from the car

Commands can also be accessed explicitly, either by name, or by code value. The has_command() function will determine whether or not your car supports the requested command:

import obd

connection = obd.OBD()


c = obd.commands.RPM

# OR

c = obd.commands['RPM']

# OR

c = obd.commands[1][12] # mode 1, PID 12 (decimal)


if connection.has_command(c):        # check for existance of sensor
    print connection.query(c).value  # get and print value of sensor

Here are a few of the currently supported commands (for a full list, see commands.py):

(note: support for these commands will vary from car to car)

  • Calculated Engine Load

  • Engine Coolant Temperature

  • Fuel Pressure

  • Intake Manifold Pressure

  • Engine RPM

  • Vehicle Speed

  • Timing Advance

  • Intake Air Temp

  • Air Flow Rate (MAF)

  • Throttle Position

  • Engine Run Time

  • Distance Traveled with MIL on

  • Fuel Rail Pressure (relative to vacuum)

  • Fuel Rail Pressure (direct inject)

  • Fuel Level Input

  • Number of warm-ups since codes cleared

  • Distance traveled since codes cleared

  • Evaporative system vapor pressure

  • Barometric Pressure

  • Control module voltage

  • Relative throttle position

  • Ambient air temperature

  • Commanded throttle actuator

  • Time run with MIL on

  • Time since trouble codes cleared

  • Fuel Type

  • Ethanol Fuel Percent

  • Fuel rail pressure (absolute)

  • Relative accelerator pedal position

  • Hybrid battery pack remaining life

  • Engine oil temperature

  • Fuel injection timing

  • Engine fuel rate

Debug

python-OBD also contains a debug object that can be used to print status messages and errors. Console printing is disabled by default, but can be enabled manually. A custom debug handler can also be set:

import obd

obd.debug.console = True

# AND / OR

def log(msg):
    print msg

obd.debug.handler = log

Enjoy and drive safe!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

obd-0.1.0.tar.gz (31.4 kB view details)

Uploaded Source

File details

Details for the file obd-0.1.0.tar.gz.

File metadata

  • Download URL: obd-0.1.0.tar.gz
  • Upload date:
  • Size: 31.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for obd-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b2aa4e81b072a6dbebf9d2aa30b006bc9c499b3167621d6d7a89603da5537d09
MD5 d54917ddf41c638233350f73b97a5a72
BLAKE2b-256 74c59d2ec7601fd3bfbfe655c268a53c6a34f16d34571fa35537f2299d4cdf0d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page