top of page

Listening In on the 420R's CAN Bus with a CANPico

11 minutes ago
10 min read

Alongside the oil temperature gauge, I've been building an ECU dashboard come data logger (dashboard) for the Caterham using a 7 inch Waveshare touch display. The project is designed to read and understand the engine data the ECU sends out on the car's CAN bus. Unfortunately the first time I plugged a capable development build into the 420, the device saw nothing at all.


This post is about an additional small tool I built to support fault finding of that issue. The additional tool, a CAN bus recorder made from a CANPico, a Raspberry Pi Pico on a CAN board, supported by a laptop. I'll cover why I built it, the hardware, how it works, and what it recorded from my own car.

Hope you enjoy!


Why I built the device

The newly developed dashboard listens to the ECU's CAN messages, a stream of frames that the 420R's MBE ECU sends out several times a second containing parameters such as the engine speed, temperatures, throttle and battery voltage. I'd connected the dashboard through an OBD-II Y splitter, with MBE's Easimap on the splitter's other socket. Easimap received the ECU data happily, it was infact Easimap that generated the requests for the data and also sent acknowledgments . Sadly the dashboard saw nothing, no frames, and no errors either. The dashboard should have been able to essentially snoop the CAN frames from the bus.


In response I went through the obvious checks. The ignition was on. The dashboard had been built with a shared ground with the car. CAN High (CAN-H) and CAN Low (CAN-L) weren't swapped, and the termination was right. Still nothing.


The difficulty with a CAN bus is that a single device that hears nothing can't tell you why. The bus might be silent, the wiring might be wrong, or the receiver might be faulty, and the failure mode all looks the same. You need a second device, independent of the first, to listen alongside it. The usual

tool is a USB-CAN adapter on a laptop, which I didn't have to hand. What I did have was a CANPico.


In response, I built canpico-capture. A tool that records everything on the can bus to a file (pcap) so that another tool such as Wireshark and my other ECU decoding scripts read.


First, a test rig

On the bench, I wired the CANPico straight to the dashboard and had it transmit test frames. The dashboard found the bus speed on its own, 500 kbit/s, and received every frame, so the dashboard receiver worked. Then the CANPico replayed recordings of another 420R's bus, which Purplemeanie published alongside his ECU Diagnostics series, including an engine start. The dashboard followed it, the revs climbed to about 2,500, the coolant warmed, and the battery voltage dipped as the engine cranked. Along the way it found a bug in the dashboard's firmware, a setting change that didn't apply while it was listening, which is now fixed.


So the dashboard was fine, and the fault had to be somewhere between the car and the dashboard.


The next question was whether the CANPico could record the car's bus itself. That would give me the following;


  1. An independent view of the bus;

    1. what's really on it, recorded by something other than the dashboard.

  2. My own car's traffic;

    1. the dashboard's decoding came from another 420R's recordings, and I wanted to check my car against them. My 420R has had a new ECU in 2024, had an update in ECU impacted the approach used in the dashboard codebase.

  3. A record of what the dashboard sends;

    1. later, it will ask the ECU for values Easimap-style, such as lambda, and I want an independent record of every request it puts on the bus.


The CANPico

The CANPico is made by Canis Labs. It's a carrier board for a Raspberry Pi Pico, the small RP2040 microcontroller board, and it adds the following components;


  • A CAN controller

    • Microchip MCP2517FD or MCP2518FD, which handles the CAN protocol and timestamps every frame with its own microsecond clock.

  • A CAN transceiver

    • a Microchip MCP2562FD, which turns the controller's logic signals into the two-wire CAN-H and CAN-L signals on the bus.

  • A terminal block for CAN-H, CAN-L and ground.

  • Jumper JP1

    • which connects the board's own 120 Ω terminating resistor across the bus.


CANPico uses Canis Labs' build of MicroPython, which includes a CAN library, so it can be programmed in Python over a USB cable. It's an older board, and at least one supplier now lists it as discontinued, so check before ordering one. If you can get one, it is worth it!


Building the lead


How the CANPico and Easimap share the car's OBD-II port
How the CANPico and Easimap share the car's OBD-II port

The lead is three wires from the CANPico's terminal block to a male OBD-II plug:

CANPico

OBD-II plug

CAN-H

pin 6

CAN-L

pin 14

GND

pin 5 (or 4)

Pin 16, the car's +12 V, is left unconnected, because the CANPico takes its power from the laptop's USB. The plug goes into one socket of the Y splitter, and Easimap's MBE interface goes into the other.


Termination

A CAN bus needs exactly two 120 Ω terminating resistors, one at each end, which together read about 60 Ω across CAN-H and CAN-L. With JP1 fitted, the CANPico read 120 Ω across its CAN-H and CAN-L terminals, which is its own terminator. A car's bus already has its terminators, so I removed JP1, and the CANPico then read open circuit. If you're not sure about a bus, measure across pins 6 and 14 at the port with the ignition off: about 60 Ω means both terminators are already there.


Listening only, and acknowledgements

