Skip to content
forked from sugiuraii/ECUSim

ECU simulator using Python to communicate OBDII PID messages via CAN.

License

Notifications You must be signed in to change notification settings

SBolinha/ECUSim

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

69 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ECUSim

  • This is a ecu simulator for OBDII scantool like ELM327.
  • This sketch can respond OBDII CAN message with using MCP2515 CAN controller board.

Demonstration

Demo

Dependency

Hardwares need to run the sketch

  • Arduino Uno or its compatilble boards.
  • MCP2515 CAN controller board.
  • Connection Arduino <-> MCP2515 board
    • This sketch does not use interrupt. No need to connect INT and D2 pin.

Wiring

Install

  • Before the install, please modify the argument of CAN.begin(CAN_250KBPS, MCP_8MHZ) in CANMessageHandle.ino, follwoing CAN speed and the frequency of XTAL of MCP2515 board.
  • And please installcoryjfowler/MCP_CAN_lib MCP2515 library and altelch/iso-tp ISO-TP library.
    • Get zip file of repository and install on Arduino IDE.
  • After setting the parameter above, compile ECUSim.ino and flash to arduino board.

GUI fronend

  • GUI frontend is available on sugiuraii/ECUSimGUI.
  • You can control PID sensor value by GUI fronted, by using the program above.

Features

  • Sends value back on PID request of service 0x01
  • Control PID sensor values by serial port (using PC GUI program)
  • Responds ECU ID
  • Responds 6PIDS request by single message (J1939)

Control PID sensor values via serial port

After the CAN initialization (Serial message by "CAN BUS Shield init ok!"), the arduino board wait PID sensor value update message on seial port. The update serial scommand consists with 10 character and LF(\n).

  • The first 2 characters select (hexadecimal) PID.
  • The following 8 characters set the sensor value of PID.
    • Plesase fill 8 character regardless of the number of value bytes. See the example below.

Example

  • Set PID 0x04(= Calculated engine load) to 60.0% (153 in decimal, 0x99 in hexadecimal)
    • -> Send "0499000000\n" via serial port (latter 3 bytes are ignored.)
  • Set PID 0x0C(= Engine speed rpm) to 5745rpm (22980 in decimal, 0x59C4 in hexadecimal)
    • -> Send "0C59C40000\n" via serial port (latter 2 bytes are ignored.)
  • Note that PIDs of "Supported PID" (such as 0x00, 0x20, 0x40, 0x60, 0x80, 0xA0, 0xC0 and 0xE0) are automatically calculated on compling the sketch. You don't have to set by serial port command.

Enable/disable debug message

You can enable/disable error or debug message on ECUSim.h.

constexpr bool PIDSET_DEBUG = false;
constexpr bool PIDSET_ERROR = true;
constexpr bool CANMSG_DEBUG = false;
constexpr bool CANMSG_ERROR = true;
constexpr bool CANMSG_FATAL = true;

Supported PID's

See PIDMap_Definition.h

Enable/disable PID

Edit constexpr unsigned char _PID_BYTE_LENGTH[256] in PIDMap_Definition.h. This array stores the data byte length of each PIDs. By setting byte length to zero, you can disable PID.

constexpr unsigned char _PID_BYTE_LENGTH[256] =
    {
        0, // PID:0x00 (refer PIDAvailableFlagMap in PROGMEM)
        4, // PID:0x01
        2, // PID:0x02
        2, // PID:0x03 // <- Set PID data byte length to enable PID, set zero to disable PID.
        1, // PID:0x04
        1, // PID:0x05
        1, // PID:0x06

Sources

License

MIT License

About

ECU simulator using Python to communicate OBDII PID messages via CAN.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 96.7%
  • Python 2.1%
  • C 1.2%