diff --git a/adafruit_seesaw/seesaw.py b/adafruit_seesaw/seesaw.py index 63e3258..2af8325 100644 --- a/adafruit_seesaw/seesaw.py +++ b/adafruit_seesaw/seesaw.py @@ -236,6 +236,17 @@ def moisture_read(self): self.read(_TOUCH_BASE, _TOUCH_CHANNEL_OFFSET, buf, .005) ret = struct.unpack(">H", buf)[0] time.sleep(.001) + + # retry if reading was bad + count = 0 + while ret > 4095: + self.read(_TOUCH_BASE, _TOUCH_CHANNEL_OFFSET, buf, .005) + ret = struct.unpack(">H", buf)[0] + time.sleep(.001) + count += 1 + if count > 3: + raise RuntimeError("Could not get a valid moisture reading.") + return ret def pin_mode_bulk(self, pins, mode):