Welcome to EnviroDIY, a community for do-it-yourself environmental science and monitoring. EnviroDIY is part of WikiWatershed, a web toolkit designed to help citizens, conservation practitioners, municipal decision-makers, researchers, educators, and students advance knowledge and stewardship of fresh water. New to EnviroDIY? Start here

Reply To: Plotting calculated values

Home Forums Monitor My Watershed Plotting calculated values Reply To: Plotting calculated values

Sara Damiano

The loop that requests values from sensors only queries sensors that have an associated variable in the variable list.  So if you don’t put the ds3231Temp in your variable list, the program will never actually ask the DS32321 for the temperature.  In that case, the value returned by ds3231Temp->getValue() in your calculation equation will just be whatever junk was in that memory slot when the board booted up.  You’re actually kind-of lucky the program ran instead of just crashing or locking up.

You can force a sensor update from within the calculated variable by calling getValue(true) – that is set the “updateValue” flag to true instead of letting it default to false.  This will give you a brand new value to do the calculation from, but you lose all of the timing optimizations that can happen when the getValue() is called from within the array instead of from within the calculation equation.  For something like the temperature from DS3231 (which is actually the real-time-clock) the process of getting a new value from the sensor takes a trivial amount of time, so you can just add the word true to your calculation equation, deleted the variable you don’t care about and call it done.  That’s what I recommend you do.

If you wanted to do it “right” and have the sensors all update in the array but only output the calculated result to MonitorMW you should do something like in the “data saving” example where you put the raw value in the full array but only the calculated value in the “to go” array.  That is what I would recommend if you wanted were using multiple sensors and wanted to do a calculation based on the results of a “slow” sensor like turbidity.  Doing it that way you would allow the VariableArray to attempt to optimize the order in which it gets values from sensors and then your calculation equation would use the value saved in memory when all the sensor are finished.  But what you’re gaining in speed of update and possibly long battery life is at the expense of having to understand and write out a large portion of the logging routine yourself.  Which is why, since you’re only talking about the DS3231, I would not recommend you bother.