Skip to main content

can_mcp2515

MCP2515 CAN bus controller for automotive and industrial communication via SPI.

Overview

The can_mcp2515 node interfaces with the MCP2515 CAN bus controller via SPI, paired with a TJA1050 or MCP2551 CAN transceiver. CAN (Controller Area Network) is the standard bus protocol for automotive and industrial systems, providing robust, multi-master, priority-based communication. Use this node to read vehicle OBD-II data, interface with industrial equipment, or build custom CAN networks.

1Mbps
Max Bitrate
8
Bytes per Frame
2048
Standard IDs
40m
Max Bus Length (1M)

Properties

Property Type Required Default Description
spiBus number No 0 SPI bus number
spiDevice number No 0 SPI chip select (CE0=0, CE1=1)
spiSpeed number No 10000000 SPI clock speed in Hz (max 10MHz)
intPin number No 25 GPIO pin for MCP2515 interrupt output
oscillator select No "8" Crystal oscillator frequency in MHz: "8", "16", "20"
bitrate select No "500k" CAN bus bitrate: "5k", "10k", "20k", "50k", "100k", "125k", "250k", "500k", "1000k"
mode select No "normal" Operating mode: "normal", "loopback" (self-test), "listen" (read-only)

Inputs

Send CAN Frame
{
  "payload": {
    "id": 1824,
    "data": [0x02, 0x01, 0x0C, 0x00,
             0x00, 0x00, 0x00, 0x00],
    "ext": false,
    "rtr": false
  }
}
OBD-II PID Request (Engine RPM)
{
  "payload": {
    "id": 2015,
    "data": [0x02, 0x01, 0x0C, 0x00,
             0x00, 0x00, 0x00, 0x00]
  }
}

Outputs

Received CAN Frame
{
  "payload": {
    "id": 2024,
    "data": [0x04, 0x41, 0x0C, 0x1A,
             0xF8, 0x00, 0x00, 0x00],
    "dlc": 8,
    "ext": false,
    "rtr": false
  },
  "timestamp": "2025-01-15T10:30:00.000Z"
}
TX Confirmation
{
  "payload": true,
  "id": 1824,
  "topic": "can/tx/done"
}

Wiring Diagram

MCP2515 Module to Raspberry Pi

  MCP2515 Module         Raspberry Pi
  +-------------+       +--------------+
  | VCC   (5V)  |-------| 5V    (Pin 2)|
  | GND         |-------| GND   (Pin 6)|
  | CS          |-------| CE0   (Pin 24)|
  | SO  (MISO)  |-------| MISO  (Pin 21)|
  | SI  (MOSI)  |-------| MOSI  (Pin 19)|
  | SCK         |-------| SCLK  (Pin 23)|
  | INT         |-------| GPIO25(Pin 22)|
  +-------------+       +--------------+

         CAN Bus
  +-------------+       +-------------+
  | CAN_H  -----|-------|----- CAN_H  |
  | CAN_L  -----|-------|----- CAN_L  |
  | GND    -----|-------|----- GND    |
  +-------------+       +-------------+
   MCP2515 Module        Target Device

Wiring Notes

VCC use 5V for the MCP2515 module (has onboard regulator)

INT active-low interrupt, triggers on RX or error

CAN_H / CAN_L differential pair, use twisted pair cable

Termination 120 ohm resistor at each end of bus

Warning: Verify your oscillator frequency matches the module hardware. Most cheap modules use 8MHz crystals. Using the wrong setting will result in no communication.

Example Use Cases

OBD-II Vehicle Diagnostics

Query engine RPM and coolant temperature via OBD-II PIDs and display on dashboard gauges.

inject (1s) can_mcp2515 (tx/rx) function (decode PID) gauge
[
  {
    "id": "obd-poll",
    "type": "inject",
    "repeat": "1",
    "payload": "{ "id": 2015, "data": [2, 1, 12, 0, 0, 0, 0, 0] }",
    "payloadType": "json"
  },
  {
    "id": "can-bus",
    "type": "can_mcp2515",
    "spiBus": 0,
    "spiDevice": 0,
    "intPin": 25,
    "oscillator": "8",
    "bitrate": "500k",
    "mode": "normal"
  },
  {
    "id": "decode-pid",
    "type": "function",
    "name": "Decode OBD-II RPM"
  },
  {
    "id": "rpm-gauge",
    "type": "gauge",
    "name": "Engine RPM",
    "min": 0,
    "max": 8000
  }
]

Industrial CAN Sensor Network

Monitor CAN bus traffic from industrial sensors and log all frames to InfluxDB for analysis.

can_mcp2515 (listen) switch (by CAN ID) influxdb
[
  {
    "id": "can-listen",
    "type": "can_mcp2515",
    "bitrate": "250k",
    "mode": "listen",
    "oscillator": "8"
  },
  {
    "id": "route-id",
    "type": "switch",
    "property": "payload.id",
    "rules": [
      { "t": "eq", "v": "256" },
      { "t": "eq", "v": "512" },
      { "t": "else" }
    ]
  },
  {
    "id": "store-influx",
    "type": "influxdb",
    "measurement": "can_frames"
  }
]

Loopback Self-Test

Verify MCP2515 wiring and configuration using loopback mode (no external bus needed).

[
  {
    "id": "test-inject",
    "type": "inject",
    "payload": "{ "id": 100, "data": [1, 2, 3, 4] }",
    "payloadType": "json"
  },
  {
    "id": "can-loopback",
    "type": "can_mcp2515",
    "bitrate": "500k",
    "mode": "loopback",
    "oscillator": "8"
  },
  {
    "id": "verify-rx",
    "type": "debug",
    "name": "Loopback RX"
  }
]

Common Use Cases

Vehicle OBD-II

Read engine data, DTCs, and live sensor values from cars

Industrial Automation

Interface with CAN-based PLCs, actuators, and controllers

Bus Sniffing and Logging

Monitor and record all CAN traffic for analysis and debugging

Robotics and Drones

CAN-based motor controllers and sensor fusion networks

Related Nodes