diff --git a/mini-beieli-node.ino b/mini-beieli-node.ino index 0b171f3..35ee056 100644 --- a/mini-beieli-node.ino +++ b/mini-beieli-node.ino @@ -9,7 +9,7 @@ */ // HX711: 0 => compile for hx711, 1 => compile for NAU7802 -#define HX711 1 +#define HX711 0 #include @@ -752,10 +752,14 @@ void StartNewIteration() { if (!fUsbPower) { DoDeepSleep(sleep_time_sec); - os_setTimedCallback( - &iterationJob, - os_getTime() + sec2osticks(2), - startNewIterationCb); + if (! stop_iterations) { + StartNewIteration(); + } + + //os_setTimedCallback( + // &iterationJob, + // os_getTime() + sec2osticks(2), + // startNewIterationCb); } else { if (config_data.debug_level > 0) { @@ -947,7 +951,7 @@ void doSleepAlert(const bool fDeepSleep) } // sleep and print - if (config_data.debug_level > 2) { + if (config_data.debug_level > 1) { gLed.Set(LedPattern::TwoShort); } @@ -1047,7 +1051,10 @@ void doLightSleep(osjob_t *pJob) { uint32_t interval = sec2osticks(CATCFG_GetInterval(gTxCycle)); - gLed.Set(LedPattern::Sleeping); + + if (config_data.debug_level > 1) { + gLed.Set(LedPattern::Sleeping); + } if (gCatena.GetOperatingFlags() & static_cast(gCatena.OPERATING_FLAGS::fQuickLightSleep)) @@ -1055,7 +1062,6 @@ void doLightSleep(osjob_t *pJob) interval = 1; } - gLed.Set(LedPattern::Sleeping); os_setTimedCallback( &iterationJob, os_getTime() + interval, diff --git a/mini_beieli_node_nau7802.h b/mini_beieli_node_nau7802.h index 5bdf7d3..57a0dde 100644 --- a/mini_beieli_node_nau7802.h +++ b/mini_beieli_node_nau7802.h @@ -17,25 +17,38 @@ byte interruptPin = A0; bool SetupScales(byte dbg_level) { debug_level = dbg_level; - + if (debug_level > 0) { + gCatena.SafePrintf("%010d - SetupScales start\n", millis()); + } pinMode(interruptPin, INPUT); Wire.begin(); if (!myScale.begin()) { - Serial.println("Scale not detected. Please check wiring. Freezing..."); + gCatena.SafePrintf("Scale not detected. Please check wiring. Freezing...\n"); return false; } - Serial.println("Scale detected!"); + gCatena.SafePrintf("Scale detected!\n"); myScale.setIntPolarityHigh(); - delay(500); + + myScale.clearBit(NAU7802_PGA_PWR_PGA_CAP_EN, NAU7802_PGA_PWR); + myScale.setSampleRate(NAU7802_SPS_80); + myScale.setLDO(NAU7802_LDO_3V3); + + if (debug_level > 0) { + gCatena.SafePrintf("%010d - SetupScales done\n", millis()); + } return true; } long ReadScale(char channel) { + if (debug_level > 0) { + gCatena.SafePrintf("%010d - ReadScale Start\n", millis()); + } + uint8_t channelNumber; if (channel == 'B') { channelNumber = NAU7802_CHANNEL_1; @@ -44,11 +57,7 @@ long ReadScale(char channel) } long startTime = millis(); myScale.setChannel(channelNumber); - myScale.clearBit(NAU7802_PGA_PWR_PGA_CAP_EN, NAU7802_PGA_PWR); - myScale.setSampleRate(NAU7802_SPS_10); - myScale.setLDO(NAU7802_LDO_2V7); myScale.calibrateAFE(); - //delay(500); long res; int const num_scale_readings = SAMPLES; // number of instantaneous scale readings to calculate the median @@ -83,17 +92,37 @@ long ReadScale(char channel) gCatena.SafePrintf("Standard Deviation: %d.%03d\n", (int)sdev, (int)abs(sdev * 1000) % 1000); gCatena.SafePrintf("Standard Deviation / Median (Percent): %d.%03d\n", (int)sdev_proc, (int)abs(sdev_proc * 1000) % 1000); gCatena.SafePrintf("Duration (ms): %d\n", duration); - } + } + + if (debug_level > 0) { + gCatena.SafePrintf("%010d - ReadScale Done\n", millis()); + } return res; } void PowerdownScale() { + if (debug_level > 0) { + gCatena.SafePrintf("%010d - PowerdownScale Start\n", millis()); + } myScale.powerDown(); + if (debug_level > 0) { + gCatena.SafePrintf("%010d - PowerdownScale Done\n", millis()); + } } void PowerupScale() { + if (debug_level > 0) { + gCatena.SafePrintf("%010d - PowerupScale Start\n", millis()); + } myScale.powerUp(); //Power up scale. This scale takes ~600ms to boot and take reading. + + // we wait 100 ms to give it time to stabilze + delay(100); + + if (debug_level > 0) { + gCatena.SafePrintf("%010d - PowerupScale Done\n", millis()); + } }