View: 7617|Reply: 8

[solved]read PIR sensor on orange pi pc plus

[Copy link]

6

threads

22

posts

109

credits

Registered member

Rank: 2

credits
109
Published in 2017-1-20 19:24:56 | Show all floors |Read mode
Edited by wwwlu at 2017-2-24 17:54

I have installed the following:
https://github.com/duxingkei33/orangepi_PC_gpio_pyH3
I can succesfully make a led blink.
But I can't read the value of a PIR sensor (HC-SR501 )
It returns 1 during 3 seconds then 0 for another 3 seconds and loop.
I tested the sensor on a arduino and it works fine
here's my code:
from time import sleep
from pyA20.gpio import gpio
from pyA20.gpio import port
mq135 = port.PA12
gpio.init()
gpio.setcfg(mq135, gpio.INPUT)
try:
    while True:
        state = gpio.input(mq135)
        sleep(0.2)
        print " %d"%state
except KeyboardInterrupt:
    print ("Goodbye.")

1

threads

64

posts

240

credits

Intermediate member

Rank: 3Rank: 3

credits
240
Published in 2017-1-20 21:54:39 | Show all floors
have you tried to read values from corresponding file in sysfs directly, when sensor is attached?

6

threads

22

posts

109

credits

Registered member

Rank: 2

credits
109
 Author| Published in 2017-1-20 22:08:42 | Show all floors
no shooreg, how can I do that ?

1

threads

64

posts

240

credits

Intermediate member

Rank: 3Rank: 3

credits
240
Published in 2017-1-20 22:35:24 | Show all floors
Try like described here.
The GPIO pin states are reflected to text files in sysfs, usually files are named equal to pin naming. These text files contain 0 or 1 for a high or low level of corresponding pin.
Very useful for debug purposes.

1

threads

64

posts

240

credits

Intermediate member

Rank: 3Rank: 3

credits
240
Published in 2017-1-20 22:37:50 | Show all floors
And besides that, these files are not read-only, so you can change the state of GPIO pin directly from the shell, just using something like "echo 1 > /sys/class/gpio_sw/PA2"

1

threads

64

posts

240

credits

Intermediate member

Rank: 3Rank: 3

credits
240
Published in 2017-1-20 22:47:41 | Show all floors
By the way, yor sensor has 2 work modes (H and L) and 2 regulators (sensivity and impulse length)
What you described in your post is a normal operation in mode L with impulse length set for 3 sec.
So, actually, looks like you have everything working correctly.

6

threads

22

posts

109

credits

Registered member

Rank: 2

credits
109
 Author| Published in 2017-1-20 23:44:09 | Show all floors
Edited by wwwlu at 2017-1-21 00:45

I checked in /sys/class/gpio_sw/ and there is no PA12
So I changed for PA6 but I still get the same issue
I have no problem to set a value (using python) for a pin but what I want is to read the value.
I am supposed to receive 0 if I don't move in front of the sensor and 1 if i do. That's the normal behavior on Arduino
The Trigger Mode is set to L but that does not change the problem. Even if no motion is detected the sensor send 1 every 3 seconds

1

threads

64

posts

240

credits

Intermediate member

Rank: 3Rank: 3

credits
240
Published in 2017-1-25 15:52:48 | Show all floors
OK, try without sensor - simulate logical 0 and 1 on GPIO pin you selected by pulling it to GND and 3.3V respectively. And check if your software reads it correctly.

6

threads

22

posts

109

credits

Registered member

Rank: 2

credits
109
 Author| Published in 2017-2-16 01:21:54 | Show all floors
thanks shooreg, I changed the jumper of the sensor and give it time to stabilise (15 seconds) and it works fine now
You need to log in before you can reply login | Register

Points Rule

Quick reply Top Return list