Home › Forums › Mayfly Data Logger › Testing power consumption › Reply To: Testing power consumption
Trying to track down and eliminate my my Mayfly’s excessive power draw during sleep, I rebuilt my circuit to use the Mayfly’s onboard ADS1115 via voltage dividers, but got the same results; my sleep current is still around 6 mA. However, I discovered that if I disconnect the Turner’s wiper trigger wire from D10, sleep current drops to around 0.5mA.
To initiate the Turner’s wiper cycle, you pulse its trigger line low for 50 milliseconds. My TurnerTurbidityPlus class (code below) derives from Sensor, and its setup() method sets the D10 pin high; then when it’s time for a measurement, its wake() function sets D10 low, delays 50 milliseconds, and sets it back to high. Is this code causing the current drain, and how can I eliminate it?
-Matt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
/** * @file TurnerTurbidityPlus.cpp * @copyright 2020 Stroud Water Research Center * Part of the EnviroDIY ModularSensors library for Arduino * @author Sara Geleskie Damiano <sdamiano@stroudcenter.org> * Adapted from TurnerCyclops by Matt Barney <mbarney@tu.org> * @brief Implements the TurnerTurbidityPlus class. */ #include "TurnerTurbidityPlus.h" #include <Adafruit_ADS1015.h> // The constructor - need the power pin, the data pin, and the calibration info TurnerTurbidityPlus::TurnerTurbidityPlus(int8_t powerPin, int8_t wiperTriggerPin, adsDiffMux_t adsDiffMux, float conc_std, float volt_std, float volt_blank, uint8_t i2cAddress, adsGain_t PGA_gain, uint8_t measurementsToAverage, float voltageDividerFactor) : Sensor("TurnerTurbidityPlus", TURBIDITY_PLUS_NUM_VARIABLES, TURBIDITY_PLUS_WARM_UP_TIME_MS, TURBIDITY_PLUS_STABILIZATION_TIME_MS, TURBIDITY_PLUS_MEASUREMENT_TIME_MS, powerPin, -1, measurementsToAverage) { _wiperTriggerPin = wiperTriggerPin; _adsDiffMux = adsDiffMux; _conc_std = conc_std; _volt_std = volt_std; _volt_blank = volt_blank; _i2cAddress = i2cAddress; _PGA_gain = PGA_gain; _voltageDividerFactor = voltageDividerFactor; } // Destructor TurnerTurbidityPlus::~TurnerTurbidityPlus() {} String TurnerTurbidityPlus::getSensorLocation(void) { #ifndef MS_USE_ADS1015 String sensorLocation = F("ADS1115_0x"); #else String sensorLocation = F("ADS1015_0x"); #endif sensorLocation += String(_i2cAddress, HEX); sensorLocation += F("_adsDiffMux"); sensorLocation += String(_adsDiffMux); return sensorLocation; } void TurnerTurbidityPlus::runWiper() { // Turner Tubidity Plus wiper requires a 50ms LOW signal pulse to trigger one wiper rotation. // Also note: I was unable to trigger multiple rotations without pausing for ~540ms between them. MS_DBG(F("Initate TurbidityPlus wiper on"), getSensorLocation()); digitalWrite(_wiperTriggerPin, LOW); delay(50); digitalWrite(_wiperTriggerPin, HIGH); // It takes ~7.5 sec for a rotation to complete. Wait for that to finish before continuing, // otherwise the sensor will get powered off before wipe completes, and any reading taken // during wiper cycle is invalid. delay(8000); MS_DBG(F("TurbidityPlus wiper cycle should be finished")); } bool TurnerTurbidityPlus::setup(void) { // Set up the wiper trigger pin, which is active-LOW. pinMode(_wiperTriggerPin, OUTPUT); digitalWrite(_wiperTriggerPin, HIGH); return Sensor::setup(); } bool TurnerTurbidityPlus::wake(void) { // Run the wiper before taking a reading runWiper(); return Sensor::wake(); } bool TurnerTurbidityPlus::addSingleMeasurementResult(void) { // Variables to store the results in float adcVoltage = -9999; float calibResult = -9999; // Check a measurement was *successfully* started (status bit 6 set) // Only go on to get a result if it was if (bitRead(_sensorStatus, 6)) { MS_DBG(getSensorNameAndLocation(), F("is reporting:")); // Create an Auxillary ADD object // We create and set up the ADC object here so that each sensor using // the ADC may set the gain appropriately without effecting others. #ifndef MS_USE_ADS1015 Adafruit_ADS1115 ads(_i2cAddress); // Use this for the 16-bit version #else Adafruit_ADS1015 ads(_i2cAddress); // Use this for the 12-bit version #endif // ADS Library default settings: // - TI1115 (16 bit) // - single-shot mode (powers down between conversions) // - 128 samples per second (8ms conversion time) // - 2/3 gain +/- 6.144V range (limited to VDD +0.3V max) // - TI1015 (12 bit) // - single-shot mode (powers down between conversions) // - 1600 samples per second (625µs conversion time) // - 2/3 gain +/- 6.144V range (limited to VDD +0.3V max) ads.setGain(_PGA_gain); // Begin ADC ads.begin(); // Print out the calibration curve MS_DBG(F(" Input calibration Curve:"), _volt_std, F("V at"), _conc_std, F(". "), _volt_blank, F("V blank.")); // Read Analog to Digital Converter (ADC) // Taking this reading includes the 8ms conversion delay. // We're using the ADS1115 library's voltsPerBit() to do the bit-to-volts conversion // for us adcVoltage = ads.readADC_Differential(_adsDiffMux) * ads.voltsPerBit() * _voltageDividerFactor; // Getting the reading MS_DBG(F(" ads.readADC_Differential("), _adsDiffMux, F("):"), String(adcVoltage, 3)); // The ADS1X15 outputs a max value corresponding to Vcc + 0.3V if (adcVoltage < 5.3 && adcVoltage > -0.3) { // Skip results out of range // Apply the unique calibration curve for the given sensor calibResult = (_conc_std / (_volt_std - _volt_blank)) * (adcVoltage - _volt_blank); MS_DBG(F(" calibResult:"), String(calibResult, 3)); } else { // set invalid voltages back to -9999 adcVoltage = -9999; } } else { MS_DBG(getSensorNameAndLocation(), F("is not currently measuring!")); } verifyAndAddMeasurementResult(TURBIDITY_PLUS_VAR_NUM, calibResult); verifyAndAddMeasurementResult(TURBIDITY_PLUS_VOLTAGE_VAR_NUM, adcVoltage); // Unset the time stamp for the beginning of this measurement _millisMeasurementRequested = 0; // Unset the status bits for a measurement request (bits 5 & 6) _sensorStatus &= 0b10011111; if (adcVoltage < 5.3 && adcVoltage > -0.3) { return true; } else { return false; } } |