adafruit / adafruit/Adafruit_CircuitPython_ADS1x15
Setting the mode from SINGLE to CONTINUOUS gives erroneous readings
- Dominant language
- Python
- Stars
- 154
- Forks
- 57
- PR merge metrics
- No merged PRs in 30d
Description
Starting in `CONTINUOUS` mode makes it possible to change to `SINGLE` mode but a subsequent change back to `CONTINUOUS` mode then gives bogus values.
Measuring a DAC's output as an example set to about 5.000V (using a Cytron Maker Nano 2040 running 10.2.1).
```
>>> ads1115 = ADS1115(i2c, data_rate=128, mode=ads1x15.Mode.CONTINUOUS, gain=2/3) ; ads1115_chan = ADSAnalogIn(ads1115, ADS1115_PIN)
>>> print(ads1115_chan.voltage) ; time.sleep(0.1) ; print(ads1115_chan.voltage) ; time.sleep(0.1) ; print(ads1115_chan.voltage, ads1115_chan.value)
5.001
5.001188
5.001188 26673
>>> ads1115.mode = ads1x15.Mode.SINGLE
>>> print(ads1115_chan.voltage) ; time.sleep(0.1) ; print(ads1115_chan.voltage) ; time.sleep(0.1) ; print(ads1115_chan.voltage, ads1115_chan.value)
4.980562
4.98
4.980188 26561
>>> ads1115.mode = ads1x15.Mode.CONTINUOUS
>>> print(ads1115_chan.voltage) ; time.sleep(0.1) ; print(ads1115_chan.voltage) ; time.sleep(0.1) ; print(ads1115_chan.voltage, ads1115_chan.value)
3.096563
3.096563
3.096563 16515
```
Also happens if you start out in `SINGLE` mode.
```
>>> ads1115 = ADS1115(i2c, data_rate=128, mode=ads1x15.Mode.SINGLE, gain=2/3) ; ads1115_chan = ADSAnalogIn(ads1115, ADS1115_PIN)
>>> print(ads1115_chan.voltage) ; time.sleep(0.1) ; print(ads1115_chan.voltage) ; time.sleep(0.1) ; print(ads1115_chan.voltage, ads1115_chan.value)
4.980374
4.98
4.980188 26560
>>> ads1115.mode = ads1x15.Mode.CONTINUOUS
>>> print(ads1115_chan.voltage) ; time.sleep(0.1) ; print(ads1115_chan.voltage) ; time.sleep(0.1) ; print(ads1115_chan.voltage, ads1115_chan.value)
3.096563
3.096563
3.096563 16515
```
I can drop voltage to near 0.000V and the value lingers on.
```
>>> dac_chan.raw_value = 0
>>> print(ads1115_chan.voltage) ; time.sleep(0.1) ; print(ads1115_chan.voltage) ; time.sleep(0.1) ; print(ads1115_chan.voltage, ads1115_chan.value)
3.096563
3.096563
3.096563 16515
```
Perhaps this is something to with the `fast=True` code path in `_read_register()` and the ADS1115 hardware register (address) no longer being correct?
https://github.com/adafruit/Adafruit_CircuitPython_ADS1x15/blob/e6ae50daa7238e617d441dc84095368af988a30b/adafruit_ads1x15/ads1x15.py#L394-L403
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in adafruit_ads1x15/ads1x15.py at the _read_register() code linked in the issue, especially its fast=True path. Reproduce the reported SINGLE-to-CONTINUOUS and CONTINUOUS-to-SINGLE transitions with the ADS1115, then trace which register is read after the mode change. Done means continuous readings follow the applied input instead of retaining the stale bogus value.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- embedded-iot
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100