The purpose of this article is to tell about my experience in modifying a car and experimenting with a CAN bus.
How it all began
At first, I decided to add a front camera to my 2017 Chevrolet Cruze. Since the car already has a factory rear view camera, two things had to be figured out at a high level:
- The method of transferring video from the front camera, which I will add.
- A way to display images from the rear view camera on the screen at any time.
The video part was simple. From previous experience, I knew that you can make a switcher on the relay.
The launch on the screen turned out to be more difficult, and after some investigation I came to the conclusion that the car should give a signal from the rear-view camera to the screen via some kind of data bus.
Chevrolet has two different data buses. The first is the standard CAN, fast (500 Kbps) and reliable, it is used for critical data. The second is what GM calls the LAN (GMLAN), the older and slower bus (33.3 Kbps), which is used for non-security data.
I needed a way to listen to traffic over CAN, that is, a sniffer. The PCAN device is incredibly useful for this purpose.
Peak Can (PCAN) is a USB device capable of intercepting and transmitting messages. With Pcan View software, you can start working without much training.
Since the rear view camera is less important to safety than other components, I assumed that the data sought would most likely be on the GMLAN bus.
The simplest access point is the OBD2 connector. I connected Peak Can to the GMLAN bus, launched the software - and immediately started listening to the traffic.
The goal was to redesign the rear view camera call. To do this, with the sniffer turned on, I drove the car in reverse so that it turned on the display and then tried parking several times. Throughout this process, I noticed one ID with messages that consistently imitated my actions.
Then I parked and through Pcan View I tried to transmit the same message that I saw when the display turned on and off. In no time I had interacted with the bus.
PCAN Message Transmission
However, I did not plan to constantly ride with a laptop. We needed a way to automate these functions - and Arduino came in handy here. The ability to directly receive 12V power in combination with a lot of resources and online support made this choice obvious.
In addition to Arduino, I needed two components to complete the project: a CAN module and a relay module. In essence, Arduino is the brain that runs and executes code. The CAN module provides the ability to interact with the data bus, and the relay provides power to the front camera, and also acts as a video switcher between it and the rear view camera.
mcp2515 module (top), Arduino Uno (middle), relay module (bottom)
After adding and configuring the appropriate libraries, Arduino established a connection with the car.
Listening to Arduino traffic
Since I already knew that I could start the display, I started thinking about HOW to do it. The initial idea was to install a special instant call button on the panel, but I started thinking: “And what else can be used as a trigger on the network?”
In the course of the experiments, I found that messages with an ID corresponding to the "Cancel Cruise Control" button are also sent over the GMLAN bus. It was perfect because the cruise control turns on at speeds above 65 km/h when I use the front camera, and at speeds below 15 km/h the rear view camera will turn on to help with parking, so they will never overlap. After writing some code, I was able to make the Arduino recognize when the cruise control cancel button was pressed.
Recognition of a single press of a button
However, I didn’t want the camera to be activated every time I cancel the cruise control, so I decided that the best approach is to turn it (essentially) into a multifunction button. The camera is activated only if the button is “double pressed”.
After a long weekend exploring the millis function and debugging the code, I successfully programmed double-click recognition.
And when I tied it to my teams to control the display, I got a pretty cool small utility.
Double tap + commands
Now I had the opportunity to turn the display on and off, but there was one problem - what about the rear view camera? I needed them to work together with the front camera, as if they were set up in a factory like that.
On the block diagram, I depicted how I represent it.
I quickly realized that for such a system it is necessary at any time to know the state of three variables:
- Front camera module: did the driver turn it on or off?
- Camera display: is the display on or off?
- Reverse: is the car in reverse or not?
With no programming experience, it was very difficult to do, and all my free time I was thinking about different approaches.
In the end, I achieved success!
Now I was able to implement the operational logic that the relay controls.
control through a relay
Throughout the process, I learned more and more about the Arduino and noticed that the Nano version was able to do everything that was needed, while it had a smaller size and lower price. It is ideal for permanent installation in the car. I developed a model and printed out a case on a 3D printer to place the components as a compact unit for installation.
Finally the day came when I saw the results. Although you still need to tinker with the timing, but it was nice to see that the module works correctly.
Turn on/off parking mode, turn on/off front camera, automatically switch to rear view camera and automatically switch back
In general, this experience taught me a lot and opened my eyes to the possibility of integration directly with the CAN bus. It’s pretty amazing what you can achieve by connecting two wires.
In the future
In the future, I plan to write an in-depth tutorial on how to add additional functionality to existing buttons in your car using free software and components.