element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Vertical Farming
  • Challenges & Projects
  • Design Challenges
  • Vertical Farming
  • More
  • Cancel
Vertical Farming
Blog Automated Green House Blog:9.1 - Updated uptime counter
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: m.ratcliffe
  • Date Created: 12 Sep 2015 4:37 PM Date Created
  • Views 806 views
  • Likes 1 like
  • Comments 2 comments
  • adapted_greenhouse
  • arduino
Related
Recommended

Automated Green House Blog:9.1 - Updated uptime counter

m.ratcliffe
m.ratcliffe
12 Sep 2015

This doesnt really deserve to be a blog, So it is 9.1 and a supplement to blog 9:

Automated Green House Blog:9 -  Some Generic Arduino Tricks - SRam - UpTime

 

Here is an updated uptime counter that makes life a little simpler

Header 1

/* This Script is the bare bones needed to Keep a Uptime counter that will survive the 50 day timer rollover

This will not give a uptime of great accuracy over long periods, but it will let you see if your arduino has reset

if you want better accuracy, pull the Unix time from the IOT, External RTC or GPS module

Also Reconnecting the serial com's will reset the arduino. So this is mainly useful for a LCD screen

 

 

Michael Ratcliffe  Mike@MichaelRatcliffe.com

   

    This program is free software: you can redistribute it and/or modify

    it under the terms of the GNU General Public License as published by

    the Free Software Foundation, either version 3 of the License, or

    (at your option) any later version.

 

 

    This program is distributed in the hope that it will be useful,

    but WITHOUT ANY WARRANTY; without even the implied warranty of

    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the

    GNU General Public License for more details.

 

 

    You should have received a copy of the GNU General Public License

    along with this program.  If not, see <http://www.gnu.org/licenses/>.

 

 

   

*/

 

 

//************************** Just Some basic Definitions used for the Up Time LOgger ************//

long Day=0;

int Hour =0;

int Minute=0;

int Second=0;

int HighMillis=0;

int Rollover=0;

 

 

 

 

//************** Setup routine - Runs once at power up **************************//

void setup(){

Serial.begin(9600); // starting Serial Com's

 

};

 

 

//****** Main Loop - Put your Code Here ********************//

void loop(){

 

uptime(); //Runs the uptime script located below the main loop and reenters the main loop

print_Uptime();

delay(500);

};

 

 

 

 

 

 

//************************ Uptime Code - Makes a count of the total up time since last start ****************//

 

 

void uptime(){

//** Making Note of an expected rollover *****//  

if(millis()>=3000000000){

HighMillis=1;

 

 

}

//** Making note of actual rollover **//

if(millis()<=100000&&HighMillis==1){

Rollover++;

HighMillis=0;

}

 

 

long secsUp = millis()/1000;

 

 

Second = secsUp%60;

 

 

Minute = (secsUp/60)%60;

 

 

Hour = (secsUp/(60*60))%24;

 

 

Day = (Rollover*50)+(secsUp/(60*60*24));  //First portion takes care of a rollover [around 50 days]

                      

};

 

 

//******************* Prints the uptime to serial window **********************//

void print_Uptime(){

 

  Serial.print(F("Uptime: ")); // The "F" Portion saves your SRam Space

  Serial.print(Day);

  Serial.print(F("  Days  "));

  Serial.print(Hour);

  Serial.print(F("  Hours  "));

  Serial.print(Minute);

  Serial.print(F("  Minutes  "));

  Serial.print(Second);

  Serial.println(F("  Seconds"));

};

  • Sign in to reply
Parents
  • DAB
    DAB over 9 years ago

    Looks like a good start.

     

    Have you considered using a RTC chip so that you can off load the timing and just read updates?

     

    DAB

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • m.ratcliffe
    m.ratcliffe over 9 years ago in reply to DAB

    You are correct Dab, It is recommend to use time pulled from a RTC, GPS or internet for any critical projects.


    In the main system I am pulling the time via an ethernet shield and shooting a warning email saying the system has reset in the setup() loop. I included this for anyone needing a estimate of uptime with no extra hardware handy but a need to know if a system has recently reset [ie the water meter total volume measurements in another blog].

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Comment
  • m.ratcliffe
    m.ratcliffe over 9 years ago in reply to DAB

    You are correct Dab, It is recommend to use time pulled from a RTC, GPS or internet for any critical projects.


    In the main system I am pulling the time via an ethernet shield and shooting a warning email saying the system has reset in the setup() loop. I included this for anyone needing a estimate of uptime with no extra hardware handy but a need to know if a system has recently reset [ie the water meter total volume measurements in another blog].

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube