Understanding your vehicle’s performance and diagnosing potential issues has become increasingly accessible thanks to On-Board Diagnostics II (OBD2). Since 1996, OBD2 has been a standard protocol mandated by the EPA, providing a wealth of data about your car’s inner workings. For vehicles manufactured from 2008 onwards, the Controller Area Network (CAN) bus (ISO 15765) is the backbone for OBD2 communication. Essentially, OBD2 is a communication protocol that operates on top of the CAN bus network. If you’re interested in tapping into this data to monitor and log your car’s performance yourself, creating a Diy Obd2 Data Logger with CANFDuino is a fantastic project.
OBD2 operates on a request-and-response principle. To retrieve data, a device, in our case CANFDuino, needs to periodically send requests. This system employs message multiplexing, meaning the same message ID is used for both sending requests and receiving responses. Within these messages, a “sub ID” further specifies the type of data being requested or provided.
These “sub IDs” are known as Parameter IDs (PIDs) in the OBD2 standard. While the CAN IDs for transmission and reception are generally fixed (Transmit (TX) – 0x18DB33F1 or 0x7DF, Receive (RX) – 0x18DAF10E or 0x7E8), the PIDs, located in the third data byte of the message payload, dictate what specific data you want to monitor. This could be anything from vehicle speed and throttle position to engine RPM and much more. For a comprehensive list of available PIDs and the parameters you can monitor and log, the Wikipedia entry on OBD-II PIDs is an invaluable resource.
The CANFDuino libraries simplify the process of incorporating OBD2 functionality, featuring classes like OBD2.h
and OBD2.cpp
. Adding different PIDs to monitor and log becomes straightforward. For each parameter you wish to track, you just need to include a few lines of code in your sketch (*.ino file). The code snippet below illustrates a class constructor in C++ where you define various attributes for each PID. These include the name, units, the PID itself, data size in bits, whether it’s a signed or unsigned number, real-time data, slope and offset in engineering units, the CAN port number, and whether your vehicle uses extended or standard IDs. Determining the correct ID type for your vehicle might require consulting online forums or testing both options.
If you encounter difficulties adding a new PID, a helpful approach is to first examine a PID example already present in the code, such as “Speed” or “Throttle.” Then, refer to the OBD2 PID Wikipedia page to understand how the units, PID value, slope, and offset are determined. You can then adapt these values for your new PID. Remember that adding a new PID also requires a minor modification to the OBDII.h
file, as shown in the subsequent code example.
***** DEFINITIONS FOR OBD MESSAGES ON CAN PORT 0, see https://en.wikipedia.org/wiki/OBD-II_PIDs to add your own ***************/ //char _name[10], char _units[10], OBD_PID pid, uint8_t OBD_PID_SIZE size, bool _signed, OBD_MODE_REQ mode, float32 slope, float32 offset, cAcquireCAN *, extended ID; cOBDParameter OBD_Speed( "Speed " , " KPH" , SPEED , _8BITS, false, CURRENT, 1, 0, &CanPort0, false);
The code snippet below shows the OBD2.h
file’s PID definitions. You’ll need to modify this section when adding custom PIDs for your diy obd2 data logger project.
/** * * This enum represents the Parameter ID field for a particular signal per the OBDII protocol */ enum OBD_PID { ENGINE_LOAD = 0x04, COOLANT_TEMP = 0x05, ENGINE_RPM = 0x0C, SPEED = 0x0D, ENGINE_IAT = 0x0F, ENGINE_MAF = 0x10, THROTTLE_POS = 0x11, FUEL_FLOW = 0x5E };
Getting Started with Your DIY OBD2 Data Logger
Now that we have a basic understanding of OBD2 and the provided CANFDuino code, let’s dive into a step-by-step tutorial to get your OBD2 vehicle communication and data logging system up and running using CANFDuino.
Step One: Initial Setup and Sketch Testing
Before connecting to your vehicle, it’s crucial to ensure your CANFDuino and software are working correctly. Follow the instructions in the Installing the Library and First Sketch guide to set up your environment and test a basic sketch. This step verifies that your CANFDuino board, Arduino IDE, and necessary libraries are properly installed and functioning before moving on to vehicle integration.
Step Two: Connecting to Your Vehicle’s OBD2 Port
To interface your CANFDuino with your car, you’ll need to establish a physical connection to the OBD2 port in your vehicle. Ensure your vehicle is a 2008 model or newer to guarantee CAN bus support for OBD2. You will require a vehicle interface cable, as shown below, correctly wired to the CAN High (CANH) and CAN Low (CANL) signals, connecting to port 0 on your CANFDuino. Using a flying leads cable combined with a DB9 to screw terminal adapter simplifies this wiring process, as illustrated below. Refer to the CANFDuino hookup guide for detailed instructions on connecting CANH, CANL, and Ground (GND).
OBDII to flying-leads cable, essential for connecting your diy obd2 data logger to your vehicle.
DB9 screw terminals, simplifying the wiring for your diy obd2 data logger.
A crucial note regarding OBDII-to-DB9 female cables: while these cables seem ideal for direct connection to CANFDuino, it’s vital to verify the pinout configuration. Ideally, you need a cable that maps CANH to pin seven, CANL to pin two, and GND to pin three. However, many OBDII-to-DB9 F cables incorrectly map GND to pin one instead of pin three. Always double-check the pinouts before purchasing an OBDII cable to avoid potential troubleshooting headaches and ensure a successful diy obd2 data logger setup.
Step Three: SD Card Formatting and Installation
The OBD2 sample code is designed to log Parameter ID (PID) values onto an SD card in CSV (Comma Separated Values) format. The SD card is essential for data logging; the system will not function without it. CANFDuino utilizes Arduino libraries for SD card support, so the card must be formatted to either FAT16 or FAT32, as outlined in the reference library instructions. Once formatted correctly, insert the SD card into the designated slot on your CANFDuino board. This ensures your diy obd2 data logger has storage for the captured vehicle data.
Step Four: Programming Your CANFDuino
Open the Arduino IDE and navigate to File -> Examples -> CANFDuino_OBD2Logger.ino to load the OBD2 logger sketch. By default, this code utilizes standard 11-bit CAN IDs, which have been tested successfully on vehicles from manufacturers like Mazda, Toyota, and GM. While 29-bit IDs are also supported (tested on Honda vehicles), they are less commonly used. Ensure you have selected the correct board and port in the Arduino IDE under Tools -> Board -> CANFDuino and Port -> COMxx. Now, click the upload button to compile and upload the code to your CANFDuino. Upon successful upload, open the Serial Monitor via Tools -> Serial Monitor and set the baud rate to 115K. For a cleaner, more stable real-time data display, consider using terminal programs like PUTTY or Chrome Terminal, similar to the setup used in the CANTerm sketch example detailed in the readme. Finally, connect your OBDII cable to your vehicle’s OBD2 port, typically located under the steering wheel, and start your car.
Step Five: Monitoring Data via Serial Monitor
After starting your vehicle and CANFDuino, the first message you should see in the Serial Monitor is a confirmation of successful SD card initialization. At this point, the CANFDuino should be actively communicating with your vehicle. The easiest way to verify data reception is to observe the Engine RPM (Revolutions Per Minute) readings in the monitor.
A successful data stream from PuTTY will appear similar to the example below:
OBDII monitoring in PuTTY, showing real-time data from your diy obd2 data logger.
Monitoring the data directly from the Arduino Serial Monitor will display readings similar to this:
System Reset Initializing SD card…card initialized. Engine Speed 0.00 RPM Throttle 0.00 % Coolant -40.00 C Speed 0.00 KPH Load 0.00 % MAF 0.00 grams/s IAT -40.00 C Engine Speed 862.50 RPM Throttle 16.08 % Coolant 59.00 C Speed 0.00 KPH Load 32.55 % MAF 4.17 grams/s IAT 25.00 C Engine Speed 865.50 RPM Throttle 16.08 % Coolant 59.00 C Speed 0.00 KPH Load 32.55 % MAF 4.10 grams/s IAT 25.00 C
Step Six: Accessing Your Logged Data
The OBD2 data captured by your diy obd2 data logger is saved in a file named “OBD2data.csv” on the SD card. CSV is a widely compatible format that can be opened and analyzed using various applications, including Microsoft Excel, Google Sheets, Notepad, and any text editor. Below is an example of a successful data log file. If your primary use case for CANFDuino is data logging, consider wiring the bootloader bypass jumper as described in the hookup guide for optimized performance.
Logged OBD2 data in CSV format, ready for analysis from your diy obd2 data logger.
Step Seven: Customizing and Expanding Your Project
Now that you have a functional diy obd2 data logger, you can explore further customization. Add more PIDs to monitor additional vehicle parameters, adjust the data logging frequency to capture data at your desired resolution, and modify the display output for real-time monitoring. We encourage you to fork the CANFDuino repository and contribute to the community by developing new features and improvements!
Thank you for your support. We wish you success in your diy obd2 data logger project!
Questions?
Ask Crowd Supply about an order Ask Togglebit a technical question