What is CAN Bus?
CAN (Controller Area Network) bus is a serial communication protocol designed for real-time applications in harsh environments
It utilizes a single twisted-pair cable, CAN high and CAN low, to connect multiple electronic control units (ECUs).
Developed for the automotive industry, it's now widely used in industrial automation, aerospace, and medical devices.
CAN Bus Message Structure

Setup RaspberryPi for CAN Bus
we need to get Hardware RS485 CAN Hat
Function PIN | Raspberry Pi (BCM) | Description |
3V3 | 3V3 | 3.3V Power Input |
GND | GND | Ground |
SCK | SCK | SPI Clock Input |
MOSI | MOSI | SPI Data Input |
MISO | MISO | SPI Data Output |
CS | CE0 | Data/Command Selection |
INT | 25 | Interrupt Output |
2. Jumper wires
Configuration :
Login to RaspberryPi using SSH using IP address
2. Use command Sudo Raspi-config
3. Make SPI interface Enable
4. Insert the module into the Raspberry Pi, modify the start-up script "config.txt".
sudo nano /boot/config.txt (OLD Versions)
sudo nano /boot/firmware/config.txt (New Versions)
Add the following content at the file:
dtparam=spi=on
dtoverlay=mcp2515-can0,oscillator=12000000,interrupt=25,spimaxfrequency=2000000
"oscillator=12000000" is the onboard oscillator with the size of 12M as shown below:
5. Reboot the RaspberryPi
After saving and exiting, restart the Raspberry Pi:
sudo reboot
After rebooting, run the command to see if the initialization was successful:
dmesg | grep -i '\(can\|spi\)'
6. Open CAN
sudo ip link set can0 up type can bitrate 50000
sudo ip link set can0 up type can bitrate 1000000
7. Install Can-Utils
sudo apt-get install can-utils
and run command
candump -tz can0
ARDUINO

ESP32
We need two ESP32 boards and two CAN transceivers for this experiment. Connect all the pins as shown below. Note that the RX and TX pins should be connected to RX and TX respectively of CAN
