Jump to content

How to turn ON/OFF Orangepi PC from Button on GPIO


lucidfaya

Recommended Posts

Hello :D!

 

Im new customer of Orangepi board.

My board: ORANGE PI PC.

 

I have a question, some one have a guide or have try to create a script for make a button ON - OFF on GPIO on this board?

 

I have try with ETA PRIME GUIDE FOR RASPBERRY PI 3 (u can find on youtube) but this guide is for raspberry pi 3, and dont work on orange pi.

I have install this GPIO  for orange pi from this guide : http://www.instructables.com/id/Orange-Pi-One-Python-GPIO-basic/?fref=gc

 

I need really to put button on gpio and make on off board from here, very tnx at all!

 

20770416_10213507790389946_2498391252773459192_n.jpg.626453b58fbe48680cdf23a4e64ff435.jpg

 

 

Link to comment
Share on other sites

For personal simplicity I would git clone https://github.com/duxingkei33/orangepi_PC_gpio_pyH3
Setup whatever pin you're connecting the switch to using the PYA20 library's (above) example code as seen here: https://pypi.python.org/pypi/pyA20
Use that library read the switch. For example: If pin high/low or on/off, use python subprocess or os.system functions to run linux shutdown, reboot command.

I might be able to give you a sample script or more concise instructions but don't hold your breath. For now I'll give you this, which is a pretty damn good start for having not really started :P
This is a script I was using on a NanoPiNeoAir using a reed (magnetic) switch attached to a door but could be easily changed to suit your needs. I've commented out the stuff that you won't need but much of the variable names are the same soo.... pretend the door is your switch! Or you can change the prompts/names yourself.

https://gist.github.com/BiTinerary/2734ac46e80af2b1a2158c9f0ba79e25

P.s. You'll need to specify the pin you're using for your button but if you use my script in tandem with the tutorial you link to (replace LED with switch) it should 'technically' work. Hack away at it, see what you can come up with and report back. Also..... you have heatsinks on your RAM dies but not your CPU? Sup with that?

Link to comment
Share on other sites

I made it simpler by renaming some stuff and omitting extra crap from previous project so check the link again. That's about as simple as it gets. You really only need to read lines 27-38.
https://gist.github.com/BiTinerary/2734ac46e80af2b1a2158c9f0ba79e25#file-shutdownswitch-py-L27-L38
 

The script simply put, checks every second to see if the GPIO (that you still have to change on line 8) pin is pulled high or low, up or down. If pulled high, send shutdown command. If low, do nothing. Continue the loop. If those ten lines of code are too complicated then I can't help you. Read up on programming. I can suggest some pretty good books.


Keep in mind that I can't remember if my reed switch defaulted to open or closed so the high/low might be switched around for you. This simply means that when you run the script if the button isn't pressed it might print "Shut Down Computer!" instead of doing nothing. If this is the case for you, simply swap lines 33 and 36. Debug with print statements so that you're not unintentionally shutting down your OPi PC.

Lemme know how it goes.

Link to comment
Share on other sites

No. This board lack hw part which is present on A10-A20-A64 ... a proper PMU (AXP chip) which can power on/off ... here this is done via special close sourced part of the H3 chip which can do some hybrid deep sleep/wakeup.

Wrote on mobile

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