gobot
gobot copied to clipboard
ads1x15 driver not working stable when reading multiple inputs
Currently I'm testing a module with ADS1115 and 2 used analog input pins. Most of the time the values of both inputs are converted as the same, although the voltage differs (measured by a meter).
The main reason seems to be the wait line 350 in driver code which tries to delay, but is to small or at the wrong position.
According to the datasheet of the ADS111x:
- in the section "Output Data Rate and Conversion Time" "Conversions in the ADS111x settle within a single cycle; thus, the conversion time is equal to 1 / DR.", which the above mentioned line of gobot driver code tries to implement
- in the table "Config Register Field Descriptions" the "OS can only be written when in power-down state and has no effect when a conversion is ongoing.", which is not implemented yet
A raw implementation of a "wait for bit15 is 1" seems to fix the problem.
I will make further tests and can possibly provide a fix by one of the both approaches or add a With...() function for that.
Found that the python library of adafruit uses the "wait for bit15 is 1" approach for single mode (which we currently have) and the time.Sleep-Approach for continuous mode (which is not implemented yet).
The Continuous mode was introduced with this commit: https://github.com/adafruit/Adafruit_CircuitPython_ADS1x15/commit/0153a800216188eaa0c60879bf63768c9a5e56c1
Some further investigations shows that the implemented delay is quite correct (7.912ms for 128 SPS). According to the datasheet the device is compatible with standard, fast and high-speed mode, so this should be no cause for the problem. In the section "Single-Shot Mode", the wake-up time should be fast enough "When the OS bit is asserted, the device powers up in approximately 25 μs, resets the OS bit to 0, and starts a single conversion.", so this should also be no cause of the problem.
My device needs around 32ms for one conversion. Possibly the purchased device is of low quality and don't fulfill the specifications.
So I will go with the safest approach and implement the code like in python. By adding a With...() function, this default behavior can be disabled.
Sounds great @gen2thomas thanks!
part of release v2.0.0