Site Information

 Loading... Please wait...

Raspberry Pi PICAN2 Functionality Test With Two PICAN2 HATs

Posted by Wilfried Voss on

Raspberry Pi PICAN2 Test Setup

The following is yet another post on testing the PICAN2 - CAN Bus Interface for the Raspberry Pi, however, with a different approach. In this case, we utilize two identical PICAN2 boards and connect them per the CAN Bus (CAN_H to CAN_H, CAN_L to CAN_L) as shown in the image above.

In the past, we have documented different methods of testing the PICAN2, which did not require the presence of a second PICAN2:

Setting up the config.txt file

The first step is to edit the config.txt file as described in the PICAN User Manual. Please make sure, you use the following settings:

dtparam=spi=on
dtoverlay=mcp2515-can0,oscillator=16000000,interrupt=25
dtoverlay=spi-bcm2835-overlay

I have seen forum entries where users recommended different settings, but they were ultimately wrong.

After editing the file, close it and reboot the Raspberry Pi.

Initializing the CAN Bus Interface

Both PICAN2 boards need to be initialized for using the same CAN Bus baud rate:

sudo /sbin/ip link set can0 up type can bitrate 500000

Sending And Receiving CAN Bus Data Frames

In the following, I used the cansend and candump commands to exchange CAN Bus data frames between the two devices. Yet again, for detailed information on the setup and data transfer, refer to the PICAN User Manual.

Raspberry Pi PICAN2 Test - Screen Print Left Monitor

The above screen shot shows the content of the monitor to the left. As the first line shows, we transmitted a CAN message, and with the second line, we received data from the other node.

Raspberry Pi PICAN2 Test - Screen Print Right Monitor

This next screen shot shows the content of the monitor to the right. The CAN data exchange is, of course, in reversed order.


Raspberry Pi Cookbook: Software and Hardware Problems and Solutions

Raspberry Pi Cookbook: Software and Hardware Problems and Solutions

With millions of new users and several new models, the Raspberry Pi ecosystem continues to expand, along with a lot of new questions about the Pi’s capabilities. The second edition of this popular cookbook provides more than 240 hands-on recipes for running this tiny low-cost computer with Linux, programming it with Python, and hooking up sensors, motors, and other hardware—including Arduino and the Internet of Things.

Prolific hacker and author Simon Monk also teaches basic principles to help you use new technologies with Raspberry Pi as its ecosystem continues to develop. This cookbook is ideal for programmers and hobbyists familiar with the Pi through resources, including Getting Started with Raspberry Pi (O’Reilly). Python and other code examples from the book are available on GitHub.

More Information...