Słomkowski's technical musings

Playing with software, hardware and touching the sky with a paraglider and amateur radio as SP3OHM.

Bosch LSU 4.9 wideband lambda sensor with NXRD AFR2CAN


Notes on the NXRD AFR2CAN, an affordable Polish wideband controller for the Bosch LSU 4.9 lambda sensor. Wiring, the rusEFI-compatible CAN protocol and logging it on Linux through an OpenPort 2.0.

Recently, I replaced the old KE-Jetronic fuel injection system in a Mercedes-Benz W124 with an aftermarket EFI system. An article about it is in the making. The ECU of the new system is a Digital ECU Cheater I, made by the Polish company Ottomotive. It has a dedicated input for the narrowband oxygen sensor and a 0–5 V input for a wideband one, which requires an external controller. But what is the difference between the two kinds of oxygen sensors?

Older cars usually have only a narrowband oxygen sensor. The information it provides boils down to three states: too lean, stoichiometric, too rich. That information is enough when the engine is already tuned; the ECU only applies small corrections to the fuel injection map stored in the firmware, usually to keep the mixture stoichiometric.

But when creating these maps from scratch, one needs to know how lean or how rich the air-fuel mixture is under the given operating conditions. That requires a wideband oxygen sensor, which measures the air-fuel ratio (AFR). It goes by several names: wideband lambda sensor, wideband O2 sensor, UEGO sensor, or just wideband. Its reading is usually given as lambda (λ), the actual AFR divided by the stoichiometric one (14.7 for gasoline), so λ = 1 means stoichiometric. The wideband oxygen sensor is similar to the narrowband one: it has a Nernst cell and a heater, but it also has an oxygen pump (see the Wikipedia article on the wideband sensor). The oxygen pump has to be actively controlled. In production cars, a dedicated chip inside the ECU, such as the Bosch CJ125, does that; with aftermarket ECUs, an external wideband controller is usually required.

An affordable wideband controller, the AFR2CAN, is made by the Polish manufacturer NXRD. Apart from the manufacturer’s online shop, I couldn’t find a single mention of it on the web, so I decided to write down my notes and findings.

Bosch LSU 4.9 wideband lambda sensor

The Bosch LSU 4.9 is a popular wideband oxygen sensor used as standard equipment in production cars, as well as in racing and engine tuning. Many car manufacturers mark it with their own part numbers. The markings on my sensor were:

LS 17465
0 258 017 465

on the box and 1928404687 on the connector. The connector contains a trimming resistor, which sets the sensor’s characteristic, so no free-air calibration is needed. The mating connector for the automotive version is available under the numbers 1928404669, 1813139. The pinout:

Pin Function
1 pump current APE / IP
2 virtual ground IPN / VM
3 heater H− / Uh−
4 heater H+ / Uh+
5 trimming resistor RT / IA
6 Nernst voltage UN / RE

The LSU 4.9 measures lambda from 0.65 to ∞, so readings below 0.65 are outside the specification. The exhaust gas temperature must stay below 930 °C (1030 °C for a short time). The system supply voltage should be 10.8–16.5 V, and the heater power is 7.5 W in steady state. As usual for lambda sensors, it has the standard M18x1.5 thread. The full specification is in the datasheet (also available on the Bosch website).

NXRD AFR2CAN controller

The NXRD AFR2CAN is a wideband controller designed for the Bosch LSU 4.9 oxygen sensor. The controller alone costs about 60 euros. It is also sold as a kit with the oxygen sensor included. The manufacturer seems to be just one guy; the housing is 3D-printed.

The device is powered by +12 V and outputs the lambda value both on the 0–5 V analog output and over the CAN interface. Once warmed up, the controller together with the sensor draws about 800 mA. The wiring diagram:

NXRD AFR2CAN wiring

and the same as a table:

Color Function
black GND
red +12 V
white CAN H
green CAN L
blue analog 0–5 V, 10–20 AFR

The CAN protocol is compatible with the rusEFI protocol; for posterity, I describe it below. rusEFI itself is a popular open-source engine management system: ECU firmware together with open hardware boards. One of its subprojects is the rusEFI wideband controller, open firmware and hardware for the Bosch LSU 4.9. The rusEFI wideband controller is available as a standalone board and is also built into some rusEFI ECU boards. Its firmware has a bootloader, so it can be updated over CAN. Any controller that speaks the protocol, like the NXRD AFR2CAN, works with rusEFI ECUs. The protocol is also published as a DBC file, so the frames can be read with generic CAN tools.

