Forum
  • Search
  • Member List
  • Calendar
Hello There, Guest! Login Register — Login with Facebook

[PROBLEM] Argon One case with 'power' button - config script fails to install
Thank you for your donation

Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Threaded Mode | Linear Mode
Problem: Argon One case with 'power' button - config script fails to install
5th Nov, 2020, 12:57 AM
Post: #9
Leodymium Offline
Registered
Posts: 1
Joined: Nov 2020
Reputation: 0
RE: Argon One case with 'power' button - config script fails to install
Hello,

I am trying to install a power switch on a RP4 device and here is the list of the steps I took manually, if you wish to have a go. It is based on various instructions, mainly here to setup the switch and here to install the library. I have the switch detected and I can access it by the python console but I am still looking at an efficient way to start the script during the boot sequence, as systemd does not seem to work.
Anyway, to install the tool you need to access GPIO from python scripts you can do the following. Start by the packages:

Terminal

sudo apt-get install python-dev python3-dev
sudo apt-get install mercurial
sudo apt-get install python-pip python3-pip
sudo apt-get install python3-setuptools
sudo apt-get install gcc-arm-linux-gnueabihf

Then you should be able to install the GPIO library. The version in the repository does not work for the raspberry pi versions higher than 1 so you need to install from the source repo:

Terminal

python3 -m pip install wheel
python3 -m pip install hg+http://hg.code.sf.net/p/raspberry-gpio-python/code#egg=RPi.GPIO

Apparently there is a kernel bug that prevents accessing the GPIO library without being root (see here and here), so you need to create a rule.d config:

Quote:Create /etc/udev/rules.d/90-gpio.rules with:

KERNEL=="gpiomem", OWNER="root", GROUP="gpio"

Create the group itself and assign it to an existing user "pi":

Then add a new group to manage the GPIO port and add the user to it:

Terminal

sudo groupadd -f --system gpio
sudo usermod -a -G gpio $USER

Note that this worked to some extent for me but I still encountered some issues when not using root, so I still use sudo for all the rest.

Once you have these done you can write your python script to switch off the device, I got mine from there with some modifications to make it operate on the correct GPIO pin (pin 5, or equivalently GPIO3):

Code:
#!/usr/bin/env python3
import signal
import sys
import os
import RPi.GPIO as GPIO
BUTTON_GPIO = 3

def signal_handler(sig, frame):
    GPIO.cleanup()
    sys.exit(0)

def button_pressed_callback(channel):
    print("Button pressed!")
    os.system('poweroff')

if __name__ == '__main__':
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(BUTTON_GPIO, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    GPIO.add_event_detect(BUTTON_GPIO, GPIO.FALLING,
            callback=button_pressed_callback, bouncetime=100)
    signal.signal(signal.SIGINT, signal_handler)
    signal.pause()

When running this code from the terminal, the power switch operated correctly and switched off the device. Using pin 5 also makes it possible to use the same switch to power up the RP4.

I only need to put this script in the boot sequence now, I will try init.r (there are some instructions here).

I hope this helps.

Just to update, init.d seems to be working, the steps are here (method 3).

Add a header to the file:

Code:
#!/usr/bin/env python3
# /etc/init.d/shutdown_interrupt.py
### BEGIN INIT INFO
# Provides:          shutdown_interrupt.py
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start shutdown daemon at boot time
# Description:       Enable to shutdown the RP4 using the switch on GPIO5-6.
### END INIT INFO
import signal
import sys
import os
import RPi.GPIO as GPIO
BUTTON_GPIO = 3

def signal_handler(sig, frame):
    GPIO.cleanup()
    sys.exit(0)

def button_pressed_callback(channel):
    print("Button pressed!")
    os.system('poweroff')

if __name__ == '__main__':
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(BUTTON_GPIO, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    GPIO.add_event_detect(BUTTON_GPIO, GPIO.FALLING,
            callback=button_pressed_callback, bouncetime=100)
    signal.signal(signal.SIGINT, signal_handler)
    signal.pause()

then save it at /etc/init.d/, make it accessible and update the system:

Terminal

sudo cp ./shutdown_interrupt.py /etc/init.d/
sudo chmod +x sample.py
sudo update-rc.d sample.py defaults

It is now working for me, I have a start/stop switch on my RP4 Smile happy times....
Find all posts by this user
Quote this message in a reply
« Next Oldest | Next Newest »
Post Reply 


Messages In This Thread
Argon One case with 'power' button - config script fails to install - Dave400 - 27th Dec, 2018, 11:15 PM
RE: Argon One case with 'power' button - config script fails to install - rikardo1979 - 28th Dec, 2018, 10:34 PM
RE: Argon One case with 'power' button - config script fails to install - Nachteule - 29th Dec, 2018, 12:48 AM
RE: Argon One case with 'power' button - config script fails to install - ikem - 14th Jun, 2020, 08:30 PM
RE: Argon One case with 'power' button - config script fails to install - Dave400 - 15th Jun, 2020, 06:19 PM
RE: Argon One case with 'power' button - config script fails to install - jorgeblat - 5th Jul, 2020, 05:30 PM
RE: Argon One case with 'power' button - config script fails to install - Dave400 - 29th Dec, 2018, 10:10 AM
RE: Argon One case with 'power' button - config script fails to install - Tayedore - 20th Dec, 2019, 11:26 AM
RE: Argon One case with 'power' button - config script fails to install - Leodymium - 5th Nov, 2020 12:57 AM
RE: Argon One case with 'power' button - config script fails to install - Thundersun - 17th Mar, 2021, 11:20 AM
RE: Argon One case with 'power' button - config script fails to install - s4r3k - 13th Nov, 2024, 04:20 AM

Possibly Related Threads...
Thread: Author Replies Views: Last Post
  [PROBLEM] Argon One M.2 Case Gpio Script Thundersun 3 6,087 21st Feb, 2024 03:33 AM
Last Post: barbarajameson

  • View a Printable Version
  • Send this Thread to a Friend
  • Subscribe to this thread
Forum Jump:

Current time: 1st Jul, 2025, 12:49 AM Powered By MyBB, © 2002-2025 MyBB Group.