OBD-II diagnostic connector, as an interface for IoT

Once upon a time, around the mid-90s, during the appearance of the Pentium Pro processor, one of the founders of Intel, Gordon Moore, noted that: “If the automotive industry developed at the speed of evolution of the semiconductor industry, today Rolls-Royce could drive half miles per gallon of gas, and it would be cheaper to throw it away than pay for parking. ” But, perhaps, today the automotive industry is making a giant development step in the direction of a cardinal change in the type of fuel and the technology of driving a car. Almost recently, commercial electric cars and hydrogen-powered cars are presented, and the autopilot becomes the desired component of the vehicle's electronic “stuffing”. For the most part, the rapid breakthrough of the automotive industry is due to the emergence of reliable and safe solutions based on intelligent electronics for automotive onboard control systems. But where is the Internet in the car in everyday life, where is the Internet of Things technology (IoT), as well as the well-known concept of a car connected to the network (Connected Car)?





The Rolls-Royce 103EX. Rolls-Royce unveils driverless electric car concept, complete with silk love seat - The Telegraph .



In fact, all of the above technologies already exist and are used, however, only in sufficiently separate solutions. The reason for this is the strict security requirements that must necessarily be implemented when launching any new technology or transport solution. Therefore, it cannot be said that, getting into a car with a smartphone, you can automatically get an IoT or Connected Car solution. In most countries, and this is very logical, there is a ban on using a smartphone or other gadgets at the wheel, and if we talk about voice assistants, in most cases they are annoying and distracting both the driver and passengers. In turn, the media center, additional video screens and excellent acoustics, of course, are very attractive components of a modern car. But I want to catch myself at the word, and note that how good it is to muffle the music and just look out the window at the passing past the streets or nature. Of course, there are traffic jams, but in this publication the goal is to point out several ethical components or to consider the problems of information glut of road users, and to consider those “invisible” components of IoT technologies that are already used in vehicles and are available for widespread use.







At present, an interesting and very promising solution for automotive IoT is the Mojio Open Connected Car platform. This open interface platform (API) provides a cloud service for "connected" cars and commercial offers are already available. For example, the telecommunications giant T-Mobile, based on this platform, provides SyncUP DRIVE service. This is a software and hardware solution based on a portable device that is connected to the vehicle via the OBD-II diagnostic connector and the corresponding mobile application. Thanks to this approach, it is possible to effectively carry out continuous monitoring of the parameters of your car and at any time to get its current location. The application can tell about driving styles, warn about preventive maintenance, as well as notify the owner about problems with the vehicle. In addition, SyncUP DRIVE deploys a Wi-Fi access point in the car using high-speed mobile standard LTE access.





The Open Connected Car Platform - Mojio



To connect to the car using the standard diagnostic connector OBD-II. Most production cars produced after 1996 are already equipped with such a connector. Although this diagnostic connector is standardized, it supports several protocols of various engine control systems at once (physically using different contacts on the connector) that the IoT communication module must know. Accordingly, in different brands of cars there can be different internal tires for obtaining diagnostic data from the engine control side (ECU - Electronic control unit). To work with the SyncUP DRIVE service, we offer a solution based on the ZTEWelink VM6200S module.



VM6200S module supports connection via mobile LTE protocol, contains an integrated 3-axis acceleration sensor and 3-axis gyroscope, GPS receiver, OBD-II chip, supporting ISO 15765-4 (CAN), ISO 14230-4 KWP protocols (Keyword Protocol 2000), ISO 9141-2 (Chrysler, Euro, and Asian automobiles), SAE J1850 PWM (Ford vehicles), SAE J1850 VPW (GM vehicles). Thus, the module allows you to deploy a Wi-Fi access point 802.11 b / g / n /, record events while driving, perform engine diagnostics, evaluate fuel economy, etc. And since the partners of Mojio are Amazon Alexa projects, IFTTT service and others, then all prospects open up for developers and solution integrators, including the creation of a social IoT based on a “connected” car as part of such an infrastructure.





