Additional Information

Site Information

 Loading... Please wait...

Blog

Installing python-can on the Raspberry Pi

Posted by Wilfried Voss on

This post demonstrates the steps required to install python-can on the Raspberry Pi for use with PiCAN2, PiCAN3, PiCAN-M CAN Bus HATs.

First make sure the driver is installed. See:

PiCAN2, PiCAN3, and PiCAN-M Driver Installation for Raspberry Pi...

Now install python-can:

pip3 install python-can

Check there is no error.

You can now initialize the CAN interface:

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

Check there is no error message returned. Now we can try the interactive python shell. Start typing at the prompt:

python3

To sent a message out type the following lines:

import can
bus = can.interface.Bus(channel='can0', bustype='socketcan_native')
msg = can.Message(arbitration_id=0x7de,data=[0, 25, 0, 1, 3, 1, 4, 1])
bus.send(msg)

Installing python-can on the Raspberry Pi

Check CAN frames on the bus.

To received messages and display on screen type:

notifier = can.Notifier(bus, [can.Printer()])

Installing python-can for Raspberry Pi

For more Python sample code, see:

https://github.com/skpang/PiCAN-Python-examples...

PiCAN2, PiCAN3, and PiCAN-M Driver Installation for Raspberry Pi

This post provides you a brief overview on the steps required to install the software driver on the Raspberry Pi for use with the PiCAN2, PiCAN3, and PiCAN-M CAN Bus HATs, including the dual-port and SMPS versions. Please refer also to the board's user manual. Start by creating a new SD card image with the Raspberry Pi [...]

Read More »


PiCAN FD Functionality Test - CAN Bus FD Duo Board with Real Time Clock for Raspberry Pi

CAN FD (CAN with Flexible Data-Rate) is an updated version of the CAN 2.0B protocol. It takes into account the requirement of the automotive industry to make Classical CAN faster. To achieve that, two principles have been introduced: Faster transfer of the data frame – the Arbitration Field (ID and Acknowledgement) remain unchanged so that the arbitration [...]

Read More »