My AFR2CAN unit didn’t work at first, so I reported it to the manufacturer. They quickly fixed the problem and sent me new firmware, along with a piece of Python code which flashes it over CAN through openport-j2534. I flashed it on the bench, with the controller powered from a lab power supply; after the update it started to work correctly.

If the AFR2CAN is placed at the end of the CAN bus, it is strongly recommended to enable the 120 Ω termination resistor. Inside the housing, the PCB has a labeled jumper that connects the 120 Ω resistor to the bus. To enable it, put a blob of solder on the jumper as shown in the photo:

Bottom side of the PCB with the 120 Ω CAN termination jumper soldered closed.

In my measurements, lambda over CAN ranged from 0.62 (AFR 9.1) at the richest moments to 2.00 on fuel cut. 0.62 is already below 0.65, the lower limit of the LSU 4.9 specification. 2.00 isn’t a real measurement: the rusEFI firmware clips lambda at 2.0, so the controller shows exactly 2.0000 both on fuel cut and in free air, even though the real lambda there is much higher. The analog output covers only AFR 10–20, so it saturates on fuel cut and at the richest moments. The analog output matches the CAN values very closely: in steady-state driving, the difference averaged 0.00 AFR, with 95% of samples within ±0.16 AFR (details below).

The sensor temperature stayed within 777–784 °C (779–780 °C for 99% of the time), and the internal resistance (ESR) within 292–307 Ω. The heater duty cycle was usually about 35% (range 21–85%).

CAN protocol

CAN 500 kbit/s, 11-bit identifiers for the data frames (the control frame and the bootloader frames use 29-bit ones), little-endian data (according to wideband-can.dbc from the rusEFI project). The controller with index N transmits two frames: 0x190 + 2N (reading) and 0x191 + 2N (diagnostics). My unit has index 0, so it uses 0x190 and 0x191. Both frames are sent 100 times per second (every 10 ms).

Standard data

Frame 0x190 + 2N (WidebandStandardData in the DBC), 8 bytes: version|valid|lambda|temperature|unused.

Value Size Description
version 1 Protocol version, 0xA0.
valid 1 1 when the lambda value is valid; 0 while warming up, when lambda is 0.6 or below, or when the Nernst voltage is off target.
lambda 2 Lambda × 10000, e.g. 12862 = λ 1.2862. 0 when not valid.
temperature 2 Sensor temperature in °C.
unused 2 Not defined in the DBC.

Diagnostic data

Frame 0x191 + 2N (WidebandDiagData), 8 bytes: esr|nernst|pump|status|heater|unused.

Value Size Description
esr 2 Internal resistance of the Nernst cell in Ω.
nernst 2 Nernst cell voltage in mV.
pump 1 Pump duty cycle, 255 = 100%.
status 1 Controller status: 0 preheat, 1 warmup, 2 running in closed loop, 3–5 faults (sensor didn’t heat, overheat, underheat). Always 0x02 in my logs.
heater 1 Heater duty cycle, 255 = 100%.
unused 1 Not defined in the DBC.

Control frame from the ECU

The DBC also defines a frame in the opposite direction, sent by the ECU to the controller. Frame 0x0EF50000 (extended 29-bit identifier, WidebandControl), 2 bytes: battery|heater_enable.

Value Size Description
battery 1 Battery voltage × 10, used for heater supply voltage compensation.
heater_enable 1 Set to 1 to allow sensor heating once the engine runs.

The current rusEFI firmware also accepts an optional third byte, not defined in the DBC, with the pump controller gain in percent.

Without that frame, the controller heats the sensor as soon as it gets power. The LSU 4.9 shouldn’t be heated while there may still be condensation in the exhaust, which is what heater enable is for.

I didn’t send this frame, and the controller works fine without it. I didn’t check whether it supports the frame at all.

I used the wideband controller only for engine tuning, so I didn’t add any protection against condensation. I power the controller from the same line as the ECU, so it starts heating at key-on. When in doubt, start the engine right away rather than leaving the ignition on.