VM6200S4G OBD Device - ZTEWelink Corporation



But not only SyncUP DRIVE is now on the market, for example, many companies provide something similar. Of course, the newly emerged Samsung Connect auto device is one such interesting suggestion that turns a car into a connected device. Samsung's solution similarly uses the 4G LTE generation mobile network and expands a Wi-Fi access point inside the car: 802.11 a / b / g / n. Connect auto device supports Bluetooth v4.1 connectivity, contains a GPS receiver, an acceleration sensor, a gyroscope and is based on a 4-core 1.2GHz processor and Tizen operating system. It should be noted that the Korean electronic giant Samsung speaks about the security of the system through the use of Samsung Knox - a mobile solution with enterprise-level protection. In fact, Samsung Knox is a software and hardware solution to enhance the security of the Android operating system.





Samsung Connect auto



Thus, the information obtained by means of OBD-II data reading, current location coordinates from a GPS receiver and vehicle dynamics parameters obtained from gyro sensors, at the current time and de facto, became the basis for turning any vehicle into IoT device. Further, we can consider scenarios for using aggregated information received from cars, apply various Big Data processing techniques, and at the same time, we should not forget about the prospects for combining such data with information from the infrastructure of “smart” roads. But before you start processing data, you must first get them, so this publication will focus on the hardware component of the implementation scenarios at the level of the diagnostic connector OBD-II.



One way or another, but all the previously reviewed solutions are more advanced industrial products, compared with the conventional diagnostic code reader on the basis of the ELM327 chip by the Canadian company Elm Electronics. ELM327 is a versatile protocol converter used in vehicle diagnostic tires to serial protocol type RS-232.





Block Diagram ELM327 v2.2 - Elm Electronics



The interaction with the ELM327 is carried out by standard AT-commands supported by the chip. You just need to organize the exchange of text messages on the RS-232 protocol, which has already become a classic (or, more correctly, the UART , since we are talking only about the data flow, and not the signal levels). And the very low level physical connection via USB, Bluetooth or Wi-Fi is simply implemented using serial conversion chips UART. It turns out that in order to turn a car into an IoT device, it’s quite enough, without forgetting to adjust the voltage levels, connect the ELM327 chip to the OBD-II diagnostic connector and, for example, put a serial interface converter into Bluetooth or Wi-Fi at the output of this chip. Then, you can “read” vehicle diagnostics from your smartphone. However, there are plenty of such ready-made modules or units on the market. And their price on AliExpress ranges from US $ 2.50 to US $ 10. Although the module does not have to consume a lot of energy, but it will be very convenient if there is already a power button on it. By the way, in terms of security - this is also not bad.





Mini ELM327 Bluetooth OBD-II Car Diagnostic Adapter V1.5



Now you can connect the standard module Mini ELM327 Bluetooth OBD-II V1.5 (it is interesting that many sources advise using modules with the old firmware version 1.5, and not new ones with version 2.2, i.e. the more stable operation of the module on the old firmware and support for more cars, but it is very subjective) and experiment with connecting a smartphone to the selected module, for example, for the Android platform you can use one of the most popular diagnostic programs Torque Lite (OBD2 & Car) or Torque Pro (OBD 2 & Car) as well as anything n easier to use, or their achievements.





The work of the Torque Pro application for Android.



By the way, I would like to note a very convenient MockUPhone service with free mock-up of modern gadgets, which was very useful for preparing a screenshot of the work of the Torque program. But this is a slight departure from the topic of publication. It should be noted that in most cases, the OBD-II connector to which the diagnostic module is connected is under the steering column of the car.





Getting Started with OBD-II - SparkFun Electronics



