Skip to content

Commit

Permalink
Merge pull request #24 from caternuson/iss23
Browse files Browse the repository at this point in the history
Add retries for moisture reading
  • Loading branch information
ladyada committed Feb 22, 2019
2 parents 2df8a67 + e604940 commit a60e576
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions adafruit_seesaw/seesaw.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit a60e576

Please sign in to comment.