An out-of-box Pi doesn't have CAN support.
This Project14 mini-project shows how you can give it a CAN bus with an Arduino CAN ShieldArduino CAN Shield.
The end result is a Pi with a physical CAN driver and the Linux CAN-utils software installed and ready to use.
Craig Peacock wrote the instructions to integrate several CAN breakout boards with the Pi.
I'm adding the Arduino MKR CAN Shield to that.
In the spirit of Project14, it's a very simple project. If you happen to own a CAN shield, you can play along.
Connections
All signals and voltages are available on the Pi's 40-pin connector.
The table below cross-references all required signals, the location on the Pi header and the Shield pin.
I used the same Pi pins as Craig.
click to enlarge
Warning: https://forum.arduino.cc/t/wiring-a-mkr-canbus-shield-to-an-arduino-uno/670010
Also beware that the MKR Canbus Shield has an error on labeling the Can H and Can L on the BOTTOM of the board.
They are reversed. They are correct on the top of the board (in micro letters).
If the Shield is an end node (first or last unit connected to your CAN bus), set the terminate switch on the shield towards the resistor symbol.
Linux CAN-utils Tools
I literally followed the steps of Craig's post. Do the same.
Follow the Driver Installation and CAN-util sections .
(not needed, because the overlay does it automatically: But first enable SPI interface with raspi-config).
I used a fresh Debian Buster Lite.
First enabled the driver for the MicroChip CAN controller by enabling an overlay.
Attention. The Arduino Shield has a 16 MHz crystal, so the oscillator attribute in the overlay string should be set to 16000000:
dtoverlay=mcp2515-can0,oscillator=16000000,interrupt=25
I tested if that was successful. dmesg reports a successful load:
Then I installed the CAN-utils package (check Craig's post for instructions).
I'm using the cansend and candump utilities of that package.
action video: hardware setup (with audio)
Testing It
I used a MicroChip CAN Bus analyser (see links at the end of this project).
Ground, CAN Hi and CAN Lo of analyser and Shield are connected to each other (attention: wrongly labeled on the underside of the Shield).
Can Hi and CAN Lo wires should be twisted.
I then used both devices to exchange data and show the results. In both directions
Success!
action video: it works (no audio)
Related Blog:
Arduino MKR CAN Shield Review - part 1: Log BUS Traffic
Arduino MKR CAN Shield Review - part 2: Interrupt and Filter
AVNET SmartEdge IIOT Gateway: Use the Isolated CAN
CAN programming in C on Linux: Filter and Mask
CAN Analyser Road Test
Microchip CAN Analyzer Road Test - part 1: First trials
Microchip CAN Analyzer Road Test - part 2: Inject CAN Messages
Microchip CAN Analyzer Road Test - part 3: Analyzer as Test Tool
Microchip CAN Analyzer Road Test - part 4: Analyze the Physical layer of CAN Bus
Microchip CAN Bus Analyser Tool - Review
Poor man's CAN:
TI Hercules LaunchPad - test the CAN with a poor man's CAN driver
Probing your Hercules LaunchPad CAN bus Part 1
Probing your Hercules LaunchPad CAN bus Part 2
Probing your Hercules LaunchPad CAN bus Part 3
Make my own CAN Driver:
CAN communication with Hercules Safety Microcontroller - part 1: tryout
CAN communication with Hercules Safety Microcontroller - part 2: Communication between 2 Devices
CAN communication with Hercules Safety Microcontroller - part 3a: Design a Bus Driver PCB
CAN communication with Hercules Safety Microcontroller - part 3c: Design a Bus Driver PCB - Layout
CAN communication with Hercules Safety Microcontroller - part 3d: Design a Bus Driver PCB - Test