Closed proboscide99 closed 2 years ago
This was added with #76 and released with 2.4.0: https://github.com/adafruit/Adafruit_ADS1X15/releases/tag/2.4.0
@proboscide99 Thanks for the PR. For future ref, PRs need to pass CI. This PR was failing on clang formatting. https://learn.adafruit.com/the-well-automated-arduino-library/formatting-with-clang-format
Hello Nelson, this is slightly different: the "continuous and non blocking" works on a single channel.
My requirement was having three channels scanned with non-blocking approach.
In my solution, the function immediately (if the conversion has been completed) returns the previous conversion result (the caller should keep track of wich channel was converted) then starts a new conversion on the specified channel.
I'm using it in an ESP32-based solar charge controller to monitor voltage/current and temperature of the 450Ah 24V battery pack.
Ciao! Alessandro
On 2/8/22 01:28, Carter Nelson wrote:
This was added with #76 https://github.com/adafruit/Adafruit_ADS1X15/pull/76 and released with 2.4.0: https://github.com/adafruit/Adafruit_ADS1X15/releases/tag/2.4.0
@proboscide99 https://github.com/proboscide99 Thanks for the PR. For future ref, PRs need to pass CI. This PR was failing on clang formatting. https://learn.adafruit.com/the-well-automated-arduino-library/formatting-with-clang-format
— Reply to this email directly, view it on GitHub https://github.com/adafruit/Adafruit_ADS1X15/pull/77#issuecomment-1032083513, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEZIDYZEQ563GRHHNFXOA73U2BPTNANCNFSM5NUF34RA. Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
You are receiving this because you were mentioned.Message ID: @.***>
-- written and gracefully sent by X55
The ADS can't read more than a single configuration (channel) simultaneously. The nonblocking example could be expanded to more than one channel: https://github.com/adafruit/Adafruit_ADS1X15/blob/master/examples/nonblocking/nonblocking.ino But still only one channel at a time.
The requirement is unclear. Might help to open an issue and provide more details.
On 2/9/22 00:34, Carter Nelson wrote:
The ADS can't read more than a single configuration (channel) simultaneously.
Of course not.
The nonblocking example could be expanded to more than one channel: https://github.com/adafruit/Adafruit_ADS1X15/blob/master/examples/nonblocking/nonblocking.ino But still only one channel at a time.
Yes, you're right. I didn't notice the 'continuous mode' could be disabled by the second parameter.
Then this version does the same job as mine. Why isn't it included in the main repository?
I just wrote a modified version of 'readADC_SingleEnded' where I return the result of previous conversion AND start a new one on the specified channel.
Here it is.
// // POPPI 05/02/2022: versione modificata di 'readADC_SingleEnded()'. // // Nonblocking version of 'readADC_SingleEnded()': // // Reads the result of PREVIOUS conversion and starts a new one on // specified channel, then exits immediately (returning the read value). // // If the calling interval is greater than conversion time, then the // function is completely non-blocking. // /**/ int16_t Adafruit_ADS1X15::readADC_SingleEnded_nonblock(uint8_t channel) {
// If necessary, wait for the previous conversion to complete while (!conversionComplete());
// Stores the previous conversion results int16_t result = getLastConversionResults();
if (channel < 4) {
// Start with default values uint16_t config = ADS1X15_REG_CONFIG_CQUE_NONE | // Disable the comparator (default val) ADS1X15_REG_CONFIG_CLAT_NONLAT | // Non-latching (default val) ADS1X15_REG_CONFIG_CPOL_ACTVLOW | // Alert/Rdy active low (default val) ADS1X15_REG_CONFIG_CMODE_TRAD | // Traditional comparator (default val) ADS1X15_REG_CONFIG_MODE_SINGLE; // Single-shot mode (default)
// Set PGA/voltage range config |= m_gain;
// Set data rate config |= m_dataRate;
// Set single-ended input channel switch (channel) { case (0): config |= ADS1X15_REG_CONFIG_MUX_SINGLE_0; break; case (1): config |= ADS1X15_REG_CONFIG_MUX_SINGLE_1; break; case (2): config |= ADS1X15_REG_CONFIG_MUX_SINGLE_2; break; case (3): config |= ADS1X15_REG_CONFIG_MUX_SINGLE_3; break; }
// Set 'start single-conversion' bit config |= ADS1X15_REG_CONFIG_OS_SINGLE;
// Write config register to the ADC writeRegister(ADS1X15_REG_POINTER_CONFIG, config); }
return(result); }
The requirement is unclear. Might help to open an issue and provide more details.
Everything is right, thanks.
Alessandro
-- written and gracefully sent by X55
…d 'readADC_SingleEnded_nonblock()'
Thank you for creating a pull request to contribute to Adafruit's GitHub code! Before you open the request please review the following guidelines and tips to help it be more easily integrated:
Describe the scope of your change--i.e. what the change does and what parts of the code were modified. This will help us understand any risks of integrating the code.
Describe any known limitations with your change. For example if the change doesn't apply to a supported platform of the library please mention it.
Please run any tests or examples that can exercise your modified code. We strive to not break users of the code and running tests/examples helps with this process.
Thank you again for contributing! We will try to test and integrate the change as soon as we can, but be aware we have many GitHub repositories to manage and can't immediately respond to every request. There is no need to bump or check in on a pull request (it will clutter the discussion of the request).
Also don't be worried if the request is closed or not integrated--sometimes the priorities of Adafruit's GitHub code (education, ease of use) might not match the priorities of the pull request. Don't fret, the open source community thrives on forks and GitHub makes it easy to keep your changes in a forked repo.
After reviewing the guidelines above you can delete this text from the pull request.