-
Notifications
You must be signed in to change notification settings - Fork 47
Closed
Labels
Description
Obviously the sysfs isn't ideal if you want to waggle GPIO pins at high speed, but the library can be made a bit faster:
- input()/output() are aliases for read()/set(), but the way they are defined _verify() is called twice for each call, once for output() and then again for set(). So change to:
def input(pin):
'''read the pin. Same as read'''
return read(pin)
def output(pin, value):
'''set the pin. Same as set'''
return set(pin, value)
or just:
input = read
output = set
-
Wrapping read()/set() with _verify() adds around 20% overhead to those calls. Is it really needed? If it is needed, doing the same "if pin in _open" test inside the set() function has far less overhead
-
Is there any benefit from defining LOW, HIGH = 'low', 'high' instead of as int? Removing the:
if value is LOW:
value = 0
value = int(bool(value))
from inside read()/set() gives another 5-10% improvement. The RPi.GPIO library uses ints rather than strings for pin values.
- The logging call adds around 30% overhead to read()/set() even with no debug output (!) i.e., without "logging.basicConfig(level=logging.DEBUG)" set at the top of the library. Even this would help a lot:
if (log.level==logging.DEBUG):
log.debug("Write {0}: {1}".format(pin, value))
All told, those 4 changes doubles the maximum speed of the library, on a modest dual core ARM board.
Reactions are currently unavailable