Being obsessed with idea to connect my car to the internet and give to it one step forward into the future, being inspired with work of Adam Varga ( his youtube channel https://www.youtube.com/@adam_) I have decided to design something similar that is interesting for me.
In the that same time I realized it would be a great opportunity to learn something new in software engineering.
So I'have decided to design my own digital cluster, give to it possibility to interact with web server, which provides us with web dashboard. In other words, we can collect data from vehicle and observe its statistic data on the web page.
On the way to approach it I have stopped on Raspberry Pi 4 platform, add GSM and GPS module to it.
Supplies and components
The list of equipment to implement our ideas:
- Raspberry Pi4 with touch screen, keyboard
- Arduino Mega 2560
- MCP2515 CAN bus adapter
- CANable adapter
- A9G GSM/GPRS Tkinter module
- Neo6m GPS module
- PyCharm IDE with Python and its GUI framework Kivy
- experiment sample car Kia Rio 3 with its CAN bus
Firstly had to be created plan and the main aim. Once having drawn it in my head, I repeated it on the paper, how it has to look like and its features. I had some thoughts and to make it true I had got know a lot of new information:
- learn about OBDII
- learn about CAN bus conception
- find out about screens implementation to the Arduino boards or others similar ones
- find out and investigate GSM module, its work in danish mobile network
- get know about web developing and its back-end
Initially I had been trying to use OBDII approach to read data off. But as far as I had been aware of at it was not the best option.
Firstly, via OBD I had only 7 accessible data types which was not much interesting for me.
Secondly, the speed of data transition was to low. Having designed app was quite visible delay between upcoming data and GUI reaction.
So I had to go further and I have got been aware of CAN bus, adapters and engineering in this area.
First step was to get know with CAN bus conception and its features. Actually is really rational implementation with the aim to save sources. Control Area Network - the main idea undermines that all modules microcontrollers are connected to common wire line "bus" which consists from 2 wires: CAN high and CAN low, correspondingly with higher and lover voltage from 0 to 5v connected in the ends with resistor 120 Ohm.
Signal from and to modules consists of voltage fluctuation: 0V is logical 0, 5V is logical 1. Having CAN bus might be achieved high speed data transmittance up to Mbits/sec that provides us with high performance of elements.
However, it is being used not only in automotive, in production, aviation, medicine etc. as well.
You can read a lot in web and get know how it works. Like here on the link bellow:
https://www.csselectronics.com/pages/can-bus-simple-intro-tutorial
My experimental car has not one CAN bus network, it has two of them.
The first one joins all significantly important nodes as ECU, ABS, ESP etc which provide car with power and behavior it on the road. It has speed 500kbit/sec.
As usually automotive producers do, they try to keep everything in secrets, even about wiring diagram, you have to put efforts to find it in the google.
Once finding it, we have to connect to CAN. I found out we have CAN wires in OBDII port.
Having OBDII diagnostics tool was not so difficult to disassemble it and solder into pins 6 and 14, 16th 12V power pin and ground, connected wire bring out from box and connect it into car network with OBD plug.
Having idea to read off CAN data with Arduino ATmega 2560 and MCP2515 I was to naive at that moment. The thing is Arduino board is quite slow for CAN bus interaction even it has 16MHz processor, it could lose some CAN messages.
MCP2515 works pretty well.
It is possible to find a wide variety of libraries in Arduino Manager which can provide us with CAN bus interaction. Howover, to decrypt CAN messages it was not enough. Was needed software which could work with MCP2515 and Windows OS, could sort messages into groups according to upcoming changes and so on. There were some bunch of them, I had to try a lot (CAN Hacker software for example) but I went with shorter way and bought CANable adopter specially to read CAN data from car, decode that message, after all it works with as long with python can library as with PCAN-viewer from Peek-System software.
PCAN-viewer is ease in usage, you can check it out. But to encode CAN messages we have to use reverse engineering approach.
The CAN communication is unique for each car. If you get success on some of them, it will not work on other one. On example of VW, to get CAN bus data you have to send frame request into CAN bus net, and after you going to get correspondant message back. On Kia/Hundai which I was encountered with the things are much easier.
Connecting to CAN bus with CANable adapter we have a list of incoming messages, which very easy to monitor in PCAN viewer.
Driving a car we can write down a trace and investigate written measurements later, because as sensors are sending distinguish data during trip in will be visible in changes in can message data.
Watching it, trying to send fake messages later with suspected type which sensor it has to belong to, we can observe behavior of speedometer, temperature arrow and so on as BCU of car thinks it gets messages from sensor an so on.
You can find a lot of information in detail on special sources.
I can recommend to start from here: https://www.carhackingvillage.com/getting-started
and highly recommend to read a book "The Car hacker's handbook". There is a lot of information how CAN bus and others networks work in cars
Next step was to find out which board can keep reading CAN data and satisfy my needs. I realized, that having ATMega 2560 as main board might bring troubles. Because it had to work following this scheme: CANbus adopter -> ATMega2560 -> GSM and Show information on the screen in the that same time.
I well know every next second is highly important as well as each byte, and if 1 cell brakes down and delays, it will crash all system.
However, Arduino on its own has not good size screens supporting, thus I decided to switch to the Raspberry Pi4 board
It has huge opportunities with a screen support.
High speed and performance with 4 core ARM processor.
Support Python on its board fixes all my troubles, but to achieve desirable result, to set my board in proper way I had to put a gigantic efforts. Linux is as new world after having Windows.
But I solved these issues with open source information on specialized RPi forum support and ofcource, Chat GPT really helped out to save my time.
To work with 3 adapters in that same time we can use GPIO UARTs and USB connection of the CANable adapter.
According to the wiring diagram above and to the following scheme:
get data from CAN, get data from GPS -> pass it to RPi4, info processing -> pass it to GSM
spending couple weeks of unsleepy nights I get wished results.
Later I noticed my RPi board gets heat to much so I've upgraded it with cooling system.
Pay attention, GSM A9G module works via AT commands. Writing your code, remember about it, each load and connection to the board requires it's configuration and connection.
Next step. App design.
As I am study Python as main programming language, I have designed it in Kivy GUI.
The app has 3 screens:
- Classic view
- Sport view
- Service screen with sensor data
Basically, it works quite well. The most challenging part is encrypting the messages and extracting
the desired information from them. Python has a wide variety of libraries to work with components. Specially to work with CAN bus, OBDII. I tried either python CAN library or PCANBasic from Peak-System. Both of them work but last one better. I mentioned it in the Troubleahooting chapter bellow.
The retrieved CAN bus data is processed by the app and sent to a web server. PHP scripts manage the data by retrieving it
from the GSM module and insering it into a database, extracting it from the database, and building corresponding plots using JavaScript.
http://vehicledata.atwebpages.com/index.html.
Yes it looks, to be humble to say, as dull one, but I am not the best professional in web development, it is my 1st web page in my life.
Finally, we can observe our vehicle's information through the plots, including details such as fuel consumption, CO2 emissions, and GPS tracking.
Actually I did not have a problems with design, but had a couple weeks back pain with making ends meet with getting can data, processing, converting it into graphic behavior.
TroubleshootingThat which I was encountering with:
- Kivy GUI Limitations: Kivy is not the ideal framework for developing digital clusters. Although it works, I initially intended to add a map as one of the screen widgets. However, the app has lost performance, leading to significant slowdowns in CAN data processing. As far as I got Kivy GUI not so good choice to implement multiprocessing approach.
- Power Supply for RPI4, A9G, and Neo6m: The Raspberry Pi 4 requires a strict 5V current and draws 0.6A during OS boot. This can impact additional components if they share the same power source. The A9G and Neo6m require 0.25A at 5V both. Any fluctuation in power supply during Raspberry Pi load can cause signal loss and connectivity issues with networks or satellites.
- Differences Between Linux and Windows: While Python itself is consistent across platforms, Linux offers a wider variety of libraries. For CAN bus functionality, the official python-can library is available, whereas the Peek-System company’s PCANBasic library, which we had to compile ourselves, works better for our needs. This last works perfect for me and did not have troubles as other one which might rise up an error: CAN bus was read to late with refer to cannotifier.py and its timeout. I have faced with a real pain in the butt. It seemed like everything was ready but can reading did not work. A week of debugging and problem was solved. I had to cut down my demands in my widgets updating.
- Different Pixel Grid on Laptop and RPi4 Screen: There is a discrepancy between the pixel grids of the laptop and the Raspberry Pi 4 screen, which affects the visual consistency and layout of the GUI.
- Connecting A9G and Neo6m to RPi4 via UART: Successfully connecting the A9G and Neo6m modules to the Raspberry Pi 4 and ensuring they work together via UART required careful configuration. There is no so much information about connecting this GSM module to RPi4. I have tried to use SIM900, SIM800 - it did not work with danish GPRS coverage in my case. Example how to set AT commands to set GSM module work with mobile internet connection you can take from my GitHub
Finally
Physically it looks like
As you see, I fixed it on the top of battery. I gave got an idea to embed it into common wiring as extra power source for the cases when car engine starts, it evokes drop down of voltage in car circuit. So if connect UPS module in right way, we can stabilize our current supply of RPi4 and it has to work without troubles.You might notice a voltage converter on the right sight of this photo. I use it to turn current of 12V from the car's OBDII socket plug into 5V and supply GSM and GPS modules with it.
I expected it would be enough of power to supply RPi4 board, but seller gave me wrong information, it does not have 5A current in the end as it had been guaranteed.
Thus solution was to connect RPi4 to other power source.
And finally, you can check it out how my App works being in car on my youtube video
Car has not been damaged. It had got a couple of battery discharging, as was mentioned about its possibility on that book above.
Couple things to enhance project
if I decide to improve it, I will switch it to Qt and use C++ as programming language.It going to give us more performance, save CPU and memory sources.The things to add are limited only with our fantasy: from Map navigation to embedding self diagnostic tools.I hope, I have inspired you, dear reader to learn and do then me.
Comments
Please log in or sign up to comment.