please choosego to mobile | Continue to access the PC version
Author: linga51

GPIO library - WiringPi

[Copy link]

1

threads

20

posts

122

credits

Registered member

Rank: 2

credits
122
Published in 2015-9-4 01:12:00 | Show all floors
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
Published in 2015-9-4 02:15:33 | Show all floors
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 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

1

threads

20

posts

122

credits

Registered member

Rank: 2

credits
122
Published in 2015-9-4 02:48:40 | Show all floors
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
Published in 2015-9-9 03:10:35 | Show all floors
How can I test gpio with led ?

1

threads

20

posts

122

credits

Registered member

Rank: 2

credits
122
Published in 2015-9-11 03:23:36 | Show all floors
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 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 code

2

threads

9

posts

133

credits

Registered member

Rank: 2

credits
133
Published in 2015-9-13 05:44:00 | Show all floors
Edited by chirik at 2015-9-13 05:46

thank you! alexparadise

2

threads

9

posts

133

credits

Registered member

Rank: 2

credits
133
Published in 2015-9-20 02:34:14 | Show all floors
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?

1

threads

20

posts

122

credits

Registered member

Rank: 2

credits
122
Published in 2015-10-2 17:12:16 | Show all floors
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
Published in 2015-10-2 21:57:59 | Show all floors
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

539

credits

Senior member

Rank: 4

credits
539
Published in 2015-10-6 00:50:41 | Show all floors
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 need to log in before you can reply login | Register

Points Rule

Quick reply Top Return list