10-19-2019, 09:42 PM
(This post was last modified: 10-19-2019, 09:48 PM by frankpintosr.)
(08-11-2019, 11:41 AM)tremers Wrote: Thanks skrimo and Grabber for this post on the 3 relay solution.
I was able to do the build with only the normal confusion in regard to GPIO numbers and pin outs, however this is all sorted - just check that you follow the diagram and Grabber's detailed notes.
Just a number of observations.
There was confusion over the use of the 2 scripts mentioned in this forum.
1. relay.py
This python script has one function and that is to arm the delay relay so that when the PI shuts down the relay will start its timer and then turn power off.
2. switch.sh
This bash script has four functions:
a. it arms the delay relay - hence if you use this script you don't need to run the relay.py script also.
i.e. the channel in relay.py is the equivalent of GPIOpin2 in switch.sh
b. to control KODI playback and blank the screen when the Accessories switch is turned off.
c. to shutdown the pi when the the accessories has been off for a number of minutes (given by the shutdown delay)
d. to resume playback in KODI and turn the screen back on.
Debugging Hardware IO
Lets say that you have used GPIOpin1=23 (Pin16) and GPIOpin2=24 (Pin18) for connections to the 12V and 5V relays.
In switch.sh GPIOPin1 is setup as an input with the following 2 commands:
Notice that I substituted the number 23 where the script uses that variable $GPIOpin1echo "23" > /sys/class/gpio/export echo "in" > /sys/class/gpio/gpio23/direction
It is possible to debug using simple commands to see what is going on.
For example to see if the pi is receiving the correct signal that the ACC is on or off then even if your script is running you can enter into a terminal the following:
This command will return 0 or 1,cat /sys/class/gpio/gpio23/value
0 means the ACC is on and
1 means it's off. If you get an error then run the 2 commands above to set the GPIO as input.
Similarly you can check if relay.ph or switch.sh actually ran at startup and has armed the delay relay.
cat /sys/class/gpio/gpio24/value
if this command return "0" then the delay relay is not armed. This could mean that the script did not start or the GPIO was not configured etc.
You can also manually arm/disarm the switch from the terminal and observe the LED's on the delay relay.
The above 2 commands only needs to be done once after a rebootecho "24" > /sys/class/gpio/export echo "out" > /sys/class/gpio/gpio24/direction
Will arm the relay (LED should light up and stay lit)echo "1" > /sys/class/gpio/gpio24/value
Will start the relay countdown (LED should flash) and then the LED will go out after the timeout delay trigger has expired.echo "0" > /sys/class/gpio/gpio24/value
You can do these tests without needing to turn on/off the accessories, however so the pi does not experience a power off keep Accessories on!
Controlling the Screen
Switch.sh has the ability to control the screen, however I discovered that depending on the hardware screen the provided default actions do not work.
I have discovered 3 Ways to turn screen off/on
# Offical PI screen echo 1 > /sys/class/backlight/rpi_backlight/bl_power #turns off screen back light --or-- # Another type of screen vcgencmd display_power 0 #--my screen-- xset s activate # uses the screen saver to display a blank screen
Ways to turn screen on
# Offical PI screen echo 0 > /sys/class/backlight/rpi_backlight/bl_power #turns on screen back light --or-- # Another type of screen vcgencmd display_power 1 #--my screen-- xset s reset
Simply edit your switch.sh file to match your hardware.
But there's more, I discovered that depending on the your hardware the way you start switch.sh can make a difference.
For example: If you have an Official PI screen or the vcgencmd compatible one, you can use rc.local (as documented on this forum) to start the script at boot up.
An alternate is to use crontab (See https://www.raspberrypi.org/documentatio...ge/cron.md).
However for my hardware I had to use xset to control the screen which did not support disabling the backlight.
(note: I installed xscreensaver but I'm not sure if its required. sudo apt-get install xscreensaver)
When I tested the script it worked fine, however my attempts at using rc.local or crontab to start it during boot up did not.
Using xset requires that the desktop be present and the script must be run in the users display context.
I solved this by:
While I could have skipped relay.sh, the time taken to startup to the desktop takes longer before the delay relay is armed.
- start relay.ph using rc.local so that the delay relay is armed as earlier as possible, and then
- start script.sh via desktop auto start.
Desktop Auto start
To start a process during desktop startup, using the terminal create a file in the directory ".config/autostart" called.desktop
This it myfile: switch.desktop
[Desktop Entry] Encoding=UTF-8 Type=Application Name=Switch Autostart Comment= NoDisplay=true Exec=sh -c '/home/pi/relay/switchstart.sh' StartupNotify=false NotShowIn=GNOME;KDE;XFCE;
The start file switchstart.sh:
#!/bin/bash sudo /home/pi/relay/switch.sh &
I was not sure how to use sudo start in the auto start file so used this simple bootstrap method. Sudo is requried to get the correct permissions to set the input port.
References:
https://raspberrypi.stackexchange.com/qu...an-stretch
https://www.raspberrypi.org/forums/viewt...p?p=931067
Hope that the above information assists those that have taken similar steps to use this 3 relay solution to power our PI's.
I am happy to say that my installation is in place and working a treat!
Cheers and good luck!
(10-18-2019, 12:02 PM)Robazz Wrote:(09-23-2019, 08:03 PM)Daniel_BlueWave Wrote: Author of this solution is @skrimo
Only post regarding solution improvement will be accepted here (and whatever posts from @skrimo)
All others, not related post, should be placed here:
https://bluewavestudio.io/community/showthread.php?tid=797&pid=4739#pid4739
Otherwise they will be removed.
Thank you for understanding.
Starting point:
https://bluewavestudio.io/community/show...hp?tid=797
What has happened to all of the instructions and links that skrimo had previously posted, the links above go nowhere?
Thanks
@bluewave The thread seems to be missing! Thread ID 797
(08-09-2019, 01:42 PM)Grabber Wrote: I have cleaned up the instructions based on the updated wiring diagram and video skrimo posted. I did this because I was confused after reading the instructions. But after seeing the video I came to the conclusion that "before" and "after" were being used instead of the words "splice" or "split". Hey, its all good skrimo. I think I got it figured out and will be putting it together today on the bench.
1) ACC wire
- Splice ACC wire - connect one lead to 12v Relay #1 at pin 85 and connect second lead to 12v Relay #2 at pin 85
2) 12v Constant BAT+
- Splice 12v Constant BAT+ - connect one lead to 12v Relay #1 at pin 87 and connect second lead to 5v Delay Relay COM
3) 5V Delay Relay NO
- Splice lead from 5V Delay Relay NO pin - connect one lead to 12v Relay #1 at pin 30 and connect second lead to 12v to 5v Converter at 12v IN
4) Main Ground (GND)
- Connect 12v Relay #1 pin 86, 12v Relay #2 pin 86, and 12v to 5v Converter to Main Ground GND
5) Raspberry Pi to 5V Delay Relay
- Connect GPIO 5v pin 2 or 4 to 5V Delay Relay V+
- GPIO GND pin (6,9,14,20,25,30,34, or 39) I will use GPIO GND pin 6. Connect GPIO GND pin 6 to 5V Delay Relay GND
- GPIO pin (x) connect to 5V Delay Relay IN
6) Rasberry Pi to 12v Relay #2
- Connect GPIO 3.3v pin 17 to 12v Relay #2 at pin 30
- Conncet GPIO pin 23 to 12v Relay #2 at pin 87a
7) Wire up power connections from 12v to 5v Converter out to Raspberry Pi and Monitor as desired.
If you use different GPIO pins to connect to the 5v Delay Relay or 12v Relay #2 you need to modify the scripts to reflect the pins you used.
I know I am breaking the rule of this thread, but the original thread seems to be missing. So...
I am working on building this circuit for my setup. Unfortunately, due to my limited knowledge, I am not sure what connections to make using the delay relay I bought. I am attaching an image here. Can anyone please help me out please?