
OBD-II Scanner on CAN Bus with Raspberry Pi 5 - Proteus Simulation

Hello friends, I hope you all are doing great. Today, I am going to share the OBD-II Scanner on CAN Bus with Raspberry Pi 5 in Proteus Simulation, the sixty-second project of our IoT Projects series. If you have searched for a Raspberry Pi OBD-II reader, a CAN bus project with the MCP2515, or a Proteus simulation of car diagnostics, here is a complete one. Every car built in the last twenty-five years has a diagnostic port under the dashboard, and behind it a CAN bus where the engine's control unit answers questions: how fast the engine turns, how hot the coolant is, whether the check engine lamp is on and why. Here a Raspberry Pi 5 is the scan tool, and an Arduino UNO plays the engine's control unit, with a throttle knob and a real coolant temperature sensor.
In this tutorial, we will go through the circuit, see how a CAN bus works and why every node hears every frame, how an OBD-II request and its answer fit in one 8-byte frame, how the Pi drives the MCP2515 CAN controller with its own SPI instructions and no library, how the engine values are packed into bytes, how a trouble code like P0217 is stored and decoded, walk through both programs, and then run the simulation: idle, driving, an overheating engine that lights the check engine lamp, reading the code, cooling down and clearing it. At the end, you can download the project with both programs and every library file.
NOTICE: Our team has put a lot of effort into this project: the circuit, the code and every part in the simulation are our own work, and you get them all free. Your feedback is the fuel that keeps us going, so please tell us what you think in the comments below. And if our free projects help you, you can buy us a coffee. So, let's get started with the OBD-II scanner on CAN bus with Raspberry Pi 5 in Proteus simulation:
What Does This OBD-II Scanner Do?
- Joins the car's CAN bus: an MCP2515 CAN controller with its TJA1050 transceiver on the Pi's SPI bus, at 500 kbit/s, the speed of the OBD-II port.
- Finds the engine: asks which values the engine control unit (ECU) supports, the way every scan tool starts.
- Reads live data: RPM, speed, coolant temperature, throttle position and engine load, several times a second.
- Watches the check engine lamp: the MIL (malfunction indicator lamp) and the number of stored trouble codes.
- Reads and clears trouble codes: OBD-II mode 03 reads them, mode 04 clears them and turns the lamp off.
- Shows it all: a 20x4 LCD like a handheld scanner, and a dashboard on a laptop or a phone with READ CODES, CLEAR CODES and a trend of RPM and coolant.
- Plays the car too: an Arduino UNO with its own MCP2515 is the engine ECU, with a throttle knob, a 100 kohm NTC coolant sensor and an amber check engine lamp.
It is a great project for learning CAN bus, SPI, the OBD-II protocol and binary data on a Raspberry Pi 5, and for seeing two very different computers talk over one bus. In the simulation, each MCP2515 has a pop-up that lists every frame on the bus, request and answer, and opens any frame field by field and bit by bit. The coolant sensor's pop-up sets the engine's temperature, from ice to boiling, and the throttle is a knob.
Components Used in the Proteus Simulation
All the parts come from our Proteus libraries, each with its own tutorial. The project zip at the end includes every LIB and DLL file and the TEPPi runtime that runs Python in Proteus.
| Part | Proteus device | Library post | Connection |
|---|---|---|---|
| Raspberry Pi 5 | RASPBERRY PI 5 | Raspberry Pi 5 Library for Proteus | PI1, obd_scanner.py, Ethernet 192.168.1.51 |
| 2 x MCP2515 CAN module | MCP2515ADVTEP | MCP2515 CAN Bus Module Library | U1 on the Pi's SPI0, U2 on the UNO's SPI; CANH / CANL joined |
| Arduino UNO V4.0 (the ECU) | ARDUINO UNO V4.0 | Arduino UNO Library for Proteus V4.0 | ARD1, OBD_ECU.hex |
| 20x4 I2C LCD | I2CLCD20X4BLUEADVTEP | I2C LCD 20x4 Library for Proteus | LCD1 on the Pi's I2C1 at 0x27 |
| Potentiometer (throttle) | POTROTARY16TEP | Potentiometer Library | RV1, the UNO's A0 |
| NTC 100k glass (coolant) | NTCGLASS100KTEP | NTC Thermistor Library | RT1, the UNO's A1, R1 100k from +5V |
| Amber 5 mm LED (MIL) | LED5MMORANGETEP | 5mm LED Library | D1, the UNO's D7 through R2 220 ohm |
| Resistors | RESISTOR4BANDTEP | Resistor Library | R1 100k, R2 220 |
| Laptop WiFi Monitor | LAPTOP WIFI MONITOR | Laptop WiFi Monitor | PC1 |
| Mobile WiFi Monitor | MOBILE WIFI MONITOR | Mobile WiFi Monitor | MOB1 |
Proteus Simulation of the OBD-II Scanner: the Circuit
| Part | Pins | Connection |
|---|---|---|
| U1 (the scan tool) | SCK / SI / SO / CS / INT | GPIO11 / GPIO10 / GPIO9 / GPIO8 (CE0) / GPIO25 |
| U2 (the ECU) | SCK / SI / SO / CS / INT | D13 / D11 / D12 / D10 / D2 |
| U1 and U2 | CANH / CANL | joined: the CAN bus |
| LCD1 | SDA / SCL | GPIO2 / GPIO3 |
| RV1 throttle | 1 / W / 3 | GND / A0 / +5V |
| RT1 coolant | 1 / 2 | A1 (and R1 100k from +5V) / GND |
| D1 MIL | A (through R2) / K | D7 / GND |
Each MCP2515 module has two chips: the MCP2515 is the CAN controller, which builds and checks frames and talks SPI to its computer; the TJA1050 is the transceiver, which turns the controller's logic levels into the two-wire differential signal on CANH and CANL. A CAN bus is just a twisted pair with a 120 ohm resistor at each end; every node connects to the same two wires. The coolant sensor is wired as in a real engine: an NTC thermistor whose resistance falls as it warms, in a divider with a fixed 100 kohm resistor, so the voltage on A1 falls as the engine heats up.
How the OBD-II Scanner Works
The CAN Bus: Every Node Hears Every Frame
CAN (Controller Area Network) was designed for cars: a single pair of wires links dozens of control units, and every unit hears every frame. A frame does not carry a destination address; it carries an identifier that says what the message is, and each node decides whether it cares. The identifier also sets the priority: when two nodes start at once, the lower identifier wins the bus bit by bit and the other waits. Each frame carries up to 8 data bytes, a CRC to catch errors, and an acknowledge slot that every receiver drives, so the sender knows somebody heard it. At 500 kbit/s a frame of 8 bytes takes about 0.25 ms on the wire.
OBD-II on CAN: One Question, One Answer
OBD-II on CAN (ISO 15765-4) uses a few fixed identifiers: a scan tool sends its request to 7DF, which every emissions-related ECU must answer, and the engine answers from 7E8. A request fits in one frame: the number of bytes that follow, the mode, and the PID (the parameter number). Mode 01 asks for live data; the answer repeats the PID and adds 0x40 to the mode. Worked example from the run: the request 02 01 0C asks mode 01 for PID 0C, the RPM; the engine answers 04 41 0C 37 82, four bytes that follow, mode 41 (01 + 40), PID 0C, then A = 0x37 = 55 and B = 0x82 = 130. The formula for PID 0C is (256 x A + B) / 4 = (14080 + 130) / 4 = 3552 rpm.
Engine Values in Bytes
Each PID has its own formula, fixed by the SAE J1979 standard, so any scan tool can read any car. PID 0D is the speed in km/h, one byte. PID 05 is the coolant temperature with a 40 degree offset, so a byte of 0x95 (149) means 149 - 40 = 109 C, and the range covers -40 to 215 C without a sign. PID 11 is the throttle and PID 04 the load, both as A x 100 / 255 percent: 0x7F (127) is 49.8 %. PID 01 packs the check engine lamp into bit 7 of its first byte and the number of stored codes into the other seven: 0x81 means the lamp is on and one code is stored. PID 00 is a bitmap of the PIDs the ECU supports.
Trouble Codes
When an ECU finds a fault, it stores a five-character code and lights the MIL. The first letter is the system: P powertrain, C chassis, B body, U network; then four digits. On the bus a code is two bytes: the top two bits of the first byte are the letter (00 = P), and the rest are the digits in hexadecimal, so P0217 travels as 02 17. Mode 03 returns the stored codes after a count; mode 04 erases them and turns the lamp off. P0217 means engine coolant over temperature; the ECU here stores it when the coolant stays above 108 C for 2 seconds, so a passing spike does not count.
The Coolant Sensor: an NTC Thermistor
A thermistor's resistance follows the Beta equation: R = R25 x exp(B x (1/T - 1/298.15)), with T in kelvin. This one is 100 kohm at 25 C with B = 3950 K. Worked example at 90 C (363.15 K): 1/363.15 - 1/298.15 = -0.000600, times 3950 is -2.371, and exp(-2.371) = 0.0934, so R = 9.34 kohm; the sensor's pop-up showed 9.333 kohm. In the divider with 100 kohm from 5 V, A1 sees 5 x 9.34 / 109.34 = 0.43 V. The ECU turns the reading back into a resistance, then into a temperature with the same equation solved for T.
Driving the MCP2515 from Python
The MCP2515 takes a handful of SPI instructions: RESET, READ and WRITE a register, READ STATUS, LOAD TX BUFFER, REQUEST TO SEND and READ RX BUFFER. After RESET it is in configuration mode, where the bit timing is set: with its 8 MHz crystal, the three CNF registers 0x82, 0x90 and 0x00 give a bit of 8 time quanta of 0.25 us, which is 2 us, 500 kbit/s. Both receive buffers are set to take every frame, the INT pin goes LOW when a frame arrives, and a write to CANCTRL switches the chip to normal mode. To send, the Pi loads the identifier, the length and the data into transmit buffer 0 and asks it to send; to receive, it waits for INT to go LOW and reads the buffer, which frees it at the same time.
The Code Explained
The scan tool is obd_scanner.py, plain Python with lgpio for the SPI bus, the INT pin and the I2C LCD. The bit timing and the receive buffers are set in configuration mode:
self.write(0x28, [0x82, 0x90, 0x00]) # CNF3, CNF2, CNF1: 500 kbit/s with an 8 MHz crystal (8 TQ of 0.25 us)
self.write(0x60, [0x64]) # RXB0CTRL: every frame, roll over into RXB1 when full
A frame goes out through transmit buffer 0: the 11-bit identifier split over two registers, the length and the data:
self.xfer([self.LOAD_TX0, can_id >> 3, (can_id & 7) << 5, 0, 0, len(data)] + list(data))
A received frame comes back the same way, and its identifier is put together again:
return (d[0] << 3) | (d[1] >> 5), bytes(d[5:5 + (d[4] & 0x0F)])
An OBD-II request is one padded frame to 7DF:
can.send(REQUEST_ID, [len(body)] + body + [0] * (7 - len(body)))
The Pi reads only when the MCP2515 says a frame is waiting:
if lgpio.gpio_read(chip, INT_PIN) == 0: # (INT LOW: a frame is waiting)
The answers are decoded with the standard's formulas, and PID 01 gives the lamp and the count:
if pid == 0x0C: s['rpm'] = (256 * a + b) / 4 # (256 A + B) / 4
mil, count = bool(a & 0x80), a & 0x7F
Two bytes become a trouble code:
return 'PCBU'[b1 >> 6] + str((b1 >> 4) & 3) + '%X%02X' % (b1 & 0x0F, b2)
The engine is OBD_ECU.ino on the UNO, with the autowp-mcp2515 library. It joins the bus at the same speed:
can.setBitrate(CAN_500KBPS, MCP_8MHZ);
It reads the coolant sensor with the Beta equation:
return 1.0 / (1.0 / 298.15 + log(r / NTC_R25) / NTC_B) - 273.15; // the Beta equation, kelvin to C
And it answers each PID in the standard's format:
case 0x0C: answer(4, 0x41, 0x0C, r4 >> 8, r4 & 0xFF, 0, 0, 0); break; // (256 A + B) / 4 = rpm
case 0x05: answer(3, 0x41, 0x05, (byte)constrain(coolant + 40, 0, 255), 0, 0, 0, 0); break; // A - 40 = C
Mode 04 forgets the codes and turns the lamp off:
dtcCount = 0; hotSince = 0;
The scan tool polls the six live PIDs in a loop, and when PID 01 shows the lamp on with a code stored, it reads the codes at once with mode 03. All SPI and I2C traffic stays in that one thread. The dashboard's pages are / (the dashboard), /read and /clear (the codes), /trend.bmp (RPM and coolant over the last 120 seconds, the 108 C line in red) and /data (everything as JSON).
How to Run the Proteus Simulation
- Download the project zip below and install the library files and the TEPPi folder (the steps are under the download button).
- Open Pi-5-OBD-Scanner.pdsprj from the Proteus Simulation folder. Keep obd_scanner.py, OBD_ECU.hex and the DLL files next to it.
- Press Play. The scan tool finds the ECU, and the LCD shows the engine at idle with the coolant at 90 C.
- On the throttle's pop-up (RV1), press 50 %.
- On the coolant sensor's pop-up (RT1), press Boiling 100, then +10 C: the MIL lights and the code appears.
- Press -10 C twice, then CLEAR CODES on the Laptop WiFi Monitor.
Simulation Results: the OBD-II Scanner in Proteus
Here is the run that made the screenshots of this tutorial, 57 seconds of simulation: idle, driving at half throttle, an overheating engine with its trouble code, the code cleared, and idle again. The times are the scan tool's own clock, as it printed them on the Pi's terminal; the ECU's log has its own clock from its reset.
Idle: the Scan Tool Finds the Engine
At 0.1 s the MCP2515 is in normal mode at 500 kbit/s, and at 0.2 s the first answer arrives: "ECU 7E8 found: PIDs 01 04 05 0C 0D 11 supported". From then on the scan tool polls the live data: 805 rpm, 0 km/h, coolant 90 C, throttle 0 %, load 14 %, MIL OFF, each answer 2.0 ms after its request. The scan tool's MCP2515 pop-up lists the conversation: a request from 7DF, sent and acknowledged, then the answer from 7E8, into RXB0, again and again, with no error frame.
Driving at Half Throttle
The throttle's pop-up goes to 50 %, 2.50 V on the wiper. The engine climbs, and at 10.4 s the scan tool reads 3541 rpm, then 3552 rpm, 50 km/h, load 54 %. On the dashboard's trend the RPM line rises from the bottom and settles.
The Engine Overheats: P0217
On the coolant sensor's pop-up the air goes to Boiling 100, then +10 C, 110 C. The sensor follows with its 4-second time constant, its resistance falling to 5.39 kohm at 109.3 C. The ECU sees 108.8 C for 2 seconds and stores "DTC P0217 stored: coolant 108.8 C - the MIL is on", and the amber lamp lights. On the next PID 01 answer the scan tool sees it, at 29.0 s: "MIL ON - 1 code(s) stored", and reads the code at once: "mode 03: 1 code(s) - P0217 engine coolant over temperature". The LCD's last line becomes P0217 COOLANT HOT. The ECU's MCP2515 pop-up shows the frames that carry it: 06 41 01 81 07 E5 for PID 01 (0x81 = the lamp on, one code) and 03 41 05 95 for the coolant (0x95 - 40 = 109 C).
Cooling Down and Clearing the Code
Two presses of -10 C bring the coolant back to 90 C, but the code stays stored, as in a real car: the ECU remembers a fault until it is cleared. CLEAR CODES on the laptop at 46.1 s sends mode 04; at 46.2 s "mode 04: the codes cleared", and the ECU logs "the codes cleared by the scan tool - the MIL is off". At 46.4 s the scan tool sees PID 01 change: "MIL OFF - 0 code(s) stored", and the LCD is back to NO TROUBLE CODES. With the throttle back to 0, the engine returns to 811 rpm.
| What | Result |
|---|---|
| ECU found | 0.2 s: PIDs 01 04 05 0C 0D 11 supported |
| Idle | 805 rpm, coolant 90 C; answers 2.0 ms after each request |
| Half throttle | 3552 rpm, 50 km/h, load 54 % |
| Overheat | P0217 at 108.8 C; MIL ON, read with mode 03 (29.0 s) |
| Clear | mode 04 at 46.2 s; MIL OFF at 46.4 s |
| The bus | 3090 frames, 0 errors |
| Simulation | 57 s of simulation |
Download the Project Files
Click the button below to download OBD-II-Scanner-CAN-Bus-Raspberry-Pi-5-Proteus-Simulation-v1.0.zip (about 15.6 MB, without the source code of the models):
OBD-II Scanner on CAN Bus with Raspberry Pi 5 - Proteus Simulation V1.0- Proteus Simulation: Pi-5-OBD-Scanner.pdsprj, obd_scanner.py, OBD_ECU.hex and copies of the models.
- Python Code: obd_scanner.py (the scan tool) and OBD_ECU/OBD_ECU.ino (the ECU's Arduino sketch).
- Proteus Library Files: the LIB files of the Raspberry Pi 5, the MCP2515, the Arduino UNO V4.0, the LCD, the potentiometer, the NTC, the LED, the resistor and the two WiFi Monitors.
- Proteus Model Files: the DLL models and the TEPPi folder (Python 3.11 and the runtime).
- README.txt: the installation steps, the properties, the test results and the links to every library post.
No Proteus yet? Read How to Download and Install Proteus 7 and 8. New to libraries? Follow How to Install a New Library in Proteus.
How to Install the Project Files
- Close Proteus and extract the whole zip file, for example to your Desktop.
- Copy the files from Proteus Library Files into the LIBRARY folder of Proteus.
- Copy the files and the TEPPi folder from Proteus Model Files into the MODELS folder.
- Start Proteus and open the project from the Proteus Simulation folder.
Changing the Code
obd_scanner.py is plain Python: edit it next to the project and press Play again; PI1's PROGRAM property names the file it runs. The ECU sketch opens in the Arduino IDE with the autowp-mcp2515 library from the Library Manager; export the compiled binary and set ARD1's PROGRAM property to it. On a real Raspberry Pi 5, enable SPI with raspi-config; lgpio is already installed on Raspberry Pi OS.
Ideas to Extend the Project
- Read the vehicle identification number with mode 09 PID 02: it needs ISO-TP multi-frame messages (a first frame, flow control, consecutive frames).
- Log every value to a CSV file for a trip report, with the fuel trims and the oxygen sensors on a real car.
- Add more ECUs on the same bus (a transmission at 7E9, an ABS unit) and let the scanner list them all.
- Show freeze-frame data (mode 02): the engine values at the moment the code was stored.
- Turn the scan tool into a dashboard: big gauges on an HDMI screen in place of the LCD.
- Add a second fault, P0118 for a broken coolant sensor, when the NTC reads open circuit.
From Simulation to Real Hardware
- Read-only first: on a real car, only send standard OBD-II requests; never send arbitrary frames on a vehicle's bus.
- Mind the logic levels: the common blue MCP2515 module runs everything at 5 V, and its SO pin would push 5 V into the Pi's 3.3 V GPIO; use a level shifter, or a module with the MCP2515 on 3.3 V and only the transceiver on 5 V.
- Check the crystal: modules come with an 8 MHz crystal or a faster one; read it on the can, because the CNF values must match it or the node will not hear the bus.
- The OBD-II connector: CAN high is pin 6 and CAN low pin 14; the car's ECUs already terminate the bus, so do not add another 120 ohm.
- Power: the port's pin 16 has the battery's 12 V; a buck converter can power the Pi in the car.
Troubleshooting
- Looking for the ECU for ever: CANH to CANH, CANL to CANL, and both modules at 500 kbit/s with the same crystal.
- The MCP2515 is not in normal mode: check SCK, SI, SO and CS on GPIO11, GPIO10, GPIO9 and GPIO8.
- Frames on the bus but no answers: the ECU answers 7DF and 7E0; the scan tool listens for 7E8.
- The coolant reads wrong: the NTC from A1 to GND, the 100 kohm from +5V to A1.
- The code comes back after clearing: the fault is still there; cool the engine first.
Limitations of the Simulation
- The engine is the UNO's simple model: RPM follows the throttle, one gear gives the speed, and the coolant is set on the sensor's pop-up.
- Only single-frame OBD-II messages are used; multi-frame answers such as the VIN are left as an idea.
- The bus has two nodes and no other traffic; a real car's bus carries hundreds of frames a second from many ECUs.
- The network to the laptop and the phone is simulated inside Proteus.
- Raspberry Pi is a trademark of Raspberry Pi Ltd and the MCP2515 a product of Microchip; this project is not made or endorsed by them or by Labcenter, and it is not a tool for a real car.
So, that was all about the OBD-II Scanner on CAN Bus with Raspberry Pi 5 in Proteus Simulation. I hope it helps you understand how a CAN bus carries frames that every node hears, how an OBD-II question and its answer fit in eight bytes, how engine values and trouble codes are packed into bits, and how a Raspberry Pi drives a CAN controller with nothing but its SPI instructions, all tested in a simulation before you plug anything into a real car. More IoT projects with the Raspberry Pi 5 and the ESP32 are coming in this series. If you have any questions, ask in the comments and I will help you out. Till the next tutorial, take care and have fun!






















Comments
0