# CAN Bus on Raspbery Pi 3

**URL:** <https://forums.balena.io/t/can-bus-on-raspbery-pi-3/369544>\
**Category:** General\
**Created:** [December 19, 2023, 4:24am UTC](https://forums.balena.io/t/can-bus-on-raspbery-pi-3/369544 "2023-12-19T04:24:51Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ursabaer](https://avatars.discourse-cdn.com/v4/letter/u/a88e4f/32.png) [@ursabaer](https://forums.balena.io/u/ursabaer)\
**Post date:** [December 19, 2023, 4:24am UTC](https://forums.balena.io/t/can-bus-on-raspbery-pi-3/369544/1 "2023-12-19T04:24:51Z")

</div>

Hi there!  
Has any one set up a Raspberry Pi 3 (or others) with a CAN bus hat ? I’d like to expose the CAN bus hat to my node.js application deployed on my my RPi3 but not sure the right way to go about it. I’m wondering if I need to do a custom balena-os build to support this.  
thanks in advance  
-CWD

---

<div class="post-metadata">

**Author:** ![TJvV](https://avatars.discourse-cdn.com/v4/letter/t/858c86/32.png) [@TJvV](https://forums.balena.io/u/TJvV)\
**Post date:** [December 19, 2023, 8:32am UTC](https://forums.balena.io/t/can-bus-on-raspbery-pi-3/369544/2 "2023-12-19T08:32:51Z")

</div>

Hi,

Have you looked at [this thread](https://forums.balena.io/t/can-bus-interface-configuring-fails/4647/1)? Sounds like they did get something working.

Judging from my own device, the `mcp2515-can0` and `mcp2515-can1` devicetree overlays, and the `can-dev` driver are bundled with balena, so there shouldn’t be any need to build a custom OS.

---

<div class="post-metadata">

**Author:** ![ursabaer](https://avatars.discourse-cdn.com/v4/letter/u/a88e4f/32.png) [@ursabaer](https://forums.balena.io/u/ursabaer)\
**Post date:** [December 19, 2023, 12:12pm UTC](https://forums.balena.io/t/can-bus-on-raspbery-pi-3/369544/3 "2023-12-19T12:12:10Z")

</div>

Hi,  
Thanks for the quick response! I had not seen that thread. It does indeed seem that the can0 interface is present when I do a

```auto
root@cbad025:~# ip link show can0
4: can0: <NOARP40000> mtu 16 qdisc noop qlen 10
    link/[280]

```

I’m at the same spot as [this](https://forums.balena.io/t/can-bus-interface-configuring-fails/4647/46) where I’m unsure if I can or should be setting the speed. There’s no canutils present on the host so I can’t actually test if all is copacetic w/ the can connection there. But perhaps I don’t need to? In reading further down in the thread I should be able to test from inside the container itself? Is that correct?  
thanks very much!

---

<div class="post-metadata">

**Author:** ![mpous](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/mpous/32/4742_2.png) [@mpous](https://forums.balena.io/u/mpous)\
**Post date:** [December 19, 2023, 2:26pm UTC](https://forums.balena.io/t/can-bus-on-raspbery-pi-3/369544/4 "2023-12-19T14:26:18Z")

</div>

@ursabaer first of all welcome to the balena community!

could you please share more details of what base image do you share? what privileges are you giving to the container that wants to access to the can0?

what errors do you get?

---

<div class="post-metadata">

**Author:** ![ursabaer](https://avatars.discourse-cdn.com/v4/letter/u/a88e4f/32.png) [@ursabaer](https://forums.balena.io/u/ursabaer)\
**Post date:** [December 19, 2023, 3:24pm UTC](https://forums.balena.io/t/can-bus-on-raspbery-pi-3/369544/5 "2023-12-19T15:24:14Z")

</div>

thanks!  
So I think my problem was just a fundamental misunderstanding of how CAN is exposed into the container. I assumed I’d have to setup the CAN interface on the host and then share into the app’s container. I just built an app w/ ` balenalib/raspberrypi3-debian-node:latest` with the dockerfile installing the canutils suite and deployed to my pi3 w/ the CAN hat on it. ssh-ing into the container it looks like it’s on my CAN bus and working!  
long story, short, I had a bad assumption and it looks like Balena already took care of everything for me. Thanks for your help!

---

<div class="post-metadata">

**Author:** ![mpous](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/mpous/32/4742_2.png) [@mpous](https://forums.balena.io/u/mpous)\
**Post date:** [December 19, 2023, 3:40pm UTC](https://forums.balena.io/t/can-bus-on-raspbery-pi-3/369544/6 "2023-12-19T15:40:50Z")

</div>

Thanks for sharing the solution here @ursabaer

Let us know if we can help you more!

---

<div class="post-metadata">

**Author:** ![ursabaer](https://avatars.discourse-cdn.com/v4/letter/u/a88e4f/32.png) [@ursabaer](https://forums.balena.io/u/ursabaer)\
**Post date:** [December 19, 2023, 3:43pm UTC](https://forums.balena.io/t/can-bus-on-raspbery-pi-3/369544/7 "2023-12-19T15:43:28Z")

</div>

thanks @mpous I think the only thing I have left to do is make sure my container configures the interface. I’m thinking I should just be able to do

```auto
RUN ip link set can0 up type can bitrate 500000
RUN ip link set up can0

```

---

<div class="post-metadata">

**Author:** ![ursabaer](https://avatars.discourse-cdn.com/v4/letter/u/a88e4f/32.png) [@ursabaer](https://forums.balena.io/u/ursabaer)\
**Post date:** [March 17, 2025, 2:08pm UTC](https://forums.balena.io/t/can-bus-on-raspbery-pi-3/369544/10 "2025-03-17T14:08:19Z")

</div>

I recently got CAN communications working on a Pi4 with the following DT Overlay in Balena and the Waveshare FD CAN Hat:  
`"spi1-3cs","mcp251xfd,spi0-0,interrupt=25","mcp251xfd,spi1-0,interrupt=24"`  
DT params:  
`"audio=on","i2c_arm=on","spi=on","audio=on"`

`socketcan` seems to work pretty good.

For my next trick I’m going to try and implement CANOpen over this CAN network.

---

<div class="post-metadata">

**Author:** ![mpous](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/mpous/32/4742_2.png) [@mpous](https://forums.balena.io/u/mpous)\
**Post date:** [March 20, 2025, 1:12pm UTC](https://forums.balena.io/t/can-bus-on-raspbery-pi-3/369544/11 "2025-03-20T13:12:21Z")

</div>

Thanks for sharing @ursabaer

Keep us posted with CANOpen please 🙂
