Skip to content

Setup & Installation

Getting the HAT running involves plugging it in, enabling the right kernel overlays, and installing a handful of packages. The whole process takes about ten minutes.

  1. Power off the Pi completely. Disconnect the power supply.

  2. Align the HAT with the Pi’s 40-pin GPIO header. The board should overhang the Pi with the screw terminals facing outward, away from the USB/Ethernet ports.

  3. Press the HAT firmly onto the header pins. All 40 pins should seat fully.

  4. Reconnect power and boot the Pi.

The MCP2515 CAN controller connects to the Pi over SPI. You need to enable SPI and load the device tree overlay that tells the kernel how the chip is wired.

On Raspberry Pi OS Bookworm and Ubuntu 23.10+, the boot configuration lives at /boot/firmware/config.txt.

Terminal window
sudo nano /boot/firmware/config.txt

Add the following lines at the end of the file:

dtparam=spi=on
dtoverlay=mcp2515-can0,oscillator=12000000,interrupt=25,spimaxfrequency=2000000

Reboot after saving:

Terminal window
sudo reboot

The RS-485 transceiver uses the Pi’s hardware UART. You need to enable the serial port hardware while disabling the kernel’s login shell on that port (the two are configured separately).

  1. Open raspi-config:

    Terminal window
    sudo raspi-config
  2. Navigate to Interface Options then Serial Port.

    raspi-config main menu with Interfacing Options highlighted

    raspi-config Interfacing Options with Serial highlighted

  3. When asked “Would you like a login shell to be accessible over serial?”, select No.

    raspi-config dialog asking about login shell over serial - select No

  4. When asked “Would you like the serial port hardware to be enabled?”, select Yes.

    raspi-config dialog asking to enable serial hardware - select Yes

  5. Finish and reboot.

After rebooting, verify the serial device is present:

Terminal window
ls -l /dev/serial*

You should see a symlink like /dev/serial0 -> ttyS0 or /dev/serial0 -> ttyAMA0.

Raspberry Pi OS Bookworm ships with lgpio and has dropped support for the older RPi.GPIO and wiringPi libraries. For most users, the Python dependencies are sufficient:

Terminal window
sudo apt-get update
sudo apt-get install -y python3-serial python3-can python3-rpi-lgpio

The demo scripts from Waveshare run directly with these packages.

After rebooting with the SPI overlay enabled, check that the kernel recognized the MCP2515:

Terminal window
dmesg | grep -i '\(can\|spi\)'

You should see lines indicating the MCP2515 was probed successfully, something like:

[ 5.sp1234] mcp251x spi0.0 can0: MCP2515 successfully initialized.

Terminal showing successful MCP2515 initialization via dmesg

If you see errors about failed SPI communication, double-check that the HAT is seated properly and that the oscillator frequency in your overlay matches your board’s crystal.

Terminal showing failed MCP2515 initialization - wrong wiring

You can also confirm the can0 network interface exists:

Terminal window
ip link show can0

Waveshare provides example code for both C (wiringPi) and Python. Download and extract:

Terminal window
sudo apt-get install -y unzip
wget https://files.waveshare.com/upload/4/4e/RS485_CAN_HAT_Code.zip
unzip RS485_CAN_HAT_Code.zip
sudo chmod 777 -R RS485_CAN_HAT_Code/
cd RS485_CAN_HAT_Code/

With the HAT physically installed, kernel overlays loaded, and dependencies in place, you are ready to start sending data. The CAN Bus Usage guide covers bringing up the can0 interface and exchanging frames. The RS-485 Usage guide walks through serial communication with the SP3485 transceiver.