CAN Bus on Raspbery Pi 3

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

1 Like


Have you looked at this thread? 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.

1 Like

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

root@cbad025:~# ip link show can0
4: can0: <NOARP40000> mtu 16 qdisc noop qlen 10

I’m at the same spot as this 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!

@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?

1 Like

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!


Thanks for sharing the solution here @ursabaer

Let us know if we can help you more!

1 Like

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

RUN ip link set can0 up type can bitrate 500000
RUN ip link set up can0
1 Like