The tool canpico-capture was built to run on the CANPico and record in a listen-only mode, i.e. it never puts anything on the bus. On a CAN bus, every frame has to be acknowledged by at least one other device, a single bit that the receivers sets as the frame passes. A listen-only device never sets such a bit. If nothing else on the bus acknowledges, the ECU assumes its frame was lost and will resend the frame over and over.

In the car, Easimap's MBE interface acknowledges the ECU's frames, so the CANPico can listen quietly alongside. For the bench, the tool has a mode that acknowledges, and a bench-only mode that transmits a test frame every 10 ms, which it warns about every time.


The mistake: a mirrored plug

The first time I plugged the CANPico into the car and ran canpico-capture , it recorded nothing, 0 frames and 0 errors, while Easimap worked through the other socket. Swapping the two sockets over made no difference, as Easimap worked in both.


In the end, the root cause was the plug. A car's OBD-II port is a female socket, and the plug that goes into it is male. The face of a male plug is the mirror image of the socket. I'd wired the plug from a picture of the car's socket, so the CAN wires landed on pins 3 and 11, which carry nothing on the 420R. The ground still worked, because pins 4 and 5 sit in the middle and simply swap over. That gives exactly what I saw, a bus that looks completely silent, with nothing physically broken.


The car's socket and a male plug, face on, with CAN-H, CAN-L, ground and +12 V marked
The car's socket and a male plug, face on, with CAN-H, CAN-L, ground and +12 V marked

To get it correct on a male plug;

  • Looking at the pin tips;

    • with the wider row at the top, CAN-H (pin 6) is in the top row, 3rd from the left, and CAN-L (pin 14) is directly below it. Pin 16 (+12 V) is bottom left.

  • From the back of the plug;

    • where the wires are soldered, it looks like the car's socket, so CAN-H is 3rd from the right.

  • Check with a meter against the numbers moulded on the plug before it goes near the car.

  • Identify wires by pin number, never colour.

    • Wire colours in OBD leads and splitters aren't standard, and they vary from one maker to another.


The dashboard's lead most likely had the same mistake. Its wires had been picked off the splitter's cut-off branch in the same way, using the same picture, which would explain the original "no data" exactly. Once I'd rewired both by pin number, the CANPico recorded the bus, and that evening the I retested the dashboard also showed live values from the car. Fantastic!


How canpico-capture works


The two halves of the tool, and what passes between them
The two halves of the tool, and what passes between them

The tool comes in two halves.


On the CANPico, a short MicroPython program, the recorder, receives every frame, stamps it with the controller's microsecond clock, and sends it to the laptop as one line of text over the USB cable. Once a second it also sends a status line, with the frame count and the controller's error counters. When the recording stops, it takes the controller off the bus.


On the laptop, a Python script uploads the recorder to the CANPico every time it starts, through MicroPython's "raw REPL". Nothing is saved to the board's flash, so the CANPico is left exactly as it was. The script then reads the lines and:


  • writes a pcap file

    • the standard capture format, in the same form as a Linux CAN capture, which Wireshark opens directly;

  • optionally writes a text log in the candump format, one frame per line;

  • shows progress once a second;

    • the frames so far, the frames a second, any errors, and the busiest IDs;

  • prints a count for each ID when it stops; and

  • a reminder that a recording of a car is private.


The timestamps come from the CANPico's controller rather than the laptop, so USB delays don't affect the timing. The controller's clock is a 32-bit count of microseconds, which wraps round every 71.6 minutes, and the script unwraps it so a long recording stays in order.


Execution

On the laptop, it's two commands: one to set up, once, and one to record.

make venv                      # once: a local Python with pyserial
./capture -o test.pcap --log   # listen-only, 500 kbit/s, until Ctrl-C
  • --seconds 60 stops on its own after a minute.

  • --bitrate sets another bus speed, for other cars.

  • Ctrl-C stops it. It takes the CANPico off the bus, then prints the count for each ID


What is Recorded

With the plug rewired, I recorded the 420R with the ignition on, the engine off, and Easimap reading live values. The first recording was short, at 0.84 seconds and 447 frames, but it's enough to show what's on the bus.

ID

What it is

Frames

Per second

0x0CBE1101

Easimap's requests to the ECU

248

296

0x0CBE0111

The ECU's replies to Easimap

155

185

0x0CBB0001

The ECU's broadcast

44

52

All three are 29-bit (extended) CAN IDs, and that's the whole bus: about 530 frames a second.

Every frame in the first 320 ms, one mark per frame
Every frame in the first 320 ms, one mark per frame

The broadcast

The ECU's broadcast uses a single ID, 0x0CBB0001. The first byte of each frame is a row number, and the other seven bytes carry that row's values. My car sends rows 4, 3, 2 and 1, 10 ms apart, then pauses for 50 ms, so each row comes round every 80 ms, which makes 50 frames a second. You can see the pattern along the top of the timeline.


That turned out to matter. The other 420R's recordings also contain rows numbered 0xFF, which double the broadcast to about 100 frames a second, and my car doesn't send them. The dashboard recognised the broadcast by counting at least 50 frames in a second, so my car sat exactly on the limit, and depending on how each second fell, the dashboard might or might not have locked on. I lowered the limit to 25 frames a second before it caused any trouble.


