Socketcan Setup Raspberry Pi - jakka351/FG-Falcon GitHub Wiki
Socketcan Setup Raspberry Pi/Linux
Using Raspberry Pi interface with a Controller Area Network using SPI or Serial Device
Hardware
- Raspberry Pi Board
- SD Card Flashed with a fresh copy of Raspbian
- Generic mcp2515 can/spi board (or)
- Raspberry Pi Specific can-bus hat
- an actual Controller Area Network (CAN)-bus to connect to
Socketcan via SPI
1. Install Can-Utils:
sudo apt install -y can-utils libsocketcan2 libsocketcan-dev
2. Append /boot/config.txt with:
# CAN-BUS Overlay
dtoverlay=mcp2515-can0,oscillator=16000000,interrupt=25
dtparam=spi=on
2. Append /etc/network/interfaces with:
auto can0
iface can0 inet manual
pre-up /sbin/ip link set can0 type can bitrate 125000 on restart-ms 100
up /sbin/ifconfig can0 up txqueuelen 65535
down /sbin/ifconfig can0 down
auto can1 # Optional
iface can1 inet manual
pre-up /sbin/ip link set can1 type can bitrate 500000 triple-sampling on restart-ms 100
up /sbin/ifconfig can1 up txqueuelen 500
down /sbin/ifconfig can1 down
4. Reboot:
sudo reboot
5a. Check Hardware & Network Status:
dmesg | grep mcp && ifconfig | grep can
5b. Successful Result:
[ 3.139428] mcp251x spi0.1 can0: MCP2515 successfully initialized.
[ 3.150549] mcp251x spi0.0 can1: MCP2515 successfully initialized.
can0: flags=193<UP,RUNNING,NOARP> mtu 16
can1: flags=193<UP,RUNNING,NOARP> mtu 16
Socketan via Serial USB Device
1. Install Can-Utils:
sudo apt install -y can-utils libsocketcan2 libsocketcan-dev
2. Append /etc/network/interfaces with:
auto slcan0
iface can0 inet manual
pre-up /bin/slcand -o -s 500000 /dev/ttyACM0 && sbin/ip link set up slcan0
up /sbin/ifconfig slcan0 up
down /sbin/ifconfig slcan0 down
/dev
and interchange names
Note: to use a different device, like bluetooth or UART, just match the device from 3. Reboot & Connect USB or Serial Device :
sudo reboot
4a. Check Hardware & Network Status:
ifconfig | grep can
4b. Successful Result:
slcan0: flags=193<UP,RUNNING,NOARP> mtu 16
OBDII/ELM327
TBC
Wiring Diagram
g