A digital dashboard using Python, a Raspberry Pi Zero W, and vehicle's On Board Diagnostics (OBD-II) Port.
My personal reason for creating this was because my car's fuel sensor broke. The cost for repair was astronomical, so I figured creating a program to calculate the fuel level and milage would be much cheaper.
Really, though, this is easily made into just a fun digital dashboard for anyone who wants to experiment with 'carputers.'
The real guts of this operation is in the OBD-II port of pretty much every car since the 1996. OBD (On Board Diagnostics) lets you access the car's computer and retrieve information from it. Scroll down to see my supplies list.
Every tenth of a second, the program queries the OBD port for the data I want through the obd python library. Dependencies are also listed below.
- Raspberry Pi Zero W (Note: if you use the display I chose, you will need the GPIO header pins on the Pi. It makes a very compact and easily mountable assembly.)
- Touchscreen Display of your choice. I like the hyperpixel4 from Pimoroni. (https://shop.pimoroni.com/products/hyperpixel-4?variant=12569485443155)
- Bluetooth ELM327 OBD-II Device (https://www.amazon.com/gp/product/B011NSX27A/ref=ppx_yo_dt_b_asin_title_o01_s00?ie=UTF8&psc=1)
- OBD-II port splitter (https://www.amazon.com/gp/product/B0711LGRGQ/ref=ppx_yo_dt_b_asin_title_o00_s00?ie=UTF8&psc=1)
- OBD-II to micro USB power supply (https://www.amazon.com/gp/product/B074M4XMBX/ref=ppx_yo_dt_b_asin_title_o00_s00?ie=UTF8&psc=1)
- OBD
pip install obd
- PyQt5
sudo apt-get install python3-pyqt5
- BlueZ Protocol
sudo apt-get install bluez
Run these commands in the terminal
curl -sSL https://get.pimoroni.com/hyperpixel4 | bash
hyperpixel4-rotate right
reboot
There have been some issues connecting the Raspberry Pi to ELM327 Devices. You might get the error this device has no services which can be used with Raspberry Pi
when trying to connect the adapter. Here is how to successfully set it up.
- Use the Bluetooth GUI or
bluetoothctl
sudo nano /etc/systemd/system/dbus-org.bluez.service
- Add/edit these lines
ExecStart=/usr/lib/bluetooth/bluetoothd -C ExecStartPost=/usr/bin/sdptool add SP
reboot
sudo rfcomm connect 0 <mac_address> 1
You can get the MAC Address by usingbluetoothctl
'sdevices
command.sudo rfcomm bind <mac_address> hci0
reboot
Many thanks to this website for helping me out with this part: https://www.lukinotes.com/2018/10/raspberry-pi-bluetooth-connection.html
That should do the trick for setting up bluetooth. To double check, try opening python in the terminal, and run this:
from obd import *
connection = obd.OBD()
connection.status()
It will return a string telling you the status of the connection. Go here for more information: https://python-obd.readthedocs.io/en/latest/Connections/.
NOTE: If you still have issues, try forgetting the bluetooth device and then reconnecting, and running the rfcomm bind
command again. I had some issues the first try around, but this worked for me.
Run these commands in the terminal
cd /home/pi/
mkdir Dashboard
cd Dashboard
git clone https://github.com/murrasource/digital_dash.git
chmod +x digital_dash.py
cp /home/pi/Dashboard/digital_dash.py /home/pi/Desktop
Now you can double click on the digital_dash.py folder on your Desktop to execute the file.
As previously stated, my motivation for coding this was because my gas sensor broke and I didn't want to pay for the $600-$800 repair. You will see in my code that I calculate the amount of fuel left in the tank based on some simple stoichiometry. This would be incredibly simple to replace with OBD-II queries if your car's gas sensor works. Take a look here (https://python-obd.readthedocs.io/en/latest/Command%20Tables/) for a list of all the different queries the OBD library supports.
Also, feel free to have fun and customize what you want for the logo.png file. It should autoscale to the correct fit. I did my car's name in Tesla font and it looks pretty cool, if I may say so myself. The example I have on the GitHub is the Lucid Motors logo from the company's Twitter post.
IMPORTANT TIP: To exit fullscreen, just double click the refill button.