Skip to main content

ESP32 with CAN Transceiver

Uses the native TWAI (Two-Wire Automotive Interface) peripheral built into all ESP32 chips. Requires an external CAN transceiver module.

Specifications

PropertyValue
CAN ControllerNative TWAI peripheral
LibraryESP-IDF driver/twai.h
Driver DefineDRIVER_TWAI
TransceiverExternal (SN65HVD230, TJA1050, MCP2551, etc.)
StatusTested

Required Hardware

  • Any ESP32 board (e.g. ESP32-DevKitC)
  • External CAN transceiver module (e.g. SN65HVD230, TJA1050, or MCP2551)

Default Pin Configuration

PinGPIOPurpose
TWAI_TX_PINGPIO_NUM_5Connect to transceiver TX
TWAI_RX_PINGPIO_NUM_4Connect to transceiver RX

If you have other GPIO Pins connected to the CAN transceiver Module. You can define the Ports in /include/arduino_enytrypoint.h

Configuration

In sketch_config.h:

#define DRIVER_TWAI

Arduino IDE Setup

  1. Add board URL: https://espressif.github.io/arduino-esp32/package_esp32_index.json
  2. Install esp32 by Espressif Systems from Boards Manager
  3. Select your ESP32 board (e.g. ESP32 Dev Module)
  4. No additional libraries needed — the TWAI driver is built into the ESP32 Arduino core

PlatformIO

pio run -e esp32_twai
pio run -e esp32_twai --target upload
tip

Hold the BOOT button during upload if auto-reset does not work.

important

If your CAN transceiver module has an onboard termination resistor, remove or disable it. The vehicle's CAN bus already has its own termination.