This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Power ON/OFF button
#1
Hi All,
I'm trying to install a Power ON/OFF button using GPIO buttons, like on a RPI.
I followed ETAPRIME's process for RPI published on Youtube
https://www.youtube.com/watch?v=4nTuzIY0i3k

Powwer OFF works OK but the TB does not wake up when I press again the Switch.
Any idea of what's wrong?
Thanks for your help.

Hereunder the transcription of ETAPRIME's procedure to the TB:


1.  sudo apt-get install update
2.  sudo apt-get install python-dev
3.  sudo apt-get install python3-dev
4.  sudo apt-get install gcc
5.  sudo apt-get install python-pip

Next you need to get RPi.GPIO:
6. wget http://dlcdnet.asus.com/pub/ASUS/mb/Linux/Tinker_Board_2GB/GPIO_API_for_Python.zip
Uncompress the packages:
7.  unzip GPIO_API_for_Python.zip
move into the newly created directory (impossible as no directory has been apparently created):
8.  No action
install the module by doing:
9.  sudo python setup.py install
10.  sudo python3 setup.py install
creating a directory to hold your scripts:
11.  mkdir /home/linaro/scripts
call our script shutdown.py (it is written in python). Create and edit the script by doing:
12.  sudo nano /home/linaro/scripts/shutdown.py
#!/usr/bin/python
import ASUS.GPIO as GPIO
import time
import subprocess

# we will use the pin numbering to match the pins on the Pi, instead of the
# GPIO pin outs (makes it easier to keep track of things)

GPIO.setmode(GPIO.BOARD)  

# use the same pin that is used for the reset button (one button to rule them all!)
GPIO.setup(5, GPIO.IN, pull_up_down = GPIO.PUD_UP)  

oldButtonState1 = True

while True:
    #grab the current button state
    buttonState1 = GPIO.input(5)

    # check to see if button has been pushed
    if buttonState1 != oldButtonState1 and buttonState1 == False:
      subprocess.call("shutdown -h now", shell=True,
        stdout=subprocess.PIPE, stderr=subprocess.PIPE)
      oldButtonState1 = buttonState1

    time.sleep(.1)

Press CRTL X  Then Y      
Restart the Tinkerboard
13.  sudo reboot
configure our script to run at startup,
14.  sudo nano /etc/rc.local
Add the following to the file
sudo python /home/linaro/scripts/shutdown.py &

Press CRTL X  Then Y
Reply
#2
The script you quote issues a shutdown command to cleanly bring the system down. Very useful in case the console/usb locks up but the system is still running behind the scenes.

Turning back on requires hardware support. The Pi has this set up by default, apparently. I haven't tried it myself.

I haven't seen anything to suggest that this function is duplicated in the GPIO pins on the Tinkerboard.

Both the Tinker and the Pi also have a dedicated hardware reset button function, but nothing is soldered to the header on either board. see https://tinkerboarding.co.uk/forum/thread-281.html I have no idea if it will power the Tinker back up if power is still connected.

If all you want is a reboot anyway, you can change "shutdown -h now" to "shutdown -r now".
Reply
#3
(08-20-2017, 08:08 AM)BeauSlim Wrote: The script you quote issues a shutdown command to cleanly bring the system down.  Very useful in case the console/usb locks up but the system is still running behind the scenes.  

Turning back on requires hardware support.  The Pi has this set up by default, apparently.  I haven't tried it myself.

I haven't seen anything to suggest that this function is duplicated in the GPIO pins on the Tinkerboard.  

Both the Tinker and the Pi also have a dedicated hardware reset button function, but nothing is soldered to the header on either board.  see https://tinkerboarding.co.uk/forum/thread-281.html        I have no idea if it will power the Tinker back up if power is still connected.  

If all you want is a reboot anyway, you can change "shutdown -h now" to "shutdown -r now".
Hi BeauSlim,
Many thanks for your reply.
I already saw your mentionned post regarding the Tinker's hardware reset function close to HDMI output.
Functionaly, it shorts a 5VDC input from a pin to the other and it is still powered after "shutdown -h now".
It can be used to wake the TB back up

ETAPRIME's script surveys GPIO 3 (pin 5) and shuts the TB (or RPI) down when grounding is detected.
As you mention, grounding GPIO 3 also wakes the RPI back up when asleep. But not the TB.

My wish id to have the same button for ON and OFF.
TB's GPIO 3 being not hardware programmed fro waking up the board, it does not work with the RPI's GPIO 3 survey script.

Does anybody have a solution for using the same ON/OFF button with Tinkerboard?
Reply
#4
Hey,

Since I'm playing a little with kernel modules, and I'm locking up my Tinker sometimes, I decided to wire a switch to the power header.

