Skip to content

Talking to your vehicle over the CAN bus with Python

License

Notifications You must be signed in to change notification settings

shnewto/can-we-talk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CAN we talk Python?

Build Status LICENSE

Talking to your vehicle over the CAN bus with Python

Overview

When properly configured and connected to your vehicle's OBD-II port, this Python3 program retrieves the following information from the vehicle:

  • The specific OBD standard this vehicle conforms to
  • The vehicle's current fuel tank level
  • The time, in seconds, since the engine was powered on

Prerequisites for success:

  • A vehicle powered on (motor on)
  • A CAN connection to the OBD-II CAN bus from your computer

Getting Started

Linux Dependencies

  • python3 (sudo apt install python3)

Windows Dependencies

Python 3 Dependencies

  • pip3 install -r requirements.txt --user

CAN Hardware requirements

OBD-II to DB9 Cable CAN USB Adapter

Usage

See the doc string in can_we_talk.py or run ./can_we_talk.py -h for usage specifics.

Usage Notes

Linux

On a Linux system socketcan is a default so can_we_talk.py can rely on the default settings for bustype and channel. After initializing the socketcan interface with:

 sudo ip link set can0 type can bitrate 500000
 sudo ip link set up can0

you can run:

# Default Linux usage
./can_we_talk.py

Windows

On a Windows system socketcan is not available so the bustype and channel must be specified.

If you've installed the Kvaser SDK you need to run:

# Default Kvaser CANlib usage
./can_we_talk.py -c 0 -b kvaser

Using PCAN drivers you can run:

# Default PEAK PCAN-USB usage
./can_we_talk.py -c PCAN_USBBUS1 -b pcan

Running the tests

You can run the tests with pytest, i.e. python3 -m pytest --verbose

Further Reading

OBD-II PIDs

Further Watching

This project supplemented a talk titled CAN we talk Python? Talking to your vehicle over the CAN bus with Python, first given at the PDX Python User Group in July of 2018. You can watch the video here.

About

Talking to your vehicle over the CAN bus with Python

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages