NEVER connect an ignition feed directly to a Raspberry Pi GPIO Pin. You will destroy the Pi.
Shutting down an application while it is writing to disk can corrupt the files on the disk. Although I often shut down SDC by simply removing the power on my test bench without suffering any corruption, in this scenario I can easily re-format the sdcard if it becomes corrupted. With the device installed behind your dashboard this is more of an operation so you should ideally implement this proper shutdown process for best reliability and functionality. An alternative is to turn off Data Logging and accept that no settings will be saved when you turn off the power. In the as-downloaded configuration, datalogging is off by default.
Controlled Shutdown
SDC accesses the SD card while running, primarily for datalogging. It writes a row to the datalog every time the selected datasource indicates it should do so. For canbus data sources that is about 25 times per second. For other sources (speeduino Serial for example) it is dependent upon other settings such as the maximum datalogging throttle rate, and the limit imposed by the speeduino firmware.
There are also certain settings from the SDC.ini file that may be updated while the application is running (such as the last displayed page). These are held in memory and are written to disk when the application shuts down. Obviously if you simply cut the power, these settings won’t be saved.
Controlled shutdown requires the use of an SDC I/O hat or other similar implementation.
Proper Application Termination
In order to get a proper clean shutdown with everything updated properly and all log files properly closed it is necessary to implement a delayed shutdown process, which removes the power from the device only after the software has performed appropriate shutdown operations. In order to achieve this you must power your devices through a secondary controlled shutdown board which holds the power on for a short period until shutdown is completed. I have mine configured for about 2 seconds.
I have small stock of delayed shutdown boards on my store from time to time; you can find them here:
https://www.v8creations.com/sdc/23-sdc-controlled-shutdown-power-module.html
The shutdown board you use may require either a ground trigger or a +12v trigger. The board above works with a +12v trigger, and this means you can connect the ignition feed directly to it to control it. This is simpler than a ground trigger as you will also need that same 12v trigger to direct into the I/O hat to control the shutdown.
As you can see, they don’t cost very much and are a worthwhile addition in my opinion. This relay board has some quiescent current draw but it is very very small.
To use this board, you should wire it as follows:
- Connect a constant positive supply to the relay’s common terminal
- Connect the Pi’s power input to the normally open terminal. This terminal will be connected to the common pin when the relay is activated, hence passing the power supply to your Pi.
- Connect constant +12v and GND to the relay board’s power supply terminals
- Connect a +12v ignition feed to the trigger pin of the relay board
- Set the relay’s delay to at least 2 seconds.
The constant supply voltage level you connect through the board’s relay common terminal is dependent upon how you have chosen to power your Pi. Pi’s are powered from a 5v supply. My I/O hat provides a 5v regulator allowing you to connect your vehicle’s 12v supply to it. Therefore if using my I/O hat you would use a nominal 12v feed through the delay board and into the hat, which in turn powers the Pi (and the screen if you bought it from me).
You will also need to connect an ignition feed to a GPIO pin (the default for this is GPIO13). My SDC I/O Hat has an IGN input for this purpose with appropriate circuitry to electrically isolate the ignition connection from the 3.3v that is needed to connect to the GPIO Pin, and it is hard wired to GPIO13.
You should then configure the SDC ini file so that it contains the following entry:
[buttons]
shutdownbutton=13.pd,shutdown
Where the number “13” is the GPIO number you want to use as the input. My I/O hat is fixed at pin 13 as above.
This pin is configured as a pulldown, and internally the software is looking for the pin to be low to trigger the action. This means that you must hold the pin high with 3.3v to prevent shutdown. If you ground the pin, or make it open circuit, then SDC will shut down immediately.
How it Works
When you turn on the ignition, the relay board will be immediately triggered to turn on its relay as it is constantly powered. This connects the power supply to the Pi causing it to boot. The delay relay will stay on until the key is turned off, at which point the relay board will hold the power on until the timeout you set expires.
In parallel, turning off the ignition key also removes the 12v supply from the “IGN” input on the SDC I/O hat. The hat only holds the pin high when you supply 12v to IGN, so when the power is removed the SDC Hat’s opto isolator disconnects the 3.3v from pin 13. This activates the internal pulldown, putting the pin in a low state and activating the shutdown action that is defined above.
When SDC shuts down it displays its boot screen. 2 seconds or so later (whatever your delay board time is set to) power will go off.
I power all of my devices through a single relay board, including the screens, as this gives a nice looking key-off process where the dials disappear and the manufacturers logo appears on screen for 2 seconds and then the screens go blank.
Controlled Shutdown of Canbus Devices
If you are using a canbus with your installation, then you will likely have more than one device that needs to be safely shut down before the power is removed (for example one cluster screen and one auxiliary control screen). When you implement the shutdown procedure above using a SHUTDOWN touch action, if the device receiving the instruction is configured with a datamode that includes support for sending canbus messages then it will automatically broadcast the shutdown command to all other devices on the bus, using the Canbus Controller Id. The other SDC devices will react by performing the same safe shutdown process.
For further details on canbus support, see the Canbus Section