It appears that just making calls to GPIO.setup() is gradually using up memory (and slowing down the rate at which these operations can be performed). This is unexpected. :)
Here's an example program, bug.py (press Ctrl-C to exit):
Code: Select all
#!/usr/bin/python
import sys
import time
import Adafruit_BBIO.GPIO as GPIO
# GPIO assignments for each button
BTN_GPIO_A = "P8_17"
BTN_GPIO_B = "P8_18"
BTN_GPIO_C = "P8_26"
BTN_GPIO_D = "P9_15"
BTN_GPIO_X_1 = "P8_7" # shared with LED
BTN_GPIO_X_2 = "P8_8" # shared with LED
BTN_GPIO_Y_1 = "P8_9" # shared with LED
BTN_GPIO_Y_2 = "P8_10" # shared with LED
BTN_GPIO_Z_1 = "P8_11" # shared with LED
BTN_GPIO_Z_2 = "P8_12" # shared with LED
BTN_GPIO_E = "P8_13"
BTN_GPIO_COM = "P9_41"
LED_GPIO_T = BTN_GPIO_X_1
LED_GPIO_D = BTN_GPIO_X_2
LED_GPIO_C = BTN_GPIO_Y_1
LED_GPIO_H = BTN_GPIO_Y_2
LED_GPIO_P = BTN_GPIO_Z_1
LED_GPIO_E = BTN_GPIO_Z_2
LED_GPIO_COM = "P9_42"
# these button GPIOs are ALWAYS inputs
GPIO.setup(BTN_GPIO_A, GPIO.IN)
GPIO.setup(BTN_GPIO_B, GPIO.IN)
GPIO.setup(BTN_GPIO_C, GPIO.IN)
GPIO.setup(BTN_GPIO_D, GPIO.IN)
GPIO.setup(BTN_GPIO_E, GPIO.IN)
# BTN_GPIO_COM is ALWAYS an output
GPIO.setup(BTN_GPIO_COM, GPIO.OUT)
try:
tickTime = 0
seconds = count = 0
runCode = int(sys.argv[1])
print "runCode:", runCode
while True:
count += 1
now = time.time()
# first time, establish next tick time
if tickTime == 0:
tickTime = now
# do stuff
if runCode:
# to read buttons, BTN_GPIO_COCOM (always an output) must be low
# removed
# so that only GPIO.setup calls are made
# GPIO.output(BTN_GPIO_COM, GPIO.LOW)
# and LED_COM must be an output set low
GPIO.setup(LED_GPIO_COM, GPIO.OUT)
# removed
# so that only GPIO.setup calls are made
# GPIO.output(LED_GPIO_COM, GPIO.LOW)
# to read buttons, GPIOs must be inputs
GPIO.setup(BTN_GPIO_X_1, GPIO.IN)
GPIO.setup(BTN_GPIO_X_2, GPIO.IN)
GPIO.setup(BTN_GPIO_Y_1, GPIO.IN)
GPIO.setup(BTN_GPIO_Y_2, GPIO.IN)
GPIO.setup(BTN_GPIO_Z_1, GPIO.IN)
GPIO.setup(BTN_GPIO_Z_2, GPIO.IN)
# Tick! Print elapsed seconds, number of times through loop in last second
if now >= tickTime:
tickTime += 1
print "%ds %d" % (seconds, count)
seconds += 1
count = 0
except KeyboardInterrupt:
print
print "Exiting..."
Code: Select all
# bug.py 0
BUT, if run as
Code: Select all
# bug.py 1
Code: Select all
ps -o vsize -p <process id>
I discovered this while running production code which multiplexes some buttons and LEDs over the GPIOs.
Any thoughts?