Installing Python-CAN for Raspberry Pi


This blog will show you how to install Python-CAN for the Raspberry Pi 2 for use with the PiCAN board.

Before the install use latest Raspbian Jessie, currently it is (2015-11-21) Kernel 4.1

Do an update first.

sudo apt-get update 
sudo apt-get upgrade 
sudo reboot 

Add the overlays by:

sudo nano /boot/config.txt

Add these 3 lines to the end of file:


Reboot and bring up the can0 interface:

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

Now download the Python-CAN files:

Unzip and install by

sudo python3 install

Now start 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)

To received messages and display on screen type:

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



Short URL:

Tags: , , ,

Comments are closed.