Introduction: Fuelmanager
Fuelmanager is an integrated system that gives car owners more insights about their fuel consumption and fuel costs.
By installing a simple plug and play module and connecting it to your smartphone, you wil see lots of information about your fuel usage, fuel costs and even an overview of all recent routes you have driven.
Being based on an ESP32, Raspberry Pi 4 and an OBD2 bluetooth reader makes Fuelmanager cheap and easy to recreate and use.
Optionally you can use a HDMI Screen to see some real-time data while driving on the road.
In September 2020 I started at Howest Kortrijk in Belgium, there my Bachelors Degree adventure started. At the end of the 2nd semester we needed to implement everything we had learned so far in a 'project'. Because I really like cars and everything about them I started looking into projects with cars.
This is how Fuelmanager was born.
Supplies
- Raspberry Pi 4 (Min 4GB Ram)
- Micro SD Card (64GB Recommended)
- USB-C Car Charger
- 12v - 5V Buck converter (1A)
- OBD2 ELM327 Bluetooth Module
- HDMI LCD Display
- ESP32 DevKit Module
- HDMI Cable
- 5V Rotary Encoder
- WS218B RGB Led Strip
- NEO - N8M GPS Module
- Jumper Wiring
Step 1: Step 1 : Circuit and Components
This is the Circuit as it is currently configured in my software. As you see it is not that hard to replicate, the magic is in the software so all you need to do is connect the components like illustrated above.
Step 2: Setting Up Raspberry Pi 4 and Packages
1. Install the OS
Download Raspberry Pi Imager from https://www.raspberrypi.org/software/
And Flash Raspberry Pi OS with desktop and recommended software
2. Configure boot files on SD Card
- When the flashing is finished, take your SD Card out of your PC and reinsert it.
- You should see a disk named 'Boot' pop up in the disks folder of your PC, go ahead and open it
- Create an empty filed with no extension named 'ssh' to enable ssh functionality on the Raspberry Pi
- Locate and open the file cmdline.txt and add 'ip=169.254.10.1' at the end so we can connect later
3. Boot your Raspberry Pi
- Insert the SD card in the Raspberry Pi
- Connect your PC and the Raspberry Pi directly with an Ethernet cable
- Plug in the power supply of the Raspberry Pi
- Open a CMD or Terminal window and type 'ssh pi@169.254.10.1'
- The password is the default one: 'raspberry'
4. Configure Raspberry Pi OS
- With 'sudo raspi-config' choose option 3 -> Serial Port -> No -> Yes
- Choose option 5 and set your country, this is important for the wifi network we will create.
5. Configure Hostapd wireless acces point
Follow the tutorial on the Raspberry Pi site HERE but you can skip the Bridge part as we wont have internet access.
6. Install Database Server
- sudo apt install mariadb-server mariadb-client
- sudo mysql_secure_installation
- sudo mysql
- create user student@localhost identified by 'W8w00rd';
- flush privileges: 'grant all privileges on *.* to username@localhost;'
- flush privileges;
- exit;
7. Install RGB Led drivers if you want to use them
- curl -L http://coreelec.io/33 | bash
Step 3: Cloning Software
Clone the code from this GitHub Repo HERE
You will see 3 folders named: Backend, Frontend , Database
Now we need to set up a few more things:
- Go in the folder Backend and run this command:
- pip3 -r install requirements
- Go in the folder Databse and run this command:
- mysql -u student -p W8w00rd Fuelmanager.sql
- Go in the folder Frontend and execute following commands:
- sudo -i
- sudo apt install apache2
- sudo nano /etc/apache2/sites-available/000-default.conf
- Change 'DocumentRoot' to 'DocumentRoot/frontend'
- Save by CTRL+X and Y
- service apache2 restart
Step 4: Setting Up ESP32 and OBD2
For this step you will need the OBD2 Bluetooth Module and the ESP32.
The Software should work with any of the Bluetooth OBD2 modules you can find that are based on an ELM327. In the software.
The script automatically connects to the WiFi network that the Raspberry Pi 4 creates so it can Post all the data to our backend.
You can find the code below.
!IMPORTANT! Because we use both Bluetooth and WiFi, the software exceeds the limits of the on-board flash storage of the ESP32, we can fix this by changing our partition scheme:
in Arduino go to Tools -> Board -> Pick ESP32 Dev Module then go to
Tools -> Partition Scheme -> Pick Minimal Spiffs
If you have trouble connecting, try changing the "OBDII" parameter in ELM_PORT.connect("OBDII") to the mac address of the OBD2 Module, you can find that if you scan your bluetooth devices with a Smartphone.
Step 5: User Interface
This is the User Interface,
Here you can see the information that the Fuelmanager device collects and calculates
In the settings Page you can set the specifications of your vehicle.
Change the Fuel Price everytime you refuel to the actual price, the system remembers the history of the fuelprice
Step 6: Database Design
Measurement
Every second while you drive your vehicle with Fuelmanager installed, the ESP32 reads the OBD2 Data and parses it to readable data. That data is sent to the Flask API with a POST request.
When it arrives, the API stores it in the database together with the timestamp of the measurement and the data from the GPS module connected to the Raspberri Pi.
Tour
When you start to drive and the system reads that there is data in the Measurement table, it starts to process all the data in to relevant information and even creates a GPX file from the GPS data. Everything is then stored in the table Tour. If we want to display every tour we have driven we can just take the data out of the table Tour. When everything is calculated and stored, the Measurement table is cleared (truncated) so that we can start a new tour.
Vehicle
Here the parameters of the vehicle are stored, the most important variable is: Current_FuelPrice. Every time we want to see the costs, the current fuelprice of that day is used. That means that we need to set the Fuel Price every time we refuel and the price changes.
User
This is the data of your personal login, it stores your user information and your password hash.
Step 7: Automating Startup
Let the backend start whenever the Raspberry Pi powers up, thats whenever your vehicle starts the engine.
- sudo nano /etc/systemd/fuelmanager.service
- Paste the content below
- CTRX + X Y to save
- sudo systemctl enable fuelmanager.service
- sudo systemctl start fuelmanager.service
Step 8: 3D Print the Housings
You can choose to 3D Print my designs, I made an OBD2 housing that plugs in existing OBD2 adapter + the ESP32 and the Buck convertor.
The LCD housing is designed for a 7 Inch display and can store the Raspberry Pi behind it as well.