It is clear that there are many ready-made solutions. But if we are talking about developing a service based on IoT or more specifically, the concept of Connected Car is being implemented, then it is quite convenient to use the on-board information network emulator of the car so as not to run to the car every time. For example, Mojio to work with its API offers an online car simulator, and an example of working with the IBM Watson IoT Platform cloud service in the article: " Sending Vehicle Data to the IBM Watson IoT Platform - IBM developerWorks Recipes " is proposed for sending data to the cloud means to use a mobile application, for example, “ IBM IoT for Automotive - OBDII Fleet Management App for Android ”, which interacts with the deployed cloud service “ IBM IoT for Automotive (Bluemix) - Fleet Management Starter Application ”, but if you do not get distracted by these projects use a simple data emulator: " Car Simulator ". True, all these decisions, basically, emulate the data already received, as it were, and we are interested in the on-board information network emulator. The most well-known such solution is ECUsim 2000, the cost of which starts from US $ 200 and depends on the number of supported emulated protocols.





ECUsim 2000 OBD Simulator - ScanTool



Of course, a professional emulator is no substitute, but enthusiasts and geeks may well be interested in the independent implementation of a less complex project on Arduino or Raspberry Pi. For example, you can limit yourself to only the most common CAN interface (Controller Area Network). At one time, the CAN standard proposed by Bosch made significant progress in the development of automotive electronics systems. If the car appeared on the Internet only recently, then the concept of a network inside the car has existed since the mid-80s. The idea is very simple, and as Ethernet made a breakthrough in computer networks, so CAN became the basis for reliable communications inside the car.





An Arduino Based CAN Bus Network - Henry's Bench



Earlier in the car, as a rule, tires and wires of various connected modules and devices “flowed” to the central engine control unit. A sequential two-wire CAN bus allowed the implementation of already independent intelligent modules, for example, the central control unit became just one of these modules that “communicate” with each other in fact via a network protocol. This significantly reduces the amount of wiring inside the car.



Unlike Ethernet, the CAN network is much more reliable, which led to its use not only in the automotive industry, but also in industrial automation systems, smart home solutions, etc. At the physical layer, CAN uses a two-wire line, CAN Lo and CAN Hi, which transmit data packed in a bit-by-bit package. At the ends of the bus there are terminating resistances of 120 Ohms, and twisting the wires should also be used to suppress interference. Data transfer rate can reach 1 Mbps.





A Controller Area Network (CAN bus)



Data transfer to the CAN bus is somewhat reminiscent of the publisher-subscriber model, where each device on the bus has a unique identifier and when one device transmits data, everyone else listens and decides on the basis of this identifier whether they specifically need these data for reception and processing or not. In general, the protocol is rather complicated, but for a microcontroller or microprocessor, it is unlikely that you have to write a CAN implementation, as well as think about the features of the physical transmission medium. Ready-made hardware bus controllers are already available for solving these tasks, and integrated converters are often used for level matching. For example, the MCP2515 controller with SPI interface and the transceiver (matching level chip) MCP2551. Just on the basis of these microcircuits, the proposed project Arduino OBD2 Simulator, published on the Instructable site. To implement it, you need only the Arduino UNO and CAN-BUS Shield, for example, from Seeed Technology.





Experiments using the Arduino OBD2 Simulator



In principle, for the development of an OBD-II data emulator, the presence of a 12V DC power supply for the ELM327 module, as well as an OBD-II connector, will not interfere. However, the no-name DC-DC-USB-TO-12V converter can easily solve the problem, since Some 5V power supplies will probably be on hand with any developer for the Internet of Things and beyond. To connect to OBD-II, you need two information wires CAN_H and CAN_L, as well as the presence of 12 V power supply, but as noted earlier, 12 V is needed only to ensure efficiency for the ELM327 module.





CAN-BUS Shield V1.2 - Seeed Development Limited Wiki



On the CAN-BUS Shield expansion card it is very convenient to use not the D-SUB connector, but simply a two-pin terminal block (CAN_H, CAN_L). From the point of view of software development, it should be noted that the prototype enthusiasts posted on GitHub . Now, the Seeed boards have changed, and in any case, for the MCP2515 controller, it is better to use all the new Seeed-Studio drivers. Of course, the original program will need to be slightly modified for new drivers, but this is a matter of a couple of minutes.





Work with CAN-BUS in Arduino IDE based on low cost OBD2 ECU Simulator



