Please select To the mobile version | Continue to access the desktop computer version

OrangePi

 Login            
 Register            
Search
Hot search: orangepi
Author: linga51

GPIO library - WiringPi

[Copy link]

0

Threads

19

Posts

111

Credits

Registered member

Rank: 2

Credits
111
Post time 2015-9-4 01:12:00 | Show all posts
By the way I ported RCswitch for OrangePi and any kind of device using GPIO.

https://github.com/apiel/rcswitch/

Have fun

2

Threads

9

Posts

133

Credits

Registered member

Rank: 2

Credits
133
Post time 2015-9-4 02:15:33 | Show all posts
Edited by chirik at 2015-9-4 03:41
alexparadise replied at 2015-9-4 01:10
@chirik

RPi.GPIO is build for RPI :p and use the library WiringPi. Until now nobody has ported this ...

there is a script
  1. #!/usr/bin/python

  2. # Import required Python libraries
  3. import RPi.GPIO as GPIO
  4. import time

  5. # Use BCM GPIO references
  6. # instead of physical pin numbers
  7. GPIO.setmode(GPIO.BCM)

  8. # Define GPIO to use on Pi
  9. GPIO_PIR = 7

  10. print "PIR Module Test (CTRL-C to exit)"

  11. # Set pin as input
  12. GPIO.setup(GPIO_PIR,GPIO.IN)      # Echo

  13. Current_State  = 0
  14. Previous_State = 0

  15. try:

  16.   print "Waiting for PIR to settle ..."

  17.   # Loop until PIR output is 0
  18.   while GPIO.input(GPIO_PIR)==1:
  19.     Current_State  = 0

  20.   print "  Ready"

  21.   # Loop until users quits with CTRL-C
  22.   while True :

  23.     # Read PIR state
  24.     Current_State = GPIO.input(GPIO_PIR)

  25.     if Current_State==1 and Previous_State==0:
  26.       # PIR is triggered
  27.       print "  Motion detected!"
  28.       # Record previous state
  29.       Previous_State=1
  30.     elif Current_State==0 and Previous_State==1:
  31.       # PIR has returned to ready state
  32.       print "  Ready"
  33.       Previous_State=0

  34.     # Wait for 10 milliseconds
  35.     time.sleep(0.01)

  36. except KeyboardInterrupt:
  37.   print "  Quit"
  38.   # Reset GPIO settings
  39.   GPIO.cleanup()
Copy the Code
which stops at:
import RPi.GPIO as GPIO
RuntimeError: This module can only be run on a Raspberry Pi!

I know that it RPi.GPIO for Raspberry Pi,
but how can i do this for orangePi

0

Threads

19

Posts

111

Credits

Registered member

Rank: 2

Credits
111
Post time 2015-9-4 02:48:40 | Show all posts
Edited by alexparadise at 2015-9-4 04:03

You have to port wiringPi for orangePi or you have to implement your on method for reading PIR pin. Maybe it's just send a 1 on the PIN when motion is detected (not so difficult to implement!!).
Edit:
I was not able to see correctly your code before but now that I can see it, you could just change GPIO.input(GPIO_PIR) by open('/sys/class/gpio_sw/PA1/data', 'r').readlines()


Then you plug your PIR on the PIN11................

2

Threads

9

Posts

133

Credits

Registered member

Rank: 2

Credits
133
Post time 2015-9-9 03:10:35 | Show all posts
How can I test gpio with led ?

0

Threads

19

Posts

111

Credits

Registered member

Rank: 2

Credits
111
Post time 2015-9-11 03:23:36 | Show all posts
This will switch on and off the led on your board


  1. sudo su
  2. modprobe gpio-sunxi
  3. echo 1 > /sys/class/gpio_sw/normal_led/data
  4. echo 0 > /sys/class/gpio_sw/normal_led/data
Copy the Code


Else you can plug a led on the pin 11 (Gpio 17) and pin 6 (GND)

  1. echo 1 > /sys/class/gpio_sw/PA1/data
  2. echo 0 > /sys/class/gpio_sw/PA1/data
Copy the Code

2

Threads

9

Posts

133

Credits

Registered member

Rank: 2

Credits
133
Post time 2015-9-13 05:44:00 | Show all posts
Edited by chirik at 2015-9-13 05:46

thank you! alexparadise

2

Threads

9

Posts

133

Credits

Registered member

Rank: 2

Credits
133
Post time 2015-9-20 02:34:14 | Show all posts
Edited by chirik at 2015-10-2 15:38

as I understand, read data from pin
cat < / sys / class / gpio_sw / PA1 / data
How can I read data consistently from pin?
And where is more information I can find about GPIO, on this board?

0

Threads

19

Posts

111

Credits

Registered member

Rank: 2

Credits
111
Post time 2015-10-2 17:12:16 | Show all posts
You could just write a program reading in loop the file /sys/class/gpio_sw/PA1/data
All depends what you wanna to achieve??

There is no information concerning this board at all. But you can get a bit more input from sunxi http://linux-sunxi.org/GPIO
Anyhow GPIO is nothing complicated, you have 2 mode INPUT or OUTPUT and then to 2 status LOW (0) or HIGH (1). That's all you have to know ;-)

2

Threads

9

Posts

133

Credits

Registered member

Rank: 2

Credits
133
Post time 2015-10-2 21:57:59 | Show all posts
alexparadise replied at 2015-10-2 17:12
You could just write a program reading in loop the file /sys/class/gpio_sw/PA1/data
All depends what ...

how can i change input and output mod ?

3

Threads

96

Posts

535

Credits

Senior member

Rank: 4

Credits
535
Post time 2015-10-6 00:50:41 | Show all posts
Edited by Survive-Pi at 2015-10-5 11:13
chirik replied at 2015-10-2 06:57
how can i change input and output mod ?

Didn't read the details properly. Ignore previous comment.
Orange Pi Plus
You have to log in before you can reply Login | Register

Points Rules

Archiver|Mobile edition|Darkroom|OrangePi En ( 粤ICP备14086627号-2

2019-11-15 10:26 GMT+8 , Processed in 0.033865 second(s), 20 queries .

Powered by Discuz! X3.2

© 2014-2015 orangepibbs en.

Quick Reply To Top Return to the list