I'm trying out CAN communication with the Arduino MKR CAN Shield.
I have a CAN bus test setup in the lab, with two DIY CAN drivers.
If all is OK, I should be able to write firmware and plug the Arduino CAN shield onto that BUS.
It can then snoop the data - and in a second step, send packets.
Introducing Arduino's MKR CAN Shield
The Arduino MKR series is rather interesting. A number of small-sized controller boards and a set of useful shields that match that size.
The CAN shield that I review here uses a popular CAN controller, the , and as CAN driver the .
image source (note: the actual screw terminals on the board I have are different): arduino.cc
- bus termination resistors that can be switched in or out.
- an on-board buck converter that allows you to power the Shield and an Arduino MKR 1xxx controller from external 7 to 24 V dc.
- Allows for interrupt driven message receive and hardware filtering for relevant data.
- A choice of supporting libraries and example sketches.
Wiring the CAN Shield in a CAN Bus
The CAN bus is an easy bus to add devices to. In my case,
I have an existing 3V3 CAN bus existing of
- two CAN breakout boards using a TI CAN driver and a Hercules automotive microcontroller for the logic.
They are currently programmed to send random data upon a button push and listen to specific packets.
- a .
Versatile, can listen, send, show protocol errors and log.
My two breakout boards are set up as termination points of the bus. They have termination resistors to properly close the bus at the two sides.
The analyser is plugged somewhere in between these two. The analyser's termination resistors are disabled, because it's not at the end of the bus.
Similarly, when wiring in the CAN shield somewhere on the bus, the switch that configures the on-board resistors has to be switched off.
So, the 4 things to do when adding the MKR CAN Shield to your bus are:
- connect HI to Bus HI
- connect LO to Bus LO
- connect GND to Bus GND
- set the switch to the right.
First Test: Snoop CAN messages
We can get started straight away. That's the magic of the Arduino world. There's always an example that gets you running.
In the case of shields with a Microchip MCP2515, there are a few options. Several good libraries have been published.
I made a choise based on the example I need more than on what library I prefer. I went for Sandeep Misty's CAN lib. Its CANReceiver example has all I need.
You install the lib by searching for MCP2515 in the Arduino library manager.
Once installed, open the CANReciever example.
All traffic on the bus will apear in the serial monitor.
What have you achieved?
- Added the Arduino MKR CAN shield as a node to a CAN bus
- Have a working device that can see what's happening on the CAN bus. Pushing data on the bus is just a little step away.
I think that's exciting.