0

Just got a Raspberry Pi kit and started tinkering with it. I have the following interrupt in place:

GPIO.add_event_detect(23, GPIO.FALLING, callback=partial(sensor1, LastPour1, PourCounter1) 

and the definition of the method is as follows:

def sensor1(LastPour1, Pourcounter1):

yet when I trip the event, I get:

TypeError: sensor1() takex exactly 2 arguments (3 given)

please enlighten me! here is most of the relevant code

# GPIO 23 set up as input. It is pulled up to stop false signals
GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_UP)


VOL_PER_TICK = 5
PourCounter1 = 0
PourCounter2 = 0
LastPour1 = time.time()
LastPour2 = time.time()
Vol1 = 0
Vol2 = 0
Beer1 = ""
Beer2 = ""
workfile = 'beer_data.txt'

def sensor1(LastPour1, PourCounter1):
    "sensor 1 tripped"

    if time.time() - LastPour1 < 5:
            PourCounter1 = PourCounter1 + 1
    else:
            print "NEW POUR\n"
            PourCounter1 = 1
            LastPour1 = time.time()

    GPIO.output(19, True)
    time.sleep(0.05)
    GPIO.output(19, False)



GPIO.add_event_detect(23, GPIO.FALLING, callback=partial(sensor1, LastPour1, PourCounter1))
  • 1
    if `sensor1` is an instance method, it will be called passing it the object it is bound to as its first parameter (i.e. `self`). Either declare it as a plain function outside the class it is now in, or decorate it with `@staticmethod`. See if [this SO QA](http://stackoverflow.com/questions/136097/what-is-the-difference-between-staticmethod-and-classmethod-in-python) helps you – Pynchia Oct 17 '15 at 14:08
  • made the suggested change, now I get a typeerror: @staticmethod is not callable – Charles Robitaille Oct 17 '15 at 15:21

0 Answers0