Use Carloop with SocketCAN and can-utils

SocketCAN is the Linux CAN networking stack and can-utils are a rich set of utilities to analyze CAN traffic. They are great all-purpose tools for car research and hacking.

You can now use your Carloop as a SocketCAN interface!

Carloop firmware

You’ll need special firmware on your Carloop to print received CAN messages to the USB serial port and allow transmitting CAN messages sent to the USB serial port.

Flash the SocketCAN serial firmware application to your Carloop. The easiest way is to go to https://build.particle.io, select Libraries on the left, search and select Carloop, then open the socketcan_serial.cpp example, click the Use this example button then flash to your device.

Linux computer setup

To use SocketCAN you’ll need a laptop running Linux. You could even do it from a Raspberry Pi.

Install the can-utils package: sudo apt install can-utils

SocketCAN has drivers to talk to many different devices. Since the Photon/Electron creates a serial port when you connect it to your laptop we’ll use the serial line CAN driver (SLCAN).

Connect your Carloop to your computer through the USB connector. A serial port named /dev/ttyACM0 should now be available. Check with ls /dev/ttyACM*

Link the serial port with a CAN network interface with sudo slcand -o -c -s6 /dev/ttyACM0 can0
(slcand comes from can-utils, s6 is the speed ttyACM0 is the serial port, can0 is the CAN network interface)

At this point you should see a CAN network when you do ip addr

3: can0: <NOARP> mtu 16 qdisc pfifo_fast state DOWN group default qlen 10
    link/can 

When you are ready to start analyzing traffic, you bring up the CAN network with sudo ip link can0 up

You can then use other canutils like candump, cansniffer and cansend.

Here’s for example what happens when I use candump can0 on my Ford Fiesta:

Here’s how I found out which message contains the accelerator pedal using cansniffer -cae can0 which progressively hides messages that don’t change. The pedal was in message 0xFD byte 3.

To stop the CAN interface, do sudo ip link can0 down.

slcand tends to keep running even after you stop the CAN interface. You can close it with sudo pkill slcand

References

For details about the SLCAN serial protocol used between SocketCAN and the Carloop firmware, see the source of the Carloop firmware on GitHub.

For more details about the can-utils programs, see the can-utils repository on GitHub. You can also search online for more info about a particular can-util program.

Some info about CAN on Linux and how to use different types of CAN interfaces.

The low-level documentation about SocketCAN (this was too detailed for my needs).

Here’s a lit of the CAN bus speed parameters that can be passed to slcand:

  •  -s0 10 kbit/s
    
  •  -s1 20 kbit/s
    
  •  -s2 50 kbit/s
    
  •  -s3 100 kbit/s
    
  •  -s4 125 kbit/s
    
  •  -s5 250 kbit/s
    
  •  -s6 500 kbit/s
    
  •  -s7 800 kbit/s
    
  •  -s8 1 Mbit/s
    

Next steps would be to implement a UDP server in the Particle Photon to send the data wirelessly. The socketcand would be a good place to start for the protocol.

Now get out there and do amazing things!

1 Like

hi,

your great app works very well on my wifes’s but not at all with mine which is CAN 29bit, 500kb . does anybody manage to use it with an extended CAN ?

@max,
Check out this thread which deals with extended CAN and a couple of related issues:
https://community.carloop.io/t/handling-29-bit-extended-format/239/8

If that does not work, let us know where you are encountering the roadblock, with details.

Hoping someone can give me some guidance. I was able to flash my Photon with the sketch no problem. Because I don’t have a linux machine I installed a Debian Virtual Machine on my laptop. I was able to connect to the USB port on the Photon, and install the carloop in my OBD port. I found the device at tty/ACM1. Everything else seemed to work correctly with the setup. When I ran ip addr command, it showed the can network and the status was DOWN.

Next I tried to bring it up. The command to bring it up seemed to execute however after checking ip addr again the Status shows UNKNOWN.

None of the utilities I ran seem to show any traffic on the network.

Not sure how to proceed to diagnose the issue.

@JerseyTechGuy,

I have not tried this myself, so I might be limited in how much I can help.
@dubb45 has done some of this; any ideas?

One thing I might suggest is to start with a simpler example, such as getting the VIN number and make sure the Carloop is working okay. That would let you know if Carloop is working and might give clues if your car is using extended 29-bit CAN messages. Maybe you have already done this.

Once we know the basics are working, then it would give us a baseline to help diagnose what is happening in this case.

I may certainly be diving in too deep to start. Yesterday I build an CanBus Simulator based on an article I found online. It works great with an Arduino and CanBus Shield. I was able to connect it to an ELM327 Bluetooth Dongle and use an OBD Scanner on my iPhone to read the simulated values. So this I know works. I then plugged the CarLoop into this same test unit and did not get anything back. I’ll try and start more simply.

ive ran into that same problem before! using my mac and a VM make sure to install the VM tools with it too. i was using parallels desktop and that did the trick for me.

1 Like

I might try Parallels instead of VMware. Thanks for the tip.

I’ve found out that there is a Windows and Mac program that allowed to communicate directly from Windows or Mac’s to SLCAN devices.
The program is CANtact (Can be found in Releases · linklayer/cantact-app · GitHub).
I’m still checking it out but it seems like a better solution than running VM every time.

@porgraming,

Thanks, I will have to check that out some time soon!