Hardware-in-the-Loop (HIL)

Hardware-in-the-Loop (HIL) simulation enables the integration of real hardware components with the BeamNG.tech simulation environment. This approach allows you to test and validate electronic control units (ECUs) and other hardware components in a controlled virtual environment.

This documentation presents an example HIL implementation using specific hardware components (PEAK CAN-Bus adapters, AiM displays, etc.). This is not the only way to implement HIL with BeamNG.tech—the approach can be adapted to work with various hardware interfaces and communication protocols depending on your specific requirements.

HIL Setup Diagram HIL Setup Diagram

Overview

HIL testing combines physical hardware components with simulated vehicle dynamics and environments. This enables comprehensive testing of:

  • Electronic control units (ECUs)
  • Sensor interfaces
  • Actuator systems
  • Communication protocols (CAN Bus, etc.)

Key Features

  • Real-time hardware integration
  • Bidirectional communication between simulation and hardware
  • Support for CAN Bus protocols

Software Implementation

The simulation communicates with CAN-Bus attached devices via a PEAK System PCAN USB Adapter that is controlled by PEAK’s custom DLL via FFI (Foreign Function Interface) from vlua.

Code Location

The relevant code can be found in \lua\vehicle\extensions\tech\CANBus, with CANBusPeak.lua being the central interface to the CAN functionality. The other files implement module-specific features and need to be loaded in order to be used.

Important: The CANBusPeak extension does not need to be loaded manually—it’s a dependency of the other extensions and is loaded automatically.

For implementation details and code examples, see the CAN Bus interface documentation .


Hardware Components

PEAK CAN-Bus USB Adapter for Hardware Connection

Purpose: Connect CAN-Bus devices to a computer and therefore the simulation. Uses USB with a provided closed-source DLL to expose its API to vlua via FFI.

PEAK CAN-Bus USB Adapter PEAK CAN-Bus USB Adapter

Used Hardware:

  • PEAK System PCAN USB FD
  • PEAK System PCAN USB opto-decoupled
  • D-SUB DE9 Connector to interface between USB Adapter and CAN wiring loom
  • Included 120 Ohm CAN termination resistor inside the D-SUB connector

CAN-Bus Cables and Wiring Loom

Purpose: Connect individual CAN-Bus modules with each other.

4-Wire Loom:

  • CAN High
  • CAN Low
  • +12V
  • GND
  • Textile tape wrapped
  • Protective nylon sheathing

Connectors:

  • 6-Pin Push/Pull Connector
  • CAN Adapter Cable to PEAK System CAN USB Adapter (note: does not have +12V wire, only CAN High, CAN Low, and GND)

CAN-Bus Cables CAN-Bus Cables

AiM MXG 1.2 Racing Display for Real-Time Data Visualization

Purpose: Display realtime simulation data on a real-world CAN-connected racing display/logger.

AiM MXG 1.2 Display AiM MXG 1.2 Display

Used Hardware:

  • AiM MXG 1.2 Racing Display
  • 37-Pin DEUTSCH Connector Wiring Loom
  • Custom 3D-Printed Housing
  • Custom Wiring Loom for CAN and +12V

Configuration: AiM’s own software called “Race Studio 3” is used to configure the display. The software needs two configuration files:

  1. Display Config: Defines what is shown where, which display pages exist, etc.
  2. ECU Config: Defines the custom CAN protocol between the simulation and the display.

AiM MXG Display Configuration AiM MXG Display Configuration

AiM MXG Display Setup AiM MXG Display Setup

For official documentation from AiM, see: AiM Sportline Documentation

External Dashboard Display for CAN-Bus Signal Monitoring

Purpose: Display real-time CAN-Bus signals and simulation data on external displays or dashboards for monitoring and demonstration purposes.

Implementation Options:

  • Connect CAN-Bus signals to external displays or dashboards
  • Use Raspberry Pi or similar devices to process and display CAN data
  • Create custom visualization interfaces for specific use cases
  • Display signals on secondary monitors or dedicated hardware displays

This approach is particularly useful for demonstrations, monitoring system behavior, and providing visual feedback during HIL testing sessions.


Getting Started

To set up HIL testing with BeamNG.tech, you’ll need:

Software Requirements:

  • BeamNG.tech software (v0.30 or later)
  • PEAK System drivers and DLL

Hardware Requirements:

  • PEAK System CAN-Interface (PCAN USB models tested, other models may require additional work)
  • A working CAN network with proper termination and wiring
  • 120 Ohm termination resistor (included in D-SUB connector)

Network Configuration:

  • Proper CAN bus termination (120 Ohm resistor at each end of the bus)
  • Correct wiring (CAN High, CAN Low, +12V, GND)
  • Proper connector configuration

Given the unique nature of CAN setups and required software support, we do not provide pre-made support for specific CAN devices. Instead, you will need to write the supporting code in vehicle lua yourself. For an example of communication with a race car dashboard, take a look at \lua\vehicle\extensions\tech\CANBus\RacingDisplay.lua.

Last modified: January 26, 2026

Any further questions?

Join our discord
Our documentation is currently incomplete and undergoing active development. If you have any questions or feedback, please visit this forum thread.