This tutorial shows you how to connect Raspberry Pi to CAN bus. and PCB gerber files are included.

Hardware Components

PartValueTypePackages
R1,R210kResistor0805/PTH
R3120RResistor0805/PTH
C1,C222pFCapacitor0805/PTH
Y116MHzCrystal OscHC49US
U2MCP2515ICSO-18/DIP
U3MCP2551ICSO-8/DIP
J1,J2TerminalConnector5MM

Use 0805 and SO Packages for PCB and PTH and DIP for DIY Perforated boards

Wiring Diagram

Raspberry Pi Configuration

Update and Upgrade Raspberry Pi

sudo apt-get update
sudo apt-get upgrade

once that is done proceed to edit the /boot/config.txt in the terminal enter the following command

sudo nano /boot/config.txt

Uncomment the following line

dtparam=spi=on

Add the following lines

dtoverlay=mcp2515-can0,oscillator=16000000,interrupt=25
dtoverlay=spi0-hw-cs

After editing save by pressing Ctrl+X followed by Enter. In the same terminal enter the following commands to install CAN bus utilities.

sudo apt-get install can-utils

After the above command executes successfully we have to add the below line to startup file /etc/rc.local before exit 0. This line will initialize the CAN bus interface with the given speed. In our case speed is 500Kb/s so it is 500000 bits per second

sudo ip link set can0 up type can bitrate 500000

reboot your raspberry pi using the following command

sudo reboot

once the raspberry pi is rebooted run the following command in the terminal to check if the CAN bus is initialized successfully.

dmesg | grep spi0

once the above command is executed you should be able to see the following response

this indicates the successful initialization of the CAN bus in Raspberry Pi. otherwise please check your wiring .

PCB

  • You can Download the PCB Gerber Here

Thanks for reading 🙂

If you like our content, please consider buying us a coffee.
Thank you for your support!