We just finished the last of a series of tests of the Maxbotix. With the changes which Sara suggested (close the serial port after each log interval and restart it for each new consectutive interval), the sleep code does work if the sensor is continuously powered.
Setup: Maxbotix 7389 sensor with the target either stream water or a fixed/flat metal plate approx 1/2 meter on a side. Before all testing (with 2 sensors), the sensor faces were coated with a very thin coating of fluoropolymer grease (very hydrophobic) to help shed any condensation.
1. Sensor mounted over a standpipe in water. Ambient temperature near 20 C. Frequent bad data (300) with normal serial read using code originally supplied by Shannon Hicks. Sensor powered by Mayfly digital pin only when logging.
2. We suspected that there might be some interaction between the sensor and logger. Tried reading in the serial data with 50 milliseconds delay between each digit. This very slow read out of the data- have never seen this in the literature, gave a partial solution. This eliminated the bad data until fall when temperatures dropped down to about 10 C at night. Then bad data again occurred.
3. Sensor tested with a boom mount over the water or metal plate with intermittent power, but no standpipe. Results still showed some bad data points, even with traps to reread up to 20 times in the event of bad data. The bad data occurred at random times, when the temps were well above freezing and below freezing. The conclusion is that condensation on the sensor face is not the issue.
4. The final test was a 10 day test, 5 minute intervals, with sensor continuously powered independently by a separate battery power pack. During that time, the angle of the sensor from perpendicular to the target was varied from 0 degrees up to 5 degrees (to help shed potential condensation if any occurred). During that time, the temperatures ranged from as high as 15 C and as low as -5 C. Absolutely no bad data points were measured during the entire test.
a. We saw no evidence that the sensor had any issue related to condensation during the tests given that there was a hydrophobic coating on the sensor face and that the bad data occurred at random temperatures as opposed to only when the temperatures were low.
b. Reading out the serial data with a pause between digits rather than at normal speed seemed to help eliminate bad data when the weather was warm. But, this did not solve the problem when cooler weather arrived in the fall.
c. There was no bad data during the testing of the sensor with continuously power independent of the Mayfly, including at temperatures well below freezing.
Recommendation: If the Maxbotix 7389 sensor is used and a criterion is to log absolutely no bad data (such as when the data is used to control a pump sampler as we intend), it is recommended that sensor power be supplied continuously by an independent power pack.
I will be happy to forward or post data files if anyone wants to see the raw data.