However, the considered example is very primitive, since all the parameters sent via the OBD-II protocol are simply generated randomly, there is no connection between the parameters of the engine operation, etc. As a continuation of the project, the development of an application similar to Freematics OBD-II Emulator GUI is obvious. This is an open source graphical shell that is used in the Freematics OBD-II Emulator hardware solution.





Freematics OBD-II Emulator GUI - Freematics



Thus, having assembled a module on the basis of Arduino that allows to work with CAN, it is quite possible to create an OBD-II emulator, since the diagnostic protocol is well described and easy to implement. It should be noted that the implementation of the interaction of the microcontroller and the on-board CAN bus is a completely different task and you need to understand that the internal high-level protocols of this bus are not documented by the automakers, and on the other hand, they should not be embedded in the internal structure of automotive electronics so as not reduce the safety of vehicle operation. If we talk about CAN in general, then it is possible to use the high-level open CANopen protocol to develop your devices based on this bus.



It remains to be easy - a little free time and a pleasure to develop your own code. True, where is the time found at the end of the year? But let's be optimistic. But if we talk about the use of such an OBD-II emulator, the most direct direction is the development of its own module for the diagnostic connector. For example, you can take the Carloop open project as a starting point, which aims to create a module for connecting a car to the cloud using 3G, Wi-Fi or Bluetooth technology.





Carloop bluetooth



The Carloop project is based on the use of boards: Particle Photon (based on the Cypress BCM43362 Wi-Fi module that supports the 802.11b / g / n standard; ARM Cortex M3 controller family — STM32F205 at 120Mhz; 1MB of flash memory; 128KB of RAM) and Electron (boards supporting 3G / 2G mobile network connectivity). Particle platform itself is very interesting, because it is based on the cloud connection service of IoT devices, a cloud IDE for development, for example, based on Photon boards, which uses a language similar to C / C ++ for Arduino. In fact, Particle is a separate topic for publication, and the Carloop project definitely deserves special attention from the enthusiasts of the car, as a connected IoT device.



By connecting the car to the Internet and IoT services, you can implement a variety of scenarios that will undoubtedly contribute to the ease of use of vehicles, increase comfort and, simply, effective solutions to everyday tasks, of course, including the solution to transportation. For example, data on driving style, reliability of the engine and car units, it is possible and already now are taken into account by insurance companies. The current location of the car will be relevant for taxi services and car rental. The interaction of road users becomes more convenient when using IoT, as well as the problem of parking, searching for free parking spaces, and much more.







We hope that the idea of ​​this publication has been achieved - materials on working with the OBD-II diagnostic connector are collected in one place, both at the level of simple reading of fault codes and emulation of the physical connection to the car. We also hope on the comments of readers. In conclusion, I would like to note that only some issues of the development of the Connected Car devices were considered, but “behind the scenes” there were many technologies that, one way or another, turn the modern car into an IoT device and make riding more comfortable and safe. Of course, we will return to these topics in our future publications.



Interesting resources and links:



- Car Hacking: Are car safety systems safe? - Habrahabr

- Microprocessor is 25 years old! - Computerworld

- T ‑ Mobile SyncUP DRIVE - T-MOBILE

- ZTE and Mojio will make almost any car part of the Internet of Things - ZTE Corporation

- Samsung Knox - SAMSUNG

- Possibilities of the CAN protocol - STA log

- Internet of things in your home - connect your car to your home - IBM developerWorks

- Vehicle telematics analytics using Watson IoT Platform Cloud Analytics - IBM developerWorks Recipes

- Using CAN network and CANopen stack - Habrahabr

- CANopen High Level Protocol - Journal of RADIOLOTSMAN

- The onboard computer for a car on Arduino the hands - Geek magazine

- Wiring the MCP2515 Controller Area Network CAN BUS Diagnostics - 14CORE

- Arduino OBD2 ELM327 I2C-LCD HC05 Bluetooth - Instructables

- Development of Android applications for working with OBDII protocol - Habrahabr



All Articles