Raspberry Pi PICAN2 Functionality Test With Two PICAN2 HATs
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:
- Troubleshooting your PiCAN2 CAN Interface Board for Raspberry PI...
- PiCAN2 CAN Bus Board for Raspberry Pi - Functionality Test...
- PiCAN2 Duo CAN Bus Board for Raspberry Pi - Functionality Test...
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:
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.
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.
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
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.