29 Responses

  1. […] on how to connect Raspberry Pi to CAN Bus. http://youness.net/raspberry-pi/raspberry-pi-can-bus. […]

  2. Michael J. Kidd at | | Reply

    Great write up.

    While I’m sure many appreciate the details of the circuits involved, I’d bet others would appreciate knowing a Pi hat exists for this purpose.

    SKPang had the PiCAN2 board which I’ve used extensively for the past 3 years in various projects. He has single and dual bus board as well as a variety which includes a 12v to 5v SMPS that works great for vehicle projects.

    Note: I’m not affiliated with SKPang other that being a customer.

  3. Michael J. Kidd at | | Reply

    Youness, thanks! That’s what I get for not browsing your blog more… 😉

  4. Yahya EL Gaoual at | | Reply

    Thank you so much, such a great blog

  5. ERAT #36 A talking shield – ZL2KEJ at |

    […] How to Connect Raspberry Pi to CAN Bus […]

  6. Matheus Penido at | | Reply

    Thanks for that great tutorial! I did build the circuit and when plug it over a CAN BUS network based on two Arduinos and MCP2515/TJA1050 raspberry pi read data flow appropriately. But I have one question: Why loopback mode didnt works for me? There are some configurations or modifications on to circuit to get it working? Maybe someone can help me! Thanks…

  7. Martin at | | Reply

    Thanx for the great HowTo.

    Just a remark for a tiny mistake:
    The drawing in chapter 1.1.5 has a bug. The Node B must be twisted. The CAN Transceiver should be connected to the bus and being on the left side, the CAN controller should be on the right side.

  8. Donald Fast at | | Reply


    Should this same process work for the microchip CAN bus analyzer (USB) ?? I followed these steps and after “ip link set can0….” i get
    cannot find device “can0”

    Product details: https://www.microchip.com/Developmenttools/ProductDetails/APGDT002

    I have this device and it works when running under windows. I am trying to monitor some canbus industrial equipment (not a car, data not encrypted).

    Thanks for any help.

  9. Donald Fast at | | Reply

    Built and working.

    Small correction: the schematic in 1.4 is wrong (but the images are correct) Raspberry pin 20 is actually pin23 (Sclk)
    ( Pin 20 is ground. )

  10. Sneh at | | Reply

    I’m having some issues after following this guide.

    can0 interface shows as state UNKNOWN on both pi’s after booting.

    can0: mtu 16 qdisc pfifo_fast state UNKNOWN group default qlen 10 link/can.

    If I set both to down and bring them back up, one usually always comes UP, sometimes both come UP. At the moment, neither are coming up, just staying as UNKNOWN.

    dmesg | grep -i can and dmesg | grep -i spi on both pi’s show the following:

    mcp251x spi0.0 can0: MCP2515 successfully initialized.

    cansend and candump show nothing whatsoever.

    Wireshark shows the following on the pi I am sending from:

    1 0.000000000 CAN 32 STD: 0x00000111 ff
    2 0.000296441 CAN 32 ERR: 0x00000004 00 20 00 00 00 00 00 00
    3 0.001137634 CAN 32 ERR: 0x00000040 00 00 00 00 00 00 00 00

    If I do the same on the other pi, I get this:

    1 0.000000000 CAN 32 STD: 0x00000111 ff
    2 0.001802927 CAN 32 ERR: 0x00000004 00 10 00 00 00 00 00 00
    3 0.002334128 CAN 32 ERR: 0x00000004 00 20 00 00 00 00 00 00
    4 0.004644923 CAN 32 ERR: 0x00000040 00 00 00 00 00 00 00 00

    After trying wireshark, checking dmesg again, I end up with bus-off error:

    mcp251x spi0.0 can0: bus-off

    Any pointers on what to check next??

  11. sneh at | | Reply

    It looks like my issue was a bad connection somewhere.

    I bought some better quality breadboards with better gripping sockets, as I thought the first pair I was using let some of the leads flop around a bit too much for my liking.

    I rebuilt the pair of modules on the new breadboards and it all worked first go.

    Just goes to show, when something doesn’t work, start with the basics first.

    Thanks for the write up.

  12. ben at | | Reply

    Is there a way to read the MCP2515 registers? Not sure how much low level access linux’s socket interface provides! I’m interested in seeing what the values are, especially the timing configuration bits.

  13. Andy Ahn at | | Reply

    This has been great help.
    At first I got some errors but turned out the wiring problems.
    Thank you so much.

  14. Augusto Hernández at | | Reply

    Hey, nice job! But why 130 Ohms? Can BUS standards recommend resistance at ends of 120 Ohms…

    And the clock, datasheet recommends two capacitors of 22 pF for CERAMIC RESONATORS (Not for CRYSTAL OSCILATORS). Anyway they are insignificant details, your work is very well documented.


  15. Augusto Hernández at | | Reply

    Hi again!

    Do you have any idea to implement CAN BUS FD (MCP2517FD, MCP2558)?

    Thank you very much in advance!

  16. Hari krishna munagala at | | Reply

    Thanks alot.
    I connected mcp2515 to raspberry pi3,but dont know what libraries i need to include in program.can you please send any demo program to blink led or control fan.Please send asap…..

  17. Lordloki at | | Reply

    I’m looking to attach a pican2, and then create a service / constantly running script that read from it and writes output to the rpi as specific keyboard strokes that can be picked up by the rpi. Anyone have any direction they can point me to?

Please comment with your real name using good manners.

Leave a Reply