CarPC ignition to trigger power on / off on GPIO

edited October 2019 in General

Hi!

I'm very new to Raspberry Pi and Emteria. I have built a CarPC that will use Apple CarPlay with a CarlinKit dongle.
My goal is to turn the Pi on when I turn the ignition on, and shut it down safely when I turn the ignition off. As of now, the Pi is just always powered on.

I really have no clue on where to begin with this, other than connecting the ignition wire from my stereo wire harness onto the Pi's GPIOs.

I've read that I have to use sysfs to listen to the GPIO's, but how to write a script that can do the actions I want?

Comments

  • this is my thread on other forum and how I achived power on/off using cars ignition. the OS used is raspbian, but I think it should work on Emteria OS. all you actually need are two scripts that start running when RPI boots up. and offcourse harness.

    https://bluewavestudio.io/community/showthread.php?tid=797

    take a look, it looks complicated but trust me its fairlly simple and cheap

  • @Skrimo said:
    this is my thread on other forum and how I achived power on/off using cars ignition. the OS used is raspbian, but I think it should work on Emteria OS. all you actually need are two scripts that start running when RPI boots up. and offcourse harness.

    https://bluewavestudio.io/community/showthread.php?tid=797

    take a look, it looks complicated but trust me its fairlly simple and cheap

    "The specified thread does not exist."

  • There is no more that topic in that forum. Well, i saved this scripts to my computer. May be it will useful for somebody.

    First, make a file ignition.sh, consist of these strings:

    !/system/bin/sh

    Set up GPIO 4 and set to input

    echo "17" > /sys/class/gpio/export
    echo "in" > /sys/class/gpio/gpio17/direction

    Main code

    while :
    do
    #check status of ignition pin
    is=cat /sys/class/gpio/gpio17/value

    # Check if GPIO status is same as display
    if [ "$is" != "$(dumpsys power | grep -c "Display Power: state=ON")" ]
    then
    echo "diff"
    if [ x"$is" = x"0" ]
    then
    input keyevent 223
    fi
    if [ x"$is" = x"1" ]
    then
    input keyevent 224
    fi
    fi
    sleep 3
    done

    And, you should put this file to /data/data, and set permissions 777 to it.

    Next, make a file "start_ignition", consist of

    !/system/bin/sh

    BEGIN INIT INFO

    Exec: boot

    Type: permanent

    END INIT INFO

    /system/bin/sh /data/data/ignition.sh </dev/null >/dev/null 2>&1

    And you should put it to /data/init.d/

    You must connect GPIO4 to + 3.3V, when need to run, and to ground, when you need to shutdown.

    p.s. sorry for my english

    p.p.s. - I used this on Asus TinkerBoard with TinkerOS Android, it works, but need to change GPIO numbers.

    p.p.p.s:

    Original text from that forum was:

    /////////
    You can find my script here.

    http://adgj.se/ignition.sh

    I have put it under /data/data/

    Then under /data/init.d/ I have put this to start up the script
    http://adgj.se/start_ignition

    Hardware wise i have a relay that short circuits GPIO 4 with ground when not active.
    //////

Sign In or Register to comment.