Emulating a Vehicle

Let’s be honest, developing OBDII tools directly from your car isn’t the most practical setup. For convenience (and comfort), we use a vehicle emulator during development. It simulates real car responses at your desk, allowing you to test and build features without constantly connecting to a real vehicle.

This is especially handy when you’re iterating quickly, writing tests, or just don’t want to sit in the driveway with a laptop balanced on your knees.

Prerequisites

To simulate a vehicle, you can use the ELM327-Emulator, a third-party tool included automatically when you install the library with the sim extra:

pip install py-obdii[sim]

The emulator simulates a vehicle’s responses and can be connected to just like a real car through a virtual serial port.

Run and use the emulator on Linux.

  1. Install the library with development dependencies

  2. Start the ELM327 Emulator

    $ python -m elm -s car --baudrate 38400
    

    The emulator will display the virtual port (e.g., /dev/pts/1) to use for connection.

  3. Connect your Python code to the emulator (e.g., /dev/pts/1):

    main.py
    1from obdii import Connection
    2
    3with Connection("/dev/pts/1", baudrate=38400) as conn:
    4    # Your code here
    

To run and use the emulator on Windows, you will need to create virtual serial ports.

  1. Install the library with development dependencies

  2. Install a kernel-mode virtual serial port driver like com0com

    Note

    On Windows 10 and 11, Secure Boot may block unsigned drivers. So make sure you download and install the signed version of com0com.

  3. Create a virtual COM port pair (e.g., COM5 ↔ COM6)

  4. Start the ELM327 Emulator on one end of the virtual connection (e.g., COM6):

    python -m elm -p COM5 -s car --baudrate 38400
    

    This command launches the emulator in car simulation mode on COM5.

  5. Connect your Python code to the other end of the virtual pair (e.g., COM6):

    main.py
    1from obdii import Connection
    2
    3with Connection("COM6", baudrate=38400) as conn:
    4    # Your code here