How to setup a raspberry pi 3 with CAN Interface

How to setup a raspberry pi 3 with CAN Interface?

  • Raspberry pi 3 b+
  • PiCAN 2 Duo – CAN-Bus Board


  • balenaOS 2.31.5+rev5

My fist step to setup this projct:
Add the overlays by: to config.txt
4 lines to the end of config.txt file:

But no can driver is visable. What ist going wrong?

Hi @tomtom68 welcome to the forums!

Could you share the Dockerfile that you’re using to set up your container? I would check to make sure you’re using a stretch-based image (if you’re using Debian).

Additionally could you enable support access for your device and share the URL here, we can then take a look to see if we can figure out what’s happening. There are some ideas around debugging CAN interfaces in this thread.

The basis setup based on:

FROM resin/%%RESIN_MACHINE_NAME%%-python
COPY ./requirements.txt /requirements.txt
RUN pip install -r /requirements.txt
COPY . /usr/src/app
WORKDIR /usr/src/app
CMD [“python”, “”]


And i get the following error:
[Info] Starting build for helloworld, user xxx
[Info] Dashboard link:
[Info] Building on arm03
[Info] Pulling previous images for caching purposes…
[Success] Successfully pulled cache images
[main] Step 1/7 : FROM resin/raspberrypi3-64-python
[main] repository resin/raspberrypi3-64-python not found: does not exist or no pull access
[Error] Some services failed to build:
[Error] Service: main
[Error] Error: repository resin/raspberrypi3-64-python not found: does not exist or no pull access
[Error] Not deploying release.

The repository: resin/raspberry3-65-python is not found!

Hey @tomtom68,

the basis setup you used is out of date since we dropped support for old resin base images a while ago, the resin/raspberrypi3-64-python image is not found because that device was added after the support ended.

Please switch to the new balenalib base images by changing to FROM balenalib/%%BALENA_MACHINE_NAME%%-python. You can drop this line ENV INITSYSTEM on and add ENV UDEV on since udev is off by default.

With the new balenalib base image:

FROM balenalib/%%BALENA_MACHINE_NAME%%-python
COPY ./requirements.txt /requirements.txt
RUN pip install -r /requirements.txt
COPY . /usr/src/app
WORKDIR /usr/src/app
CMD [“python”, “”]

i get the following errors:

[main] Step 4/7 : RUN pip install -r /requirements.txt
[main] —> Running in 431f691ef15d
[main] DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won’t be maintained after that date. A future version of pip will drop support for Python 2.7.
[main] Collecting RPi.Gpio (from -r /requirements.txt (line 1))
[main] Downloading
[main] Collecting python-can (from -r /requirements.txt (line 2))
[main] Downloading (174kB)
[main] Collecting wrapt~=1.10 (from python-can->-r /requirements.txt (line 2))
[main] Downloading
[main] Collecting aenum (from python-can->-r /requirements.txt (line 2))
[main] Downloading
[main] Collecting typing (from python-can->-r /requirements.txt (line 2))
[main] Downloading
[main] Building wheels for collected packages: RPi.Gpio, python-can, wrapt
[main] Building wheel for RPi.Gpio ( started
[main] Building wheel for RPi.Gpio ( finished with status ‘error’
[main] ERROR: Complete output from command /usr/local/bin/python -u -c ‘import setuptools, tokenize;file=’"’"’/tmp/pip-install-6186Ci/RPi.Gpio/’"’"’;f=getattr(tokenize, ‘"’"‘open’"’"’, open)(file);’"’"’\r\n’"’"’, ‘"’"’\n’"’"’);f.close();exec(compile(code, file, ‘"’"‘exec’"’"’))’ bdist_wheel -d /tmp/pip-wheel-XNhnzK --python-tag cp27:
[main] ERROR: running bdist_wheel
[main] running build
[main] running build_py
[main] creating build
[main] creating build/lib.linux-aarch64-2.7
[main] creating build/lib.linux-aarch64-2.7/RPi
[main] copying RPi/ -> build/lib.linux-aarch64-2.7/RPi
[main] creating build/lib.linux-aarch64-2.7/RPi/GPIO
[main] copying RPi/GPIO/ -> build/lib.linux-aarch64-2.7/RPi/GPIO
[main] running build_ext
[main] building ‘RPi._GPIO’ extension
[main] creating build/temp.linux-aarch64-2.7
[main] creating build/temp.linux-aarch64-2.7/source
[main] gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/local/include/python2.7 -c source/py_gpio.c -o build/temp.linux-aarch64-2.7/source/py_gpio.o
[main] unable to execute ‘gcc’: No such file or directory
[main] error: command ‘gcc’ failed with exit status 1
[main] ----------------------------------------
[main] ERROR: Failed building wheel for RPi.Gpio

@tomtom68, we have some breaking changes in the balenalib base images (you can find more details in the blog post here So the default image now only contains essential packages for a project to run, not all the tools or common libraries.

Looks like you should install build-essential package here, please add RUN install_packages build-essential to your Dockerfile before RUN pip install... command.

The basic setting (raspi, balena gpio’s) works very well.

But the CAN interface driver is not detected.

I modified the config.txt and add these 3 lines to the end of file:


After reboot the spi controller (can0 and can1) is not detected.

Hey @tomtom68,

Could you share your Dockerfile on a gist so I can try building it on my end?

Did you make the configuration change on the dashboard or on the config.txt itself?
If so, you should make the changes on the dashboard. Go to the device page and on Device Configuration, add the custom variables there.

So RESIN_HOST_CONFIG_dtparam = on (it should be already ON)

And for the other configs, you need to add the RESIN_HOST_CONFIG_ or BALENA_HOST_CONFIG_ prefix.

Let me know how it goes!