Installing PiCAN for Raspberry 2 Model B


This blog shows the steps required to install the software on the Raspberry 2 Model for use with PiCAN board

All the previous kernel modules will not work with the current Raspbian (2015-02-16) for the Raspberry Pi 2. However the next version of the kernel will have the mcp251x driver compiled in. We can upgrade the firmware now with the new driver. These instruction will also work on the Raspberry B+.

Start by installing a brand new version of Raspbian (2015-02-16) kernel 3.18

Enable the SPI interface by running raspi-config.

cd /usr/bin 
sudo ./raspi-config

Select Advanced Options.

Select A6 SPI

Confirm you want the SPI interface enabled. Confirm you want the SPI kernel module to be loaded by default, then exit.

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 Pi:

sudo reboot

You can now bring the CAN interface up:

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

Download and copy the CAN test programs to the Pi.

To send a CAN message use :

 ./cansend can0 7DF#0201050000000000

This will send a CAN ID of 7DF. Data 02 01 05 – coolant temperature request.

Installing can-tools.

To write your own CAN-Bus program follow this blog.










Short URL:

Tags: , , ,

40 Responses to Installing PiCAN for Raspberry 2 Model B

  1. pavel on 10/03/2015 at 21:29

    I’m trying to install PICAN on RPi 2, but I don’t know how and where to install “CAN test” programs. I have this archiv downloaded unpacked on PC and uploaded through WinSCP to RPi /home/pi/can_test but I could not see how to continue with instalation. Sorry maybe for stupid questions, but I am on basic level with RPi.
    Thanks for help.

    • admin on 10/03/2015 at 21:32

      In the can_test directory are the test programs. Just change into that directory and run the test programs like this
      ./cansend can0 7DF#0201050000000000

      • pavel on 10/03/2015 at 21:39

        Yes that I tried, but without sudo systems return:
        -bash: ./cansend: Permission denied
        If I tried with sudo system return:
        sudo: ./cansend: command not found

        Any idea?
        I made all steps as are above.

        • admin on 10/03/2015 at 21:41

          Have you changed into the can_test directory? Do a “ls” and see if cansend is there or not.

          • pavel on 10/03/2015 at 21:45

            Yes I am in can_test folder and all filles I can see are:

            canbusload, candump, cangen, canlogserver, cansend,, can-calc-bit-timing, canfdtest, cangw, canplayer, cansniffer,

          • pavel on 10/03/2015 at 21:48

            I found the problem it is permision of each files now it seem to work I will connect with CAN network and see if everythink working and I will leave info here.

      • pavel on 10/03/2015 at 21:41

        Other question there is no installation procedure only copying of unpacked files to the destination folder?

        • admin on 10/03/2015 at 21:44


    • pavel on 10/03/2015 at 22:13

      OK now after changing permition everything working.
      Thank you for your good job

  2. Chad Gibbons on 12/03/2015 at 00:45

    This worked great, the first time. Thanks for the info! Sure a lot better than having to build the whole kernel from scratch like the “old” days…

  3. Bart on 16/03/2015 at 13:08

    The procedure works well for Wheezy (thank you for this, the kernel recompile procedure was quite an ordeal), do you know if this will work under Jessie as well?

    • admin on 16/03/2015 at 14:19

      Not tried Jessie.

  4. Yasir on 06/04/2015 at 05:16

    Followed exactly as is, but I’m seeing this error in dmesg when I send a message (and message is not sent according to CAN Bus analyzer):

    mcp251x spi0.0: unable to set initial baudrate!
    mcp251x spi0.0: can0: bit-timing not yet defined

    Anyone know of any solution to this? Running on RPi 2. Thanks

    • admin on 06/04/2015 at 10:24

      Check you have edited the /boot/config.txt file correctly.

  5. SteinarK on 12/04/2015 at 14:21

    I had the same issue on my Rpi2. Had to run the command:
    sudo /sbin/ip link set can0 up type can bitrate 500000

  6. SteinarK on 12/04/2015 at 14:27

    How does the ./cansend work?
    If I set baudrate to something different than 500000 in “sudo /sbin/ip link set can0 up type can bitrate 500000″, it seems to me like cansend transmit messages onto the canbus forever (have to stop it by “/sbin/ip link set can0 down”. With 500000 cansend transmits only once (which I expect is the way it should be).

    • SteinarK on 17/04/2015 at 18:38

      Regarding “How does the ./cansend work?”

      Found the source and downloaded it by:
      sudo git clone

      Then compiled and built it by:
      cd can_utils
      sudo make

      My system:
      Linux raspberrypi 3.18.11-v7+ #777 SMP PREEMPT Sat Apr 11 17:30:37 BST 2015 armv7l GNU/Linux

  7. boxinger on 14/04/2015 at 14:09

    When I try the sudo /sbin/ip link set can0 up type can bitrate 500000 the I get the Cannot find device “can0″ message.
    Please help.

  8. Dan E on 23/04/2015 at 19:00

    pi$ sudo /sbin/ip link set can0 up type can bitrate 500000
    Cannot find device “can0″

    Any idea how to do debug whats wrong?
    I have verified everything is good in /boot/config.txt

  9. Neil Emiro on 29/04/2015 at 01:01

    Installed everything on a Raspberry Pi 2, and it takes all commands, no errors. My problem is that nothing seems to work. Nothing in Wireshark, and no level changes on an oscilloscope. After attempting to send data with cansend several times, I will eventually get an error: write: No buffer space available I will have to reboot the Pi to clear it, and start again. I reboot, but it just repeats the cycle. LED1 is lit on the PiCAN, if that helps any. I am trying to use the PiCAN as a ‘master’ driving the CAN bus, sending data to a device, so I have no way of just watching traffic on an existing bus.

    Also, trying to talk on a low speed bus, 125k. I imagine this command is correct:
    sudo /sbin/ip link set can0 up type can bitrate 125000

    I have tried the recommended:
    sudo /sbin/ip link set can0 up type can bitrate 500000

    But I still get no results, according to the oscope. Anything you can suggest would be most helpful. Thanks!

    • admin on 29/04/2015 at 09:19

      What device are you connecting to? Make sure the baud rate matches. Also you may need to enable the terminator, just close JP3.

      • Neil Emiro on 30/04/2015 at 03:15

        Jumped JP3, and that did have an effect. I now get some traffic. What I now notice is that using ./cansend can0 20B#6100 sends data for several seconds, instead of just sending quickly, and then stopping. It’s as if it is either sending several times, or it is initiating bus activity, and sending very slowly. Nothing registers in Wireshark, despite being open and supposedly capturing can0. If you try to send again, it yields no additional response, as if no command had been sent, and the bus stays ‘silent’. After sending 3-4 more times, it gives the same write error, and then effectively locks up until I reboot.

        In short, the termination resistor at least shows it wants to work, but still have a bit more to work out. Any suggestions you can offer will be most welcome. Thanks!

        • admin on 30/04/2015 at 20:27

          Check you have configured Wireshark correctly. Check the baud rate matches the device you are connected to.
          Check CAN_L and CAN_H is not swapped.

  10. Mario on 11/05/2015 at 06:29

    is it possibile to use with CANopenNode or Canfestival?

  11. rad on 24/06/2015 at 13:44


    is there any info what GPIO pins doest it use? I want to use it with my RP2, but I also need to keep free as many GPIO pins as possible. So which ones does it need to be connected in order to behave correctly?

    Thanks a lot.

  12. boxinger on 10/07/2015 at 09:10


    Is it possible to connect two PiCAN boards to my raspberry?

    • admin on 10/07/2015 at 09:15

      Possible, you can stack one board on the top. You need to move the CS line on the second board to CE1. The driver would also need to be updated.

      • boxinger on 10/07/2015 at 14:04

        Could you explain how can I update the driver?

  13. gary on 10/07/2015 at 14:39

    Which side of the SJ1, SJ2, SJ3 solder points do I use for the DB-9 connector. The schematic seems to indicate left on SJ1 and SJ2 and right on SJ3. Also, I can’t find JP3 on the schematic. What is it used for?

  14. Bart on 26/07/2015 at 16:49

    after an rpi-update today (26 July 2015) to kernel 4.0.7, the PICAN board failing to work.
    Has anyone else been able to successfully use 4.0.7
    Also, one needs to drop the -overlay in the /boot/config.txt settings, so that it reads:
    according to


    • Bart on 26/07/2015 at 20:13

      did sudo rpi-update again, and firmware is now 4.0.9-v7+
      dmesg reports:
      [...] mcp251x spi0.0: can0: bit-timing not yet defined
      [...] mcp251x spi0.0: unable to set initial baudrate!
      [...] mcp251x spi0.0: can0: bit-timing not yet defined
      [...] mcp251x spi0.0: unable to set initial baudrate!

      /boot/config.txt is what it states above.
      I have tried with other PICAN’s and RPi’s, same issue.

      • Bart on 26/07/2015 at 21:46

        I might have found the issue:
        in raspi-config, overlocking, set to ‘Pi2′

        This appends 3 lines to config.txt

  15. rcan on 30/07/2015 at 18:33

    I got it working today with:
    $ uname -a
    Linux pi 4.0.9-v7+ #807 SMP PREEMPT Fri Jul 24 15:21:02 BST 2015 armv7l GNU/Linux

    /boot/config.txt is as the instructions indicate:

    I didn’t do any overclocking.

    It appears to work fine when the Pi has an ethernet network connection, but not over wifi. As soon as I bring up the CAN interface with:
    /sbin/ip link set can0 up type can bitrate 500000

    it takes down the wlan0 interface. I have no idea why that is, and am looking for suggestions.

  16. Ota on 16/08/2015 at 15:16

    Hi, does this “new” method work also on RPI B+, or is it just for RPI 2? I am trying to reproduce it on B+, but keep getting messages
    [ 854.333249] mcp251x spi0.0 can0: bit-timing not yet defined
    [ 854.333300] mcp251x spi0.0: unable to set initial baudrate!
    in dmesg.

    $ uname -a
    Linux rpi-pwm02 4.1.5+ #809 PREEMPT Thu Aug 13 00:30:15 BST 2015 armv6l GNU/Linux


    • Ota on 16/08/2015 at 15:59

      Now I can see the messages from my prevous message seems to be normal. But after following debugging, I found out that
      $ ip -d -s link show can0
      shows in the beginning:
      can state ERROR-ACTIVE
      but after sending a message or if there is some communication on the bus it changes to:
      can state ERROR-PASSIVE

      The complete can state is:
      $ ip -d -s link show can0
      3: can0@NONE: mtu 16 qdisc pfifo_fast state UP mode DEFAULT qlen 10
      can state ERROR-PASSIVE restart-ms 0
      bitrate 500000 sample-point 0.875
      tq 125 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1
      mcp251x: tseg1 3..16 tseg2 2..8 sjw 1..4 brp 1..64 brp-inc 1
      clock 8000000
      re-started bus-errors arbit-lost error-warn error-pass bus-off
      0 0 0 4 4 1
      RX: bytes packets errors dropped overrun mcast
      0 0 0 0 0 0
      TX: bytes packets errors dropped carrier collsns
      0 0 1 1 0 0

      Do You have any more hints, what else to check?

      I am feeling completely stuck….

      Thanks in advance!


      • Ohng on 21/08/2015 at 19:35

        I got the same problem here.

        Have you got it solved, Ota?

        • Ohng on 23/08/2015 at 22:43

          My problem has been fixed.

          I am now able to send and receive between PiCAN and Tiny-CAN.

          The problem was I connected the cable to ODBII instead of CAN_H and CAN_L and I set the wrong baudrate.

          Just for the update.

  17. Andy on 24/08/2015 at 16:29


    how is it possible to change the physical adress from the device “can0″? If I type “ifconfig”, the hardware adress is always “00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00″. How can ich change this?


  18. Marty OC on 09/09/2015 at 02:36

    I seem to be stuck in a *similar* area.


    Raspberry Pi 2 Model B Rev 1.1
    Linux raspberrypi 4.1.6-v7+ #810 SMP PREEMPT Tue Aug 18 15:32:12 BST 2015 armv7l GNU/Linux

    marine (raymarine) can net environment

    after executing:
    ip link set can0 up type can bitrate 500000

    and executing: ip -s link show can0
    3: can0@NONE: mtu 16 qdisc pfifo_fast state UNKNOWN mode DEFAULT qlen 10
    RX: bytes packets errors dropped overrun mcast
    0 0 0 0 0 0
    TX: bytes packets errors dropped carrier collsns
    0 0 0 0 0 0

    dmesg show:
    [ 125.586532] mcp251x spi0.0 can0: bit-timing not yet defined
    [ 125.586558] mcp251x spi0.0: unable to set initial baudrate!

    I tried different a bitrate, etc and anything else I can find (aside from going back to a specific firmware and build) but have never got it to work. I wish I had a way to minimally know the pican board is good.

    Another clue: when I try to bring the port up with: ‘ ip link set can0 up type can bitrate xxxxxxx
    ‘, it brings the seaTalk bus down until I either delete the device or reboot rpi. (The device becomes ‘busy’ and trying to put it in a ‘down’ state is futile).

    If you have any suggestions and or comments please forward on. Thanks!!