i2c_can
Python library to communicate with the Longan Labs I2C CAN Bus Module
Also sold as the SEEED STUDIO 113020111 I2C CAN-BUS Module
This library is nowhere near as safe, good, advanced, robust OR SAFE as https://github.com/commaai/panda so don't use it to drive a car.
Overview
add text
Features
- tbc
Installation
Install the TPMS library using pip:
pip install i2c_can
Usage
add text
Example Code
add examples
TLDR
pip install i2c_can
from i2c_can import I2C_CAN, CAN_500KBPS, CAN_OK, CAN_MSGAVAIL
import time
def initialize_can():
i2c_can = I2C_CAN(0x25) # Replace with the actual I2C address
i2c_can.begin()
print("begin to init can")
while True:
if i2c_can.begin_CAN(CAN_500KBPS) == CAN_OK:
break
print("CAN BUS FAIL!")
time.sleep(0.1)
print("CAN BUS OK!")
return i2c_can
def send_obd2_request(i2c_can, pid):
request = [0x02, 0x01, pid, 0x00, 0x00, 0x00, 0x00, 0x00]
i2c_can.send_msg_buf(0x7DF, 0, 0, 8, request)
print(f"Sent OBD2 request for PID {pid:02X}")
def receive_obd2_response(i2c_can):
if i2c_can.check_receive() == CAN_MSGAVAIL:
length, buf = i2c_can.read_msg_buf()
if length:
can_id = i2c_can.get_can_id()
print(f"Received CAN ID: {can_id:X}")
print("Data: ", ' '.join(f"{byte:02X}" for byte in buf))
return buf
return None
def parse_response(pid, response):
if pid == 0x0C: # Engine RPM
rpm = ((response[3] * 256) + response[4]) / 4
print(f"Engine RPM: {rpm}")
elif pid == 0x0D: # Vehicle Speed
speed = response[3]
print(f"Vehicle Speed: {speed} km/h")
elif pid == 0x05: # Engine Coolant Temperature
temp = response[3] - 40
print(f"Engine Coolant Temperature: {temp} °C")
def main():
i2c_can = initialize_can()
# List of PIDs to monitor
pids = [0x0C, 0x0D, 0x05] # Engine RPM, Vehicle Speed, Engine Coolant Temperature
while True:
for pid in pids:
send_obd2_request(i2c_can, pid)
response = receive_obd2_response(i2c_can)
if response:
if response[2] == pid:
parse_response(pid, response)
time.sleep(1) # Delay between requests for different PIDs
if __name__ == "__main__":
main()
TODO
Check it actually works...
License
This project is licensed under the MIT License - see the LICENSE file for details.
Metadata
Release files for i2c-can 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| i2c_can-0.0.2.tar.gz | 4.6 kB | Without provenance | Details for i2c_can-0.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| i2c_can-0.0.2-py3-none-any.whl | Python 3 | none | any | Details for i2c_can-0.0.2-py3-none-any.whl |
Total release size: 10.3 kB
Release files / i2c_can-0.0.2.tar.gz
| Download URL | i2c_can-0.0.2.tar.gz |
|---|---|
| Size | 4.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
afa11588807a820a32b923614c39a3a8bfcd0779f99bd3fe3beda4120563360a
|
|
BLAKE2b-256 checksum How to use checksums |
9b7ff02fe635033aafb1a92758f2bf7e987b567ff9565b53199b298e9224b6b4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.6
|
Release files / i2c_can-0.0.2-py3-none-any.whl
| Download URL | i2c_can-0.0.2-py3-none-any.whl |
|---|---|
| Size | 5.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
616addb55adc3cbb9ce0a81d754270c5a2e51f6dbeaa7ed849a6af9191696212
|
|
BLAKE2b-256 checksum How to use checksums |
01b896989fbc82a150cbdb80be3ce38a0dc9d801c840f9f0a39712ea03844b88
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.6
|
Security for i2c-can 0.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.