1511209962.263492 -> 1paddyg wrote: ↑Sun Nov 19, 2017 1:59 pmHi @fishwolf, it's tricky for us to track down the solution but it's also hard for you without more data (as you are finding). My approach would be a) try to find exactly what happens each time the switch makes or breaks. That's what my previous post was, basically run as simple a program as possible and see what you get (this is a slightly modified version to make a smaller file).b) if there are lots of changes as the switch makes or breaks then I would use the system you already do but b.1) delay the re-measurement of the pin state b.2) keep track of the previous state and only count changes from 0 to 1 i.e. 1 to 1 would be ignored. c) if the changes happen randomly when the switch is either off or on then I would check the wiring, also bits of wire can act as aerials and pick up voltage fluctuations from the 'ether'. These random fluctuations should be filterable by delayed re sampling in the callback function.Code: Select all
#! /usr/bin/python import time import RPi.GPIO as gpio gpio.setmode(gpio.BCM) #PinStart = whatever you're using gpio.setup(PinStart, gpio.IN, pull_up_down=gpio.PUD_DOWN) with open('log.txt', 'w') as f: last_state = 0 for i in range(10000000): state = gpio.input(PinStart) if state != last_state: f.write('{} -> {}\n'.format(time.time(), state) last_state = state #finally gpio tidy up
1511209962.264796 -> 0
1511209962.6437123 -> 1
1511209962.6450381 -> 0
1511209962.7736838 -> 1
1511209962.7749689 -> 0
1511209962.9237957 -> 1
1511209962.9248245 -> 0
1511209963.0734184 -> 1
1511209963.0742624 -> 0
1511209963.1900215 -> 1
1511209964.1405602 -> 0
1511209964.9820774 -> 1
1511209966.6762125 -> 0
1511209966.8334801 -> 1
1511209966.834763 -> 0
1511209966.8734715 -> 1
1511209966.8747513 -> 0
1511209967.2129457 -> 1