Logging over CAN

To get the CAN data to the PC, I used an OpenPort 2.0 clone I had lying around. OpenPort 2.0 is a J2534-compatible OBD-II diagnostic interface with an OBD-II plug, which can also work as a generic CAN interface.

SAE J2534, also called PassThru, is a standard API for vehicle communication interfaces, defined so that a single diagnostic or reprogramming program can work with interfaces from different vendors. It specifies a set of C functions (PassThruOpen, PassThruConnect, PassThruReadMsgs, PassThruWriteMsgs and so on), but not how the PC talks to the interface over USB. That part is different for every vendor, so each interface still needs its own driver: a library that implements the J2534 API on top of the device’s own protocol.

Officially, the OpenPort 2.0 only has a Windows driver. I use Linux, however. Fortunately, several weeks before I started my tuning project, someone had already vibed an open-source driver for Linux: openport-j2534. I, in turn, just vibed a simple Python+Qt logger for AFR. The logger loads libj2534.so with Python’s ctypes and calls only the standard J2534 functions, so it doesn’t depend on the OpenPort beyond the driver it loads. I tested it only under Linux. openport-j2534 now also supports macOS and Windows, so the logger could work there as well. On Windows, it would need to load openport-j2534-64.dll instead; my logger doesn’t do that yet.

That said, you’d be better off with a dedicated CAN interface supported by the Linux kernel through SocketCAN, such as a CANable flashed with the candleLight firmware or another candleLight board (gs_usb driver), PEAK PCAN-USB (peak_usb), Kvaser Leaf (kvaser_usb), or an MCP2515 module on a Raspberry Pi (mcp251x). Standard tools like candump from can-utils then show the frames, with no extra driver needed. My logger doesn’t support SocketCAN yet, though. I guess if you tinker with cars, you probably have an OBD-II interface at hand anyway, so why not use it?

Connecting the AFR2CAN to the OBD-II connector

Before connecting the CAN bus, it is recommended to disassemble the controller and enable the 120 Ω termination resistor. On a short bus, it usually works without it, but proper termination won’t hurt, right? The CAN cable could be much longer (at 500 kbit/s, a CAN bus can be up to about 100 m long). Mine was under 30 cm, though.

The other side of the CAN bus, near the OBD-II connector, should be terminated with another 120 Ω resistor, as shown in the schematic. The CAN bus is exposed on pins 6 and 14 of the OBD-II connector:

NXRD AFR2CAN connected to the OBD-II connector over CAN, with the 120 Ω terminating resistor on the OBD-II side and external 12 V supply.
NXRD AFR2CAN connected to the OBD-II connector over CAN, with the 120 Ω terminating resistor on the OBD-II side and external 12 V supply.
↑ click to enlarge ↑

The W124 has no OBD-II, of course. I used an OBD-II socket from a scrapyard car just as a connector for the OpenPort, so I didn’t have to solder anything to the OpenPort’s plug.

Using the setup

I used this controller to tune the M102 engine in a Mercedes-Benz W124 upgraded with aftermarket EFI. For the tuning, I replaced the old narrowband sensor with the wideband one. Both have the M18x1.5 thread, so the LSU 4.9 went into the existing hole in the exhaust manifold.

I attached the AFR2CAN controller and logged the data both from CAN and from the analog output. The ECU itself (the Digital ECU Cheater I by Ottomotive) logged the analog output, and the aforementioned vibecoded logger logged the CAN data.

I then compared the two to check whether the analog line was precise enough. I was worried that ADC and DAC inaccuracies, voltage differences between ground points, voltage spikes etc. might skew the readings.

I logged both during two drives of about 20 minutes each. The ECU logs the analog value less often than the controller sends CAN frames, and the clocks of the two logs didn’t match, so I aligned them by the shape of the AFR signal. In steady driving, the analog reading agreed with CAN very closely, within a few steps of the ECU’s 8-bit ADC, and the 0–5 V scale matched the nominal 10–20 AFR. Only during fast changes did the two differ more, because the slower analog log couldn’t keep up. For tuning the fuel map, the difference didn’t matter.

Once the analog line was verified, I unplugged the OBD-II interface and made further tweaks using only the analog input. The details of tuning the M102 engine will be described in an upcoming article.