To be used with my RPi hat with voltage regulator and off switch.
pin 2 - 5v
pin 3 - GPIO 2 - SDA
pin 4 - 5v
pin 5 - GPIO 3 - SCL
pin 6 - GND
pin 7 - GPIO 4 - SQW
pin 9 - GND
pin 14 - GND
pin 20 - GND
pin 25 - GND
pin 30 - GND
pin 34 - GND
pin 39 - GND
pin 40 - GPIO21 - SLEEP
*in the earlier versions, GNDs are not connected to the pins, instead the screws ground the hat to the pi and the screen)
the pinout can be changed by removing the shunt on the corresponding pin, and adding a jumper wire to the pin of choice. the same shunts can be used to enable/disable features.
-
before starting, make sure that the voltage adjuster trim pot is all the way counter clock wise, give it around 25 turns just to be sure, this will make sure that the starting voltage is fixed at 5. and not at 12. as this can damage the RTC module.
-
then give it 12v on the Batt, 12v on the IGN, and ground on the GND, once it starts, check voltage between 5v header pin and any ground, (best to use the pads on the mounting holes as a clean ground) to make sure the output voltage is within spec (set it to 5.15 if pi shows the lightning icon). if so, short the 5v header pins with the shunt jumber which would then power on the PI.
ive made a image for a full PiDash rom by Alex Bartonek, you can just download, extract, and flash to your SD card using "Raspberry Pi Imager", this rom is a stripped out version of dietpi for use as a dash on in car installs, and boots in around 20 seconds.
to flash the rom,
download link for the rom.
https://drive.google.com/file/d/1LwtBL5jEeM_5KxnBrZM2rW1z33K-vyiC/view?usp=sharing
- after downloading, extract the image to any folder
- install Raspberry Pi Imager,
download link https://www.raspberrypi.org/software/ - open it
- click "choose OS"
- scroll down and select "use custom"
- select the image you just downloaded in step 0
- inset SD card in the computer, or use a SD card USB adapter.
- click "choose SD card" and select the SD card you want to install the image on.
- select "write" to write image to the SD card.
- once the write is complete, insert the SD card back in the pi, power it on and youre all set.
- set your RTC time with following command in terminal (sudo timedatectl set-time 'YYYY-MM-DD HH:MM:SS') for example ('sudo timedatectl set-time '2021-05-26 15:45:20') without the (,) and hit enter. Side note: if you open the terminal and click the up arrow on the keyboard twice, the command will come up, and you can just edit it
- to connect to internet, open updater on the desktop, and click "enable networking", it can take a couple of minutes, and if it doesnt work, restart and try the step 12 again.
point to note: this has a shutdown feature, as a result if the hat is not plugged in, and the shunt for "off" is not installed, the pi with shutdown before it even fully boots up, for bench testing purposes, you can install a jumper between pin 40 and gnd (short pin 40 to gnd), to stop the pi from shutting down**
*SD card has to be minimum 8gb
and you wouldnt need to do anything with the code, the rom has real time clock, pi on, off script, and tunerstudio already installed and set to start at boot.
all credits to alex bartonek for putting in the time to create this rom,
https://www.bartonekdragracing.com/encyclopedia/pidash-knowledge-base/
https://www.facebook.com/PiDashByAB
follow his work, and find out about more features imbedded within the rom such as file sharing and backups etc.
alternatively you can build it manually on a rom of your chioce
-
Clone this repo:
git clone https://github.com/Howchoo/pi-power-button.git
-
Run the setup script:
./pi-power-button/script/install
***if the git clone command doesnt work, run these
- sudo apt update
- sudo apt install git
-
edit script by 'sudo nano /usr/local/bin/listen-for-shutdown.py'
-
replace the text with
#!/usr/bin/env python
import RPi.GPIO as GPIO import subprocess import time
GPIO.setmode(GPIO.BCM) GPIO.setup(21, GPIO.IN, pull_up_down=GPIO.PUD_UP)
while GPIO.input(21) == 0: time.sleep(2)
subprocess.call(['sh', './home/pi/stopts.sh']) time.sleep(8)
subprocess.call(['shutdown', '-h', 'now'], shell=False)
-
Once the text has been replaced, click CTRL+X, Y, enter to save.
-
test script using 'sudo /etc/init.d/listen-for-shutdown.sh start'
If you need to uninstall the power button script in order to use GPIO21 for another project or something:
- Run the uninstall script:
./pi-power-button/script/uninstall
- Make sure that the shunts are installed on SDA, SCL, and SQW
use this guide as its actually much better. https://learn.adafruit.com/adding-a-real-time-clock-to-raspberry-pi/set-up-and-test-i2c
alternatively.
-
Type in [sudo raspi-config] set up raspberry pi and prepare to enable i2c interface, alternatively you can go to start > prefference > raspberry pi configuration. and enable it from there.
-
type "sudo nano /boot/config.txt" and at the end, add the following
dtoverlay=i2c-rtc,ds1307
save by CTRL+O, ENTER, CTRL+X
-
sudo reboot,
-
once its back on, type "sudo i2cdetect -y 1" you should see a table with UU where 68 previously was, this means the module is being used, if you dont, check to see that you are editing the right file, as in dietpi etc you will need to edit "sudo nano /dietpi/config.txt" instead.
-
now disable the fake clock by "sudo apt-get -y remove fake-hwclock sudo update-rc.d -f fake-hwclock remove sudo systemctl disable fake-hwclock"
-
with fake clock off. run "sudo nano /lib/udev/hwclock-set", and comment the following lines out by adding a # behind them.
#if [ -e /run/systemd/system ] ; then #exit 0 #fi #/sbin/hwclock --rtc=$dev --systz --badyear #/sbin/hwclock --rtc=$dev --systz
save by CTRL+O, ENTER, CTRL+X
-
sync time on the pi by connecting it to a network, once the time is sync, check time by writing "date" or "sudo hwclock -r" if time is correct, write "sudo hwclock -w" to save the time on the RTC.
-
if the time is in a different region, write "sudo hwclock -l", if this time is correct write "sudo hwclock -l -w" to save it.
power off script is based on howchoo power button and Mike Armstrongs work. https://howchoo.com/g/mwnlytk3zmm/how-to-add-a-power-button-to-your-raspberry-pi
Digi-Key Part Number: 1528-1385-ND.
Manufacturer Part Number 0766500075 (for kit)
Digi-Key Part Number 23-0766500075-ND (for kit)
*Digi-Key Part Number if you want to buy seperately, Receptacle WM3701-ND, terminals WM2501-ND
RS-components part numbers (seperate parts), Receptacle 484-1754, terminals 172-9134
Manufacturer Part Number STC02SYAN
Digi-Key Part Number S9000-ND
RS-component part number 251-8503
Manufacturer Part Number 3034TR
Digi-Key Part Number 36-3034TR-ND
RS-component part number 185-4652