It works as you would expect a power button to work. Hit once, and your OS should register it and ask if you want to shutdown or whatever. If in suspend state, it will wake. If in "off" state but the power hasn't been interrupted, it will boot. If your Tinker has locked up, hold for 4 or so seconds, and it will power off.

So, yeah, the easiest solution will definitely be to solder a header to the spot between the power input and HDMI and rig a (momentary) switch. I just grabbed a reset switch from an old PC case I had lurking in my basement.

It's kind of too bad that Asus didn't bother to solder the pins in.
Reply
#5
(08-21-2017, 11:18 PM)BeauSlim Wrote: Hey,

Since I'm playing a little with kernel modules, and I'm locking up my Tinker sometimes, I decided to wire a switch to the power header.

It works as you would expect a power button to work.  Hit once, and your OS should register it and ask if you want to shutdown or whatever.  If in suspend state, it will wake.  If in "off" state but the power hasn't been interrupted, it will boot.  If your Tinker has locked up, hold for 4 or so seconds, and it will power off.  

So, yeah, the easiest solution will definitely be to solder a header to the spot between the power input and HDMI and rig a (momentary) switch.  I just grabbed a reset switch from an old PC case I had lurking in my basement.  

It's kind of too bad that Asus didn't bother to solder the pins in.
I soldered a momentary switch between HDMI and input.
I am currently using the TB under Android OS, which is new for me.

In my project, I want the TB to monitor some relays through GPIOs.
The main relay will have to be disabled when the switch is pressed for sleep or shutdown.
Till now, I don't really understand the command generated by pressing this switch (under Android) neither the state in which the TB is after pressing the switch.
1- short press seems only to switch off the screen, a kind off lock screen. If you press again the switch the screen lights up. GPIOs' state are not affected.
If you press again the switch too soon, some screen lines are troubled and misaligned

2- longer press but less than 4s pops up the Android power menu. You can then shutdown or reboot the TB. GPIOs are also resetted unless you cancel the window of course.

3- >4s press generates a reset. The displayed screen during reset is horrible

And I am not sure of the exact state of the TB after a short switch action.
If anyone can give me some explanation regarding what this switch does as a command, in particular under Android, I would really appreciate.
Reply
#6
Hey, not sure if you guys are still around, but thanks for the script! one issue though. I'm getting an error when the script executes that says "Runtime error: This gpio is set to other function" whenever the script executes the GPIO.setup function. Any clues for me?

Thanks!
Reply
#7
(09-14-2018, 02:21 PM)karendar Wrote: Hey, not sure if you guys are still around, but thanks for the script! one issue though. I'm getting an error when the script executes that says "Runtime error: This gpio is set to other function" whenever the script executes the GPIO.setup function. Any clues for me?

Thanks!

After more mucking around, I got the script to execute without errors. Had to git clone the latest version from Asus' GPIO libs... Issue is, power button doesn't work as expected at all for me with the nespi case. If I hit the power button, it just shuts off the entire thing. If I hit the reset button, it cuts power. Both scenarios end up corrupting my SD card... So I'm a little tired of rewriting my SD card to test. Sad Any help would be appreciated.

Thanks!
Reply
#8
Do you have skill to compile a new kernel ?
https://github.com/armbian/build/blob/master/patch/kernel/rockchip-default/135_tinker_boot_fix.patch.disabled
https://github.com/armbian/build/blob/master/patch/kernel/rockchip-default/135_tinker_boot_fix.patch.disabled
These patches might give an idea.
Reply
#9
@karendar,

What is your Tinker Board version? S?
You can find the power button pin on board. no need to use sw coding via GPIO.
[Image: j3fhDzK.png]

other ref: https://tinkerboarding.co.uk/forum/thread-281-post-751.html
Reply
#10
(09-17-2018, 02:59 AM)Craz_tyle Wrote: @karendar,

What is your Tinker Board version? S?
You can find the power button pin on board. no need to use sw coding via GPIO.
[Image: j3fhDzK.png]

other ref: https://tinkerboarding.co.uk/forum/thread-281-post-751.html

Original Tinkerboard. Already soldered leads on the board, but I'm trying to get it to integrate with the Nespi case... Considering that already connects to GPIO cleanly, not sure how to approach this other than with software.. I don't really wanna do any hardware mods on the case itself, as I wanna be able to return it if possible.

(09-16-2018, 11:46 AM)Im4Tinker Wrote: Do you have skill to compile a new kernel ?
https://github.com/armbian/build/blob/master/patch/kernel/rockchip-default/135_tinker_boot_fix.patch.disabled
https://github.com/armbian/build/blob/master/patch/kernel/rockchip-default/135_tinker_boot_fix.patch.disabled
These patches might give an idea.

Haven't compiled a kernel in years. lol

I imagine I can muddle through compiling it... I'm running the old ROTT version, so it might be outdated, hence the issues I'm facing. Thanks!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)