Jump to content

Shutdown Button for OrangePiZero


rlsten

Recommended Posts

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
 

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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)

 

Link to comment
Share on other sites

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

Image result for orange pi zero pins

 

 

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

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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 :-)

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines