- This topic has 3 replies, 2 voices, and was last updated 3 years, 9 months ago by Sylvester Dzimiri.
-
AuthorPosts
-
February 25, 2021 at 11:42 pm #1478Stacy OkaiParticipant
What are some programming methods for keeping track of time, or determining how long multiple events have happened between start and end? This was a problem that was faced over the course of the data logging project.
February 26, 2021 at 1:41 am #1486Sylvester DzimiriParticipantI am not sure if you guys looked into the RTC library. You can use the DS1307 Real Time Clock breakout, you will need to install the library from GitHub to begin working with that.
https://github.com/adafruit/RTClib
https://www.adafruit.com/product/264This is also the RTC library (https://www.arduino.cc/en/Reference/RTC) and it has some examples to start with.
February 27, 2021 at 11:09 am #1638Stacy OkaiParticipantHi Sylvester, thanks for your suggestion. Two of the data loggers that were used actually have a built-in RTC(DS1307), and the third logger uses an RTC module. The appropriate libraries were also installed for RTC usage.
You can check out the code on our blog post titled “Data Logging with the Nano Shield – Testing – Programming and Results – Version 1.”
Here is the link:
Data Logging with the Nano Shield – Final Test Circuit-Programming and Results (Version 1)
The main problem was trying to use the RTC and/or code the program in such a way that when each event/case took place, the duration of time the event occurred would be documented. For example, if a red LED was on in a forward case from 5:36:05 to 5:38:09, we would want to print the difference of 2 minutes 4 seconds (00:02:04).
I also tried implementing the “millis” function, during the coding phase, and had no success.
I appreciate your help!!
February 27, 2021 at 5:04 pm #1640Sylvester DzimiriParticipantHey Stacy, Thanks for the link; such a great post. You are right that you can use the “millis” function. This is what I used in my project to see how much time has passed before sending sensor data. I have attached some of the snippet code on how I instantiated the millis object and keep track of the time. I think you also want to do something along those lines.
//initialize times gas_time = millis(); flame_time = millis(); pir_time = millis(); sound_time = millis(); temperature_time = millis(); ultrasonic_time = millis(); //PIR sensor pinMode(PirInput, INPUT); } void loop() { // put your main code here, to run repeatedly: unsigned long time_passed = 0; //device #2 //read gas sensor // don't read analog pins too often (<1Hz), else caps never get to charge. time_passed = millis() - gas_time; //if roll over, send next value again if (time_passed < 0) { gas_time = millis(); gas_time_send = -700000; }
I hope that might be helpful. I am sure you also read their documentation but I am attaching the link (https://www.arduino.cc/reference/en/language/functions/time/millis/)
-
AuthorPosts
- You must be logged in to reply to this topic.