Easimap's traffic

Easimap reads the ECU by asking for a list of memory addresses, and the ECU replies with their values. Easimap sent a request about every 8 ms on average, and the ECU started each reply typically a third of a millisecond after the request ended, and never more than one.


A request or a reply that doesn't fit in one 8-byte frame is split across several, using ISO-TP, the standard way of sending longer messages over CAN. Normally the receiver answers the first frame with a "flow control" frame before the rest follow. MBE's ECU doesn't use flow control, the sender just sends the whole message. Purplemeanie described this in his ECU Diagnostics series, and the recording shows it clearly. There's a good write-up at https://purplemeanie.co.uk/index.php/2019/09/15/ecu-diagnostics-part-8-easimap-uses-isotp/


The log

These are the first 16 lines of the text log. Each line is the time in seconds, the interface, then the ID and the frame's data bytes in hex.

(1795802880.150813) can0 0CBB0001#04A1A42891919191
(1795802880.152075) can0 0CBE1101#10230100000000F8
(1795802880.152791) can0 0CBE1101#21363744454C4D4E
(1795802880.153547) can0 0CBE1101#224F50515A5B5C5D
(1795802880.154307) can0 0CBE1101#23646A6B7C7D9091
(1795802880.155043) can0 0CBE1101#249E9FA0A1D8D9DA
(1795802880.155775) can0 0CBE1101#25DB9FA0A1D8D9DA
(1795802880.156089) can0 0CBE0111#101E814F397C3A0A
(1795802880.156367) can0 0CBE0111#21AAB886803DA80D
(1795802880.156639) can0 0CBE0111#227AA000B04F0000
(1795802880.156920) can0 0CBE0111#23C80518A1860700
(1795802880.157196) can0 0CBE0111#24800080A1860700
(1795802880.160810) can0 0CBB0001#0327912591910000
(1795802880.167187) can0 0CBE1101#100B0100000000F9
(1795802880.168070) can0 0CBE1101#21AFBABBBCBD00F9
(1795802880.168380) can0 0CBE0111#0681C7781EDC1EF9

Reading it from the top:

  • Line 1 is broadcast row 4.

  • Lines 2 to 7 are one Easimap request, 35 bytes long (0x23), split over six frames. The first frame starts 10, and the rest follow straight away, numbered 21 to 25, with no flow control frame from the ECU in between. The request asks for memory page F8, then lists the addresses it wants: 36, 37, 44, 45 and so on.

  • Lines 8 to 12 are the ECU's reply, 30 bytes (0x1E), starting with 81, followed by the values.

  • Line 13 is broadcast row 3, 10 ms after row 4.

  • Lines 14 to 16 are the next, shorter request and its reply, which fits in a single frame (06).

One note on privacy. When Easimap first connects, it asks the ECU to identify itself, and the reply includes the ECU's ID, which I treat as private. I ran the log through a script that blanks out that reply wherever it appears. This recording started after Easimap had connected, so it doesn't contain one, and the excerpt above is unchanged.


Summary

My ECU decoding script gives a quick summary of any recording.

This is its output for this one:

test.pcap: 447 frames over 0.8 s

         id format   frames   per s  note
  0xCBE1101 29-bit      248   295.7  Easimap request (ISO-TP)
  0xCBE0111 29-bit      155   184.8  ECU reply to Easimap (ISO-TP)
  0xCBB0001 29-bit       44    52.5

0xCBB0001: byte 0 takes 4 values - looks multiplexed (an MBE datastream uses byte 0 as the row id)
   byte0 0x01: 11 frames, median repeat 80 ms; constant bytes [1, 2, 3, 4, 5, 7]
   byte0 0x02: 11 frames, median repeat 80 ms; constant bytes [1, 2, 3, 6, 7]
   byte0 0x03: 11 frames, median repeat 80 ms; constant bytes [1, 2, 3, 4, 5, 6, 7]
   byte0 0x04: 11 frames, median repeat 80 ms; constant bytes [2, 3, 4, 5, 6, 7]
   first 32 byte0 values (F = 0xFF): 43214321432143214321432143214321

Easimap polling present: 100 requests. Decode them with easimap-trace.

Decoding row 1

Row 1 carries most of what a dashboard needs.

In this recording it reads 01 3A 00 00 3D 00 A1 39:

Value

Bytes

Formula

Reading

Coolant

3A

−30 + 0.625 × 58

6.2 °C

Engine speed

00 00

low byte + 256 × high byte

0 rpm

Throttle sensor

3D

0.01953 × 61

1.19 V, throttle closed

Throttle site

00

16 × 0 / 255

0

Battery

A1

0.0781 × 161

12.6 V

Air temperature

39

−30 + 0.625 × 57

5.6 °C

That's a cold car on a November evening, with the engine off: everything as it should be. The battery byte flicks between A0 and A1, 12.5 and 12.6 V, through the recording.

Comments


follow me
  • Twitter Social Icon
  • White YouTube Icon
Meet Mark
Loves cars, light weight specials, jDM, Lotus, Caterham, Rallying and Trackdays
Mark Rodman Isle of Man CTRMint
bottom of page