Skip to Content
Software & FirmwareCAN Interface Setup

CAN Interface Setup

This guide brings up a SocketCAN interface on a Linux host and verifies communication with Robstride 00 motors.

Prerequisites

  • Linux (Ubuntu 20.04+ recommended)
  • CAN interface hardware (Canable, PEAK PCAN-USB, or similar)
  • can-utils package

Install can-utils

sudo apt update sudo apt install can-utils

Bring Up the Interface

Plug in your CAN adapter

For USB adapters (Canable), the kernel auto-loads the gs_usb driver. Check it appeared:

ip link show | grep can # should list: can0

Set bus speed and enable the interface

sudo ip link set can0 type can bitrate 1000000 sudo ip link set can0 up

For Raspberry Pi with MCP2515 HAT, add to /boot/config.txt:

dtoverlay=mcp2515-can0,oscillator=16000000,interrupt=25

then run the same ip link commands after reboot.

Verify the interface is up

ip link show can0 # Expected: can0: <NOARP,UP,LOWER_UP,ECHO> ...

Sniff the bus with candump

candump can0

Send the motor-enable command from another terminal (see Motor Control) and confirm frames appear here.

If candump shows error frame entries, check termination resistors and cable length. Also verify bus speed matches the motor’s configured speed (default 1 Mbit/s).

Persistent Configuration (systemd-networkd)

To bring up the CAN interface automatically at boot, create /etc/systemd/network/80-can.network:

[Match] Name=can0 [CAN] BitRate=1000000

Then enable networkd:

sudo systemctl enable systemd-networkd sudo systemctl start systemd-networkd

Python CAN Library

Install python-can for scripting:

pip install python-can

Basic smoke test — listen for one frame:

import can bus = can.Bus(channel='can0', interface='socketcan') msg = bus.recv(timeout=5.0) if msg: print(f"ID: {msg.arbitration_id:#x} Data: {msg.data.hex()}") else: print("No message received") bus.shutdown()
Last updated on