Jump to content

Recommended Posts

Posted

Hi, This topic was a initially a question and become a tutorial to use push buttons on orange pi PC.

This tutorial has been made with an Orange PI PC running on "Armbian_5.35_Orangepipc_Debian_jessie_default_3.4.113.img".

 

With this example you will be able to launch 3 different scripts for each push button : 

/usr/local/bin/run<Wpi GPIO number>short.sh   -> immediately launched when a button is pressed

/usr/local/bin/run<Wpi GPIO number>long.sh  ->  launched after a long pression

/usr/local/bin/run<Wpi GPIO number>release.sh  -> launched when a button is released (but not after a long pression)

 

 

I've made this image to know easily see the correspondence between WiringOP and physical Orange PI PC connector :

 

Pinout2.thumb.jpg.3d6076415349088c1bcd76cf2a26d17e.jpg

 

Mhhh if you want to modify it, you'll find the excel source file here.

 

Sources :

http://orangepi.club/showthread.php?tid=2173     -> excellent tutorial for beginners !

https://github.com/zhaolei/WiringOP     -> a modified WiringPi for OrangePi

http://nix.zeya.org/wiki/разработка_средств_аппаратного_управления_для_orange_pi_pc     -> a very good example of program in C to use Orange PI GPIO with push buttons

 

To install and compile the WiringOP library :

mkdir downloads
cd downloads
git clone https://github.com/zhaolei/WiringOP.git -b h3
cd WiringOP/
sudo ./build

 

Make a test :

gpio readall

 

You should obtain something like that :

 +-----+-----+----------+------+---+-Orange Pi+---+---+------+---------+-----+--+
 | BCM | wPi |   Name   | Mode | V | Physical | V | Mode | Name     | wPi | BCM |
 +-----+-----+----------+------+---+----++----+---+------+----------+-----+-----+
 |     |     |     3.3v |      |   |  1 || 2  |   |      | 5v       |     |     |
 |  12 |   8 |    SDA.0 | ALT5 | 0 |  3 || 4  |   |      | 5V       |     |     |
 |  11 |   9 |    SCL.0 | ALT5 | 0 |  5 || 6  |   |      | 0v       |     |     |
 |   6 |   7 |   GPIO.7 | ALT3 | 0 |  7 || 8  | 0 | ALT3 | TxD3     | 15  | 13  |
 |     |     |       0v |      |   |  9 || 10 | 0 | ALT3 | RxD3     | 16  | 14  |
 |   1 |   0 |     RxD2 | ALT3 | 0 | 11 || 12 | 0 | ALT3 | GPIO.1   | 1   | 110 |
 |   0 |   2 |     TxD2 | ALT3 | 1 | 13 || 14 |   |      | 0v       |     |     |
 |   3 |   3 |     CTS2 |   IN | 1 | 15 || 16 | 0 | ALT3 | GPIO.4   | 4   | 68  |
 |     |     |     3.3v |      |   | 17 || 18 | 0 | ALT3 | GPIO.5   | 5   | 71  |
 |  64 |  12 |     MOSI | ALT4 | 0 | 19 || 20 |   |      | 0v       |     |     |
 |  65 |  13 |     MISO | ALT4 | 0 | 21 || 22 | 0 | ALT3 | RTS2     | 6   | 2   |
 |  66 |  14 |     SCLK | ALT4 | 0 | 23 || 24 | 0 | ALT4 | CE0      | 10  | 67  |
 |     |     |       0v |      |   | 25 || 26 | 0 | ALT5 | GPIO.11  | 11  | 21  |
 |  19 |  30 |    SDA.1 | ALT5 | 0 | 27 || 28 | 0 | ALT5 | SCL.1    | 31  | 18  |
 |   7 |  21 |  GPIO.21 |   IN | 1 | 29 || 30 |   |      | 0v       |     |     |
 |   8 |  22 |  GPIO.22 |   IN | 1 | 31 || 32 | 0 | ALT3 | RTS1     | 26  | 200 |
 |   9 |  23 |  GPIO.23 |   IN | 1 | 33 || 34 |   |      | 0v       |     |     |
 |  10 |  24 |  GPIO.24 |   IN | 1 | 35 || 36 | 0 | ALT3 | CTS1     | 27  | 201 |
 |  20 |  25 |  GPIO.25 | ALT5 | 0 | 37 || 38 | 0 | ALT3 | TxD1     | 28  | 198 |
 |     |     |       0v |      |   | 39 || 40 | 0 | ALT3 | RxD1     | 29  | 199 |
 +-----+-----+----------+------+---+----++----+---+------+----------+-----+-----+
 | BCM | wPi |   Name   | Mode | V | Physical | V | Mode | Name     | wPi | BCM |
 +-----+-----+----------+------+---+-Orange Pi+---+------+----------+-----+-----+

 

 

Now we are going to write a program in C to detects pushes on buttons :

nano pushbuttons.c

The copy / paste the C program below :

(you should modify the numbers of buttons that you use, the WiringOP pins that you use, you can create scripts later)

 

  Reveal hidden contents

 

OK now compile it and run it :
 

gcc -lwiringPi -lwiringPiDev -o pushbuttons pushbuttons.c
./pushbuttons

 

Press a button and you're done ;)

 

FYI : To use the native button on the motherboard of the orange PI PC you can use  "acpid" to make working for reboot

 

I hope it will be useful to some of you.

 

Posted

Successfully used this on an Orange Pi Zero with

unsigned int nums = 2;
unsigned int WpiPinsSelection[] = {8, 24};

Pin "24" corresponds to physical pin 26 as per this pinout guide:O03j0.jpg

Posted

Nice script, but it's not working on my OPiZeroPlus2 H5

 

The problem is outdated WiringPO library - from zhaolei

 

More updated library from Orange http://www.orangepi.org/Docs/WiringPi.html  can be compiled on actual armbian

gpio recognize opizeroplus2 board, but pushbuttons script frozen hole board ...

 

Is any project on sf or github for these boards and GPIO contol ..??

Posted

Thanks for answer Igor ..

I'm wrote my own script in python,  moved to OPi Zero with poor XR819 ..

 

Better OPi Zero Plus H5 with RTL8189FTV wifi module was burned ...

and H5 board does notwork properly with WiringPO library at this moment ..

 

see:

 

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

Important Information

Terms of Use - Privacy Policy - Guidelines