gknippels
unread,Feb 2, 2013, 4:19:07 PM2/2/13Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to quick2wi...@googlegroups.com
Hi,
I'm new to the forum, and have a question:
I'm trying to read out the status of a reed switch using epoll. Eventually I would like to use it to read out my water meter and monitor water usage The switch is connected to GPIO input 0 (GPIO pin 17) of my Rapsberry Pi (512 Mb version).
The electronic wiring diagram is simple test setup (sorry for the poor schematics):
3.3 V-------------------------------470Ohm------LED--------reedswitch-------GND
|
|
|
10KOhm
|
GPIO 17
I've just added the LED to visually observe when the reed switch closes/opens.
I'm using the following python 2.7 code:
import select
from datetime import datetime
from quick2wire.gpio import GPIOPin as Pin
from quick2wire.gpio import In, Out
pin1 = Pin(0, Pin.In, Pin.Both)
epoll = select.epoll()
epoll.register(pin1, select.EPOLLIN | select.EPOLLET)
while True:
events = epoll.poll()
for fileno, event in events:
if fileno == pin1.fileno():
print("%s: input reads %d and event %d detected!" %(datetime.now(), pin1.value, event))
if event & select.EPOLLIN:
print "EPOLLIN, Avialable for read."
if event & select.EPOLLOUT:
print "EPOLLOUT, Available for write."
if event & select.EPOLLPRI:
print "EPOLLPRI, Urgent data for read."
if event & select.EPOLLERR:
print "EPOLLERR, Error condition happened on the associated fd."
if event & select.EPOLLHUP:
print "EPOLLHUP, Hang up happened on the associated fd."
if event & select.EPOLLET:
print "EPOLLET, Set Edge Trigger behavior."
if event & select.EPOLLONESHOT:
print "EPOLLONESHOT, Set one shot behavior."
if event & select.EPOLLRDNORM:
print "EPOLLRDNORM, equivalent to EPOLLIN."
if event & select.EPOLLRDBAND:
print "EPOLLRDBAND, Priority data band can be read."
if event & select.EPOLLWRNORM:
print "EPOLLWRNORM, Equivalent to EPOLLOUT."
if event & select.EPOLLWRBAND:
print "EPOLLWRBAND, Priority data may be written."
if event & select.EPOLLMSG:
print "EPOLLMSG, ignored."
When I trigger the switch (by waving a magnet close to the switch) I get the following typical output where often (but not always the EPOLLERR is in the event. I don't understand what is causing it. I'm also not sure if it is a problem, since the electronics+script seem to behave more or less like a expected it too. But before I start working on debouncing the switch behavior I would prefer to understand EPOLLERR. Any suggestions?
2013-02-02 21:57:44.007578: input reads 1 and event 9 detected!
EPOLLIN, Avialable for read.
EPOLLERR, Error condition happened on the associated fd.
2013-02-02 21:58:09.218895: input reads 0 and event 9 detected!
EPOLLIN, Avialable for read.
EPOLLERR, Error condition happened on the associated fd.
2013-02-02 21:58:09.219966: input reads 0 and event 1 detected!
EPOLLIN, Avialable for read.
2013-02-02 21:58:09.410510: input reads 1 and event 9 detected!
EPOLLIN, Avialable for read.
EPOLLERR, Error condition happened on the associated fd.
2013-02-02 21:58:09.502444: input reads 0 and event 9 detected!
EPOLLIN, Avialable for read.
EPOLLERR, Error condition happened on the associated fd.
2013-02-02 21:58:09.588152: input reads 1 and event 9 detected!
EPOLLIN, Avialable for read.
EPOLLERR, Error condition happened on the associated fd.
Any suggestion on what could cause the EPOLLERR are appreciated