Home › Forums › Mayfly Data Logger › Atlas Scientific Logger – Sleep between readings › Reply To: Atlas Scientific Logger – Sleep between readings
2020-10-26 at 2:13 PM
#14715
It looks like this code was based on one of our old sleeping Mayfly logger example sketches, but there’s some stuff in the main Loop that is out of order. I’m assuming you’ve got th
It looks like this code was based on one of our old sleeping Mayfly logger example sketches, but there’s some stuff in the main Loop that is out of order. I’m assuming you’ve got the Atlas sensors connected to the I2C Grove port on the Mayfly. If you want to be able to switch their power on and off, then you need to move the small jumper on the headers pins next to those Grove ports to the 3.3v-SWITCHED position. Then you need to turn on the sensor power pin (D22) on and off in your code. Pin D8 is the green LED and your code sets it low once but never does anything else with it. I typically turn the green LED on when the board is awake and taking a reading, to let the use know that something is happening. You’ll also see the red LED by the Grove sockets turn on when the switched power is turned on, too. You’ve also got to run the sensor sampling function while the sensor power is on, and in your code you’ve got that happening after everything, including writing the data. I didn’t go through the entire sketch to look for all problems, but I think fixing a few things in the main Loop will get you most of the way to solving your issue. Here’s how I would write that section, but you might want to change it based on your goals.
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 |
void loop() { //Update the timer timer.update(); if(currentminute % sleepMinutes == 0) // change "2" to "5" to wake up logger every 5 minutes instead { Serial.println("Multiple of 1! Initiating sensor reading and logging data to SDcard...."); digitalWrite(8, HIGH); // turn the Green led pin on digitalWrite(22, HIGH); // turn the switched power on delay(5000); //wait 5 seconds for the sensors to stabilize? getdata(); //take readings from the Atlas sensors digitalWrite(22, LOW); //turn the switched power off digitalWrite(8, LOW); //turn the green LED off String dataRec = createDataRecord(); //puts timestamp and sensor data into a string logData(dataRec); //Save the data record to the log file Serial.println(dataRec); //Echo the data to the serial connection } delay(1000); systemSleep(); } |