Skip to content

Update read for continuous #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 28, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion adafruit_ads1x15/ads1x15.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
__version__ = "0.0.0-auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_ADS1x15.git"

import time
from micropython import const
from adafruit_bus_device.i2c_device import I2CDevice

Expand Down Expand Up @@ -161,7 +162,10 @@ def _read(self, pin):
if self.mode == Mode.CONTINUOUS and self._last_pin_read == pin:
return self._conversion_value(self.get_last_result(True))
self._last_pin_read = pin
config = _ADS1X15_CONFIG_OS_SINGLE
if self.mode == Mode.SINGLE:
config = _ADS1X15_CONFIG_OS_SINGLE
else:
config = 0
config |= (pin & 0x07) << _ADS1X15_CONFIG_MUX_OFFSET
config |= _ADS1X15_CONFIG_GAIN[self.gain]
config |= self.mode
Expand All @@ -170,8 +174,12 @@ def _read(self, pin):
self._write_register(_ADS1X15_POINTER_CONFIG, config)

if self.mode == Mode.SINGLE:
# poll conversion complete status bit

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would throw these comments up in the function definition comments to describe how this works in the context of the whole function.

while not self._conversion_complete():
pass
else:
# just sleep (can't poll in continuous)
time.sleep(2 / self.data_rate)
Copy link

@zacnelson zacnelson Jun 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the ADS1115 data sheet (and also the ADS1015) the conversion time is 1 / DR:

9.3.6 Output Data Rate and Conversion Time
The ADS111x offer programmable output data rates. Use the DR[2:0] bits in the Config register to select output
data rates of 8 SPS, 16 SPS, 32 SPS, 64 SPS, 128 SPS, 250 SPS, 475 SPS, or 860 SPS.
Conversions in the ADS111x settle within a single cycle; thus, the conversion time is equal to 1 / DR.

@caternuson Any particular reason you chose 2 / DR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried 1 / DR first and it didn't seem to work. Might have something to do with extra settling time needed due to the mux being changed? Not sure.


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

Expand Down