Demo Projects![]() Carberry Info Panel 2.0Update of Carberry Info Panel 1.0Attention! This is demo projects and is not supposed to be a ready solution. It has only testing purposal to understand Carberry possibities.Any improvement or additional feature must be added editing your own application code.
IntroBased on original project Car Engine Parameters Visualization, we developed a newer version of this project in order to work with the new firmware version of Carberry. Differences between previous version:
How we did thisHardware Necessary
Raspberry Software Limit - QT5 SolutionThe first problem in order to draw with Raspberry some gauges was the hardware acceleration, in fact at the moment with none of OS available for Raspberry is possible to get a Desktop Session Hardware Accelerated, that means that all graphic calculations that should be manage by SoC GPU are managed by SoC CPU with an higher resource usage and a worst result. A gauge that moves slowly or lagged is useless... After tons of web searches and tests:
I found that the UNIQUE solution, for the moment, to allow to an application to use the Raspberry Hardware Acceleration was to use the QT5 programming language. How to install QT5 on RaspberryQT5 unfortunately is not available on Raspbian repository, and for this reason must be built manually. There are two ways to do that:
Remember that Raspbian must be modified in order to work with Carberry, you could do that following this guide: http://www.carberry.it/wiki/carberry:rpi:linux:distrib:raspbian_yourself How to draw Gauges - QMLAfter 9 hours we have our Raspberry with QT5 successfully installed and we are ready to create our QT5 application. Now I don't know nothing about QT programming language, I'm a web designer and I know "only": HTML, CSS3, JavaScript, PHP and use a programming language like QT5 that's very similar to C++ it's not so easy. For this reason I decided to use just QML (Qt Meta Language) that has a syntax very close to JavaScript and allows to create simple Graphic UI. To create some gauges I used a ready online project: https://github.com/lemirep/QtQuickCarGauges But some modifications were necessary because the source code renders a canvas bar each time that the needle moves up or down, this feature reduces dramatically the Raspberry performance. So I decided to comment all the parts of the source code related to this canvas render, you could find my ready Project at bottom of this Paragraph. Carberry OBD Info Panel Project draws 5 gauges:
Carberry OBD Info Panel Project Download: Carberry - OBD Info Panel - QT Project - v2.0 How to update gauge valueIn order to update the gauge value we need to communicate with the Carberry Socket. I'm not able to communicate with the Carberry Socket directly through QT5 so I used the possibility of QML to integrate also JavaScript in order to execute Ajax calls to a PHP script, written by me, that communicates with the socket and returns a JSON output. To run PHP I installed NGINX + PHP-FPM that reduces at minimum the use of CPU.
![]() In the main.qml file we can find 2 javascript functions: function update_speed_rpm_usage() { call_1_status = "false"; var action = "update_speed_rpm_usage"; var doc = new XMLHttpRequest(); var params = "action="+ action +"&method=json"; doc.onreadystatechange = function() { if (doc.readyState === XMLHttpRequest.DONE) { call_1_status = "true"; //console.log("chiamata 1 completata"); var obj = JSON.parse(doc.responseText); if(obj.speed != undefined && obj.rpm != undefined && obj.engine_usage != undefined) { speed_value = obj.speed; rpm_value = parseFloat(obj.rpm); usage_value = obj.engine_usage; } if(obj.error != '') { error_text = obj.error; show_error = true; } else { show_error = false; } } } doc.open("post", url, true); doc.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); doc.setRequestHeader("Content-Encoding", "UTF-8"); doc.setRequestHeader("Content-length", params.length); doc.setRequestHeader("Connection", "close"); doc.send(params); } function update_air_fuel() { call_2_status = "false"; var action = "update_air_fuel"; var doc = new XMLHttpRequest(); var params = "action="+ action +"&method=json"; doc.onreadystatechange = function() { if (doc.readyState === XMLHttpRequest.DONE) { call_2_status = "true"; //console.log("chiamata 2 completata"); var obj = JSON.parse(doc.responseText); if(obj.fuel_level != undefined && obj.air_temp != undefined) { fuel_value = parseFloat(obj.fuel_level); air_value = parseFloat(obj.air_temp); } if(obj.error != '') { error_text = obj.error; show_error = true; } else { show_error = false; } } } doc.open("post", url, true); doc.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); doc.setRequestHeader("Content-Encoding", "UTF-8"); doc.setRequestHeader("Content-length", params.length); doc.setRequestHeader("Connection", "close"); doc.send(params); } Called by 2 timers that work at different speed:
Timer { interval: 100 repeat: true running: true onTriggered: { if(parent.call_1_status == "true") { parent.update_speed_rpm_usage(); } } } The first timer calls the function "update_speed_rpm_usage" every 100ms because these information must be updated as fast as possible.The function calls a PHP called ajax_commands.php that returns a JSON output with the value of SPEED and RPM. Timer { interval: 5000 repeat: true running: true onTriggered: { if(parent.call_2_status == "true") { parent.update_air_fuel(); } } } The second timer calls the function "update_air_fuel" every 5 seconds because are information that don’t require a fast update. The function calls a PHP called ajax_commands.php that returns a JSON output with the value of AIR TEMPERATURE and FUEL LEVEL. How the socket communication worksAs previously said the communication between QML and the socket is managed by PHP, that opens a connection to 127.0.0.1 at the port 7070 where the Carberry daemon runs, sends the right command, as described in the wiki http://www.carberry.it/wiki/carberry:cmds:subsys:obd:query_new, read the value, return the value in JSON format. How to setup Carberry in order to communicate with the carThe new way to communicate with OBD ports is a bit more tricky but is more complete and allows any kind of communication with car OBD port. Steps necessary:
Canbus 11bit working example
Canbus 29bit working example
The PHP script is available here: Carberry - OBD Info Panel - PHP Script - v2.0 Compile and RunTo run the QML application we need just to copy the project folder to "/home/pi" Enter in the directory cd /home/pi/Carberry_InfoPanel Run QMAKE qmake Build the application make To run the application ./Carberry_InfoPanel To run the application on boot we need to edit the /etc/rc.local file sudo nano /etc/rc.local Add before "exit 0" /home/pi/Carberry_InfoPanel/Carberry_InfoPanel The PHP script must be placed in the Webserver Document Root (by default) is /var/www/html OBD Connections
OBD Pinout
The OBD connections can be found at this link: http://www.carberry.it/wiki/carberry:hardware:parallel_connection DownloadsCarberry OBD Info Panel Ready Image (8GB SD required): Carberry - OBD Info Panel - V2.0
|