Skip to content

Commit 1ffc009

Browse files
authored
Merge pull request #57 from caternuson/iss55
Update read for continuous
2 parents 0ecce36 + 0153a80 commit 1ffc009

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

adafruit_ads1x15/ads1x15.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
__version__ = "0.0.0-auto.0"
3232
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_ADS1x15.git"
3333

34+
import time
3435
from micropython import const
3536
from adafruit_bus_device.i2c_device import I2CDevice
3637

@@ -161,7 +162,10 @@ def _read(self, pin):
161162
if self.mode == Mode.CONTINUOUS and self._last_pin_read == pin:
162163
return self._conversion_value(self.get_last_result(True))
163164
self._last_pin_read = pin
164-
config = _ADS1X15_CONFIG_OS_SINGLE
165+
if self.mode == Mode.SINGLE:
166+
config = _ADS1X15_CONFIG_OS_SINGLE
167+
else:
168+
config = 0
165169
config |= (pin & 0x07) << _ADS1X15_CONFIG_MUX_OFFSET
166170
config |= _ADS1X15_CONFIG_GAIN[self.gain]
167171
config |= self.mode
@@ -170,8 +174,12 @@ def _read(self, pin):
170174
self._write_register(_ADS1X15_POINTER_CONFIG, config)
171175

172176
if self.mode == Mode.SINGLE:
177+
# poll conversion complete status bit
173178
while not self._conversion_complete():
174179
pass
180+
else:
181+
# just sleep (can't poll in continuous)
182+
time.sleep(2 / self.data_rate)
175183

176184
return self._conversion_value(self.get_last_result(False))
177185

0 commit comments

Comments
 (0)