rlsten Posted March 14, 2017 Posted March 14, 2017 Hi, I am trying to use an Orange Pi Zero as a headless music player running MPD connected to a USB DAC. I have everything set up and it works well, but now I would like to add a momentary push button connected to a gpio pin to enable me to soft shutdown the Orange Pi Zero. I've done the same with python scripts that I've found in the Rune Audio forum (which runs on Arch Linux) for the Raspberry Pi, but I understand that the Pi Zero pins are different from the Raspberry Pi. This is the script I used on the Raspberry Pi #!/usr/bin/env python2 import RPi.GPIO as GPIO import time import subprocess GPIO.setmode(GPIO.BOARD) #Select unused GPIO header pin to be used for shutdown InputPin = 13 # Set selected pin to input, and enable internal pull-up GPIO.setup(InputPin, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Wait for a button press on the selected pin (pin pulled to ground, falling edge) GPIO.wait_for_edge(InputPin, GPIO.FALLING) print "*** Netctl shutdown activated ***" subprocess.call("/sbin/shutdown now", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) Based on what I've read here, I've installed https://github.com/duxingkei33/orangepi_PC_gpio_pyH3 and successfully run an example. However, I am pretty much a noob when it comes to python and the underlying hardware involved in this, so I have run into a brick wall as to what to do next. Here are my questions: 1) Can I just assign say pin 26 to perform this function, or do I have to reassign that button in the fex file. If so, how do I do that? 2) Would I something like this to attach the button to pin 26 button = connector.gpio1p26 or is there some other way to identify it? and 3) How exactly do I write the shutdown function? Thanks very much, Rod
tkaiser Posted March 14, 2017 Posted March 14, 2017 Please do not always try to do things in the most complicated way possible (the Raspberry way). Just use the custom search link from my signature, enter 'acpid button' and configure the button accordingly.
rlsten Posted March 14, 2017 Author Posted March 14, 2017 20 minutes ago, tkaiser said: Please do not always try to do things in the most complicated way possible (the Raspberry way). Just use the custom search link from my signature, enter 'acpid button' and configure the button accordingly. Thanks, but please forgive me for needing a little more help. I follow the steps for acpid etc. from the banana pi forum, but the Orange Pi Zero doesn't have a power button. Don't I need to physically attach a button to a GPIO pin and then tell the Orange Pi Zero, through fex or something else, that that button will respond to the shutdown script?
tkaiser Posted March 14, 2017 Posted March 14, 2017 47 minutes ago, rlsten said: but the Orange Pi Zero doesn't have a power button Ah, correct. Totally forgot that. Ok, then the idea is as follows: You choose one of the pins from the 26 pin header to be used as button. The so called pin mappings can be seen here: http://linux-sunxi.org/Orange_Pi_Zero#Expansion_Port You have to ensure that this pin is not already in use, so for example (and without actually checking it) if you would choose pin 8 then it's PG06. Then the needed change would be to adjust (bin2fex/fex2bin) https://github.com/igorpecovnik/lib/blob/master/config/fex/orangepizero.fex#L812-L814 to [gpio_power_key] key_used = 1 key_io = port:PG06<6><default><default><0> and then follow the steps outlined in https://forum.armbian.com/index.php?/topic/872-beelink-x2-with-armbian-possible/&do=findComment&comment=11137 But I've to admit that I've no idea what has to happen electrically with PG06 (someone able to read schematic could answer this with regard to PL03 on the H3 boards that feature a power button)
Elliot Woods Posted July 30, 2017 Posted July 30, 2017 So it sounds like we can assign any GPIO as an ACPI power button using the fex configuration. In my case I'd like to assign GPIO 6 / Pin No 7 The only question then is, should the power switch be pull down or pull up. I.e. does closing the switch cause the GPIO to connect to +3.3V or to GND
martinayotte Posted July 30, 2017 Posted July 30, 2017 Normally, any GPIO Inputs use internal PullUps and the switches are pulling them to GND. But, about ACPI, I doubt the driver is included in a Legacy build. As a workaround, you can have an application that scan the button and then call "halt" when button is pressed.
prosprintCZ Posted August 21, 2017 Posted August 21, 2017 On my OPi Zero (v1.1) not function power button on pin PG06. But perfect function on PA07. Pin have active internal pull down rezistor and after conect to +3.3V (in a series with resistance 4K7 - preventatively) the device turns off.
martinayotte Posted August 21, 2017 Posted August 21, 2017 If UART1 is enabled, PG6 cannot be use as GPIO since it is UART1-TX.
prosprintCZ Posted August 21, 2017 Posted August 21, 2017 Of course you are right. I react mainly to this sample setup ;-) On 14. 3. 2017 at 5:33 PM, tkaiser said: [gpio_power_key] key_used = 1 key_io = port:PG06<6><default><default><0> I do not want, others to do dysfunctional experiments like me :-)
Recommended Posts