1-800-859-6265   FAX: +1 (586) 731-2274

How to use SocketCAN on a Raspberry Pi 4 (Linux) using ValueCAN 4

August 13, 2020

Intrepid Control Systems introduced an Open Source API called Libicsneo. This can be used with python_ics to integrate Intrepid vehicle networking hardware to any Python application running Linux, Mac or Windows. Please refer to The easy way to program ValueCAN 4 in python using Raspberry Pi (Linux) if you would like to learn how to program your device using Intrepid API. 

In this tutorial you will learn how to set up the Intrepid SocketCAN kernel module on your Raspberry Pi 4 to work with any Intrepid tool such as ValueCAN 4 series. Please reference the documentation for a list of supported hardware. We will be using ValueCAN 4–2 that includes two channels of CAN or CAN FD. 

Hardware Setup

Connect ValueCAN 4–2 using DB-9F to OBD-II cable to neoOBD2 Simulator (optional) to receive or transmit CAN or CAN FD messages instead of a car.

Open Terminal 

Install dkms, the package for Dynamic Kernel Module Support Framework. We need the dkms package for Raspberry Pi because it doesn’t have a kernel header. On Ubuntu, this is accomplished by running: sudo apt install linux-headers-generic build-essential gcc git 

sudo apt-get install dkms

Clone Intrepid SocketCAN Kernel Module from www.github.com/intrepidcs
git clone https://github.com/intrepidcs/intrepid-socketcan-kernel-module.git

 

Go to the module directory by using:

cd intrepid-socketcan-kernel-module

Make the project to build the KO file by using the command make

make

The resulting file will be intrepid.ko. This module depends on can, can_dev, and can_raw. We have a script to help within the makefile, make reload. But If you prefer to run it yourself, you can run using the following command: 

sudo modprobe can

sudo modprobe can_raw

sudo modprobe can_dev

sudo insmod intrepid.ko

Use lsmod to confirm the module is loaded.

If you wish to have the module auto-load on boot, then please follow the instructions on our GitHub page at https://github.com/intrepidcs/intrepid-socketcan-kernel-moduleOnce you have the Intrepid Socket Kernel Module setup, then we will need to install icsscand. Intrepid Icsscand is a user-mode SocketCAN daemon for Intrepid devices. 

To keep our file system clean, we will move out of the Intrepid SocketCAN Kernel directory by using cd.. command.

To install the dependencies needed we will run 

sudo apt install git cmake gcc libusb-1.0-0-dev libpcap-dev build-essential

Once you have the dependencies installed, then clone icsscand repository recursively by running

git clone --recursive https://github.com/intrepidcs/icsscand.git

Switch into the cloned directory, cd icsscand and make a build directory and switch into it, mkdir build && cd build

Invoke CMake,

cmake .. -DCMAKE_BUILD_TYPE=Release 

Build the daemon, using the command make

Daemon should now be available as libicsneo-socketcan-daemon. Daemon allows you to run Intrepid devices in the background. To start the daemon program use

sudo ./libicsneo-socketcan-daemon

If you’re happy with the results and would like to run in the background, run sudo ./libicsneo-socketcan-daemon -d to run in daemon mode.

To view your CAN interfaces, use the command, sudo ip linkThey will be labeled can0, can1, and etc. They will have an alias listed which corresponds to the serial number of the device and network on that device. To enable the CAN interface to transmit and receive with sudo ip link set up can0, replacing can0 with whichever interface you’d like to enable

You can now use any SocketCAN application with this interface. A good package for testing is the can-utils package. You can get this with sudo apt install can-utils. A good testing tool which comes with this package is candump. Running candump can0 will print a line for every incoming frame.

So to recap: 

Install Intrepid SocketCAN Kernel Module 

Install and start SocketCAN daemon for Intrepid devices.

View and enable the correct CAN Interface

You can read intrepid-socketcan-kernel-module at https://github.com/intrepidcs/intrepid-socketcan-kernel-module and icsscand https://github.com/intrepidcs/icsscand

You May Also Like…

JapanKoreaChinaUSA