CAN communications with Raspberry Pi and CodeSys

  • egret

    egret - 2016-10-31

    Codesys Forum,

    I would like to use the Raspberry Pi with an SPI CAN module to establish CAN communications. However, I'm unclear on a few points:

    With "CODESYS Control for Raspberry Pi SL

    I'm considering the following CAN modules. Can anybody recommend one over another?
    SK Pang Electronics - PiCAN2
    MikroElektronika - CAN SPI click 3.3V with Pi 2 click SHIELD
    IndustrialBerry - CanBerryDual V2.1

    If CAN communications is the only requirement is the Beaglebone a better alternative?

    Regards, Ben

  • menno

    menno - 2016-11-09

    CODESYS supports SocketCAN communication. I managed to get CODESYS CAN communication working on a Raspberry Pi 3 with CanberryDual. However, for some reason it only works if one mcp2515-overlay is configured in /boot/config.txt, so only one CAN bus is working. Still figuring out, why that is the case and whether it is a CODESYS or SocketCAN problem. Any help on this appreciated.

  • bmunsil

    bmunsil - 2016-11-15

    I have the PiCanV2 from Skpang it took some browsing of the forums here, but there is a really good thread on it that will help you get it working. you can compile socketcan into you image and configure the codesys control to auto load on CAN1. I actually have an image that I would be more than happy to share if you send me your information. as a side note I am NOT a Linux or Codesys expert. I have just compiled the bits and pieces that the community has provided to make a working system.

    so far I have it running on a Raspberry PI B, and Raspberry PI 2 B. I don't have a Raspberry PI 3 yet to get it working but I have been told that there is little difference in the configurations.

    I do know however that the Device version doesn't work for me. I have to use an older device version in Codesys V3.

    I know this was a bunch of random info put into a not so nicely formatted post but I hope it somewhat helps.

  • CanBohr

    CanBohr - 2018-01-09

    I have a problem with PiCanV2 from Skpang
    Codesys gives me the error message "Bus not running"
    But the canbus is working on the raspi, I can see messages by using candump can0.
    Codesys Version is
    Can you tell me where you found the solution for your problem?

  • eschwellinger

    eschwellinger - 2018-01-11

    to have this script executable is mandatory:
    l viewtopic.php?f=21&t=8463#p20132 l

    BITRATE=expr $2 \\* 1000
    ifconfig $1 down
    echo ip link set $1 type can bitrate $BITRATE
    ip link set $1 type can bitrate $BITRATE
    ifconfig $1 up


  • jond

    jond - 2019-03-27

    I have similar problem with PiCanV2 from Skpang
    Canbus is working on the raspi, I can see messages by using candump can0.
    Have installed Codesys Version is
    Downloaded CANbus example from the store.
    Unfortunately I can not get the example working.

    Can you help me please to get this example running on Raspberry 3 controlled with Codesys?

    • molarcheveque

      molarcheveque - 2020-05-26


      I have the same problem... the CAN0 is working from the terminal, but not able to make it work in Codesys. I have the following error. No CAN Driver Found. and the bus is not running.... (see attached picture)

      what am I missing.
      thanks for your help...

      • Ingo

        Ingo - 2020-06-04

        I can imagine two common problems:

        1. The socket CAN device is not configured as it should be and CODESYS doesn't find it.
        2. The script is not in place, not found or doesn't have the proper rights.

        Maybe we start with the first one, and you send us the output of "System Info" in the Raspberry Pi deploy tool inside CODESYS (Tools -> Update Raspberry Pi -> System Info).

        And regarding issue 2:
        Did you change anything in the config file regarding that script? Just because it should already be prepared that you don't need to change anything manually.

  • DavidBo

    DavidBo - 2020-10-15

    I have no problem with PiCAN2 but a script has to be called in order to enable the CAN bus before CODESYS


    BITRATE=expr $2 \\* 1000
    ifconfig $1 down
    echo ip link set $1 type can bitrate $BITRATE
    ip link set $1 type can bitrate $BITRATE
    ifconfig $1 up


    Last edit: DavidBo 2020-10-15

Log in to post a comment.