-
Notifications
You must be signed in to change notification settings - Fork 58
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
Conversation
@caternuson Are you sure that's using your fork of the ads1x15 library? It seems like you're in the ads1x15 library directory, so the import paths you're using wouldn't work (or at least didn't work on my pi) Python 3.5 was giving me some issues with the SCL and SDA pins, so I'm installing 3.7 to try it on that |
@caternuson Ok, so I got 3.7 working, which turned out to be an exceptional waste of time since the issue was actually that I forgot to enable I2C.
|
@dherrada Are you testing the current version or the pull request? You need to do some special git-foo to bring in the PR code. |
@caternuson You're totally right. I did have your fork, but I was not on the right branch |
@caternuson Yep. Works perfectly now |
@caternuson This is working for me as well. Here's some benchmark testing. import board
import busio
import digitalio
from adafruit_mcp230xx.mcp23017 import MCP23017
import adafruit_ads1x15.ads1115 as ADS
from adafruit_ads1x15.analog_in import AnalogIn
from adafruit_ads1x15.ads1x15 import Mode
import time
def print_data_and_time(pin):
t_start = time.time()
print('{}: {:>5} {}'.format(pin._pin_setting, pin.value, (time.time() - t_start) * 1000))
i2c = busio.I2C(board.SCL, board.SDA, frequency=1000000)
ads = ADS.ADS1115(i2c, address=0x49)
ads.mode = Mode.CONTINUOUS
ads.data_rate = 860
p0 = AnalogIn(ads, ADS.P0)
p1 = AnalogIn(ads, ADS.P1)
p2 = AnalogIn(ads, ADS.P2)
p3 = AnalogIn(ads, ADS.P3)
print_data_and_time(p0)
print_data_and_time(p0)
print_data_and_time(p0)
print_data_and_time(p1)
print_data_and_time(p2)
print_data_and_time(p3)
print_data_and_time(p3)
print_data_and_time(p3)
print_data_and_time(p1) The correct values for the following pins should be (roughly):
and now with the fix:
|
@@ -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 |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
Updating https://github.com/adafruit/Adafruit_CircuitPython_ADS1x15 to 2.2.2 from 2.2.1: > Merge pull request adafruit/Adafruit_CircuitPython_ADS1x15#57 from caternuson/iss55 Updating https://github.com/adafruit/Adafruit_CircuitPython_BLE to 7.0.1 from 7.0.0: > Merge pull request adafruit/Adafruit_CircuitPython_BLE#93 from dhalbert/start_scan-prefix-fix
Possible fix for #55
This issue wasn't 100% reproducible. Sometimes was able to get things to work on a Pi0. Testing on a Pi4 seemed to make it happen all the time. The datasheet doesn't provide much information about what to do when switching ADC channels while in continuous mode. This fix simply adds a delay based on data rate. Seemed to fix, tested on Pi 4: