RealDash, Raspberry pi, raspberry screen and Bluetooth

Ok so I have finally settled on doing this project using
RealDash to read all the standard obd 2 data. Then I’ll use a raspberry pi to control the touchscreen using android os.

I have found a box that converts digital and analog inputs into data the raspberry pi can read to allow the data to be used in RealDash. This box connects via Bluetooth to the pi for the inputs.

Could also be used with a tablet and leave out the pi and the pi screen but I have yet to find a tablet I like that I can flush mount and still get to the controls for power and all that.

Now one of my questions would be the safe shutdown of the raspberry pi and the os. This I have no idea about. I would like for there to be a way something sees the voltage drop or the key off and then it initiates the shutdown somehow.

I’m still not exactly sure how all this works as I have yet to install android in the pi as I am waiting on the box to come in for the external inputs so I can even test it.

But if someone could lead me in the starting direction that would be awesome.

Thanks.

sudo nano /usr/local/bin/ignition_shutdown.py

#!/usr/bin/env python3
import time
import subprocess
import RPi.GPIO as GPIO

Pick a GPIO you wired to the optocoupler output

IGN_PIN = 17 # BCM numbering (GPIO17)
OFF_DELAY_SEC = 8 # wait after ignition off (debounce / brief key cycling)
POLL_SEC = 0.1

def shutdown_now():
# Close RealDash (adjust process name if yours differs)
subprocess.call([“pkill”, “-f”, “realdash”])
time.sleep(1)
subprocess.call([“shutdown”, “-h”, “now”])

def main():
GPIO.setmode(GPIO.BCM)
# Optocoupler output is typically OPEN COLLECTOR to GND, so use pull-up
GPIO.setup(IGN_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP)

# Define ON state:
# If opto pulls pin LOW when ignition is ON, set ON_WHEN_LOW = True.
# If your wiring makes it HIGH when ON, set to False.
ON_WHEN_LOW = True

def ignition_is_on():
    val = GPIO.input(IGN_PIN)
    return (val == GPIO.LOW) if ON_WHEN_LOW else (val == GPIO.HIGH)

try:
    # Wait until ignition is ON before monitoring OFF events
    while not ignition_is_on():
        time.sleep(0.5)

    while True:
        if not ignition_is_on():
            # ignition just went off -> start timer
            t0 = time.time()
            while time.time() - t0 < OFF_DELAY_SEC:
                # If ignition comes back during delay, cancel shutdown
                if ignition_is_on():
                    break
                time.sleep(POLL_SEC)
            else:
                # Stayed OFF for full delay -> shutdown
                shutdown_now()
                return

        time.sleep(POLL_SEC)

finally:
    GPIO.cleanup()

if name == “main”:
main()

sudo chmod +x /usr/local/bin/ignition_shutdown.py

sudo nano /etc/systemd/system/ignition-shutdown.service

[Unit]
Description=Ignition OFF → Safe shutdown (RealDash + Pi)
After=multi-user.target

[Service]
Type=simple
ExecStart=/usr/local/bin/ignition_shutdown.py
Restart=always
RestartSec=2

[Install]
WantedBy=multi-user.target

sudo systemctl daemon-reload
sudo systemctl enable ignition-shutdown.service
sudo systemctl start ignition-shutdown.service
sudo systemctl status ignition-shutdown.service

2 Likes