Go Down

Topic: How to display current time in Hour Minute Second Millisecond format in arduino? (Read 7397 times) previous topic - next topic

abujuguluy

Hello guys, how can I display current time in Arduino? I have tried using mills() but it only shows the date since reboot of the arduino in milliseconds, how do I get the current time in HH:MM:SS:Milliseconds? not the time after the last reboot

TomGeorge

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html 

You will need a RealTimeClock ,RTC, to keep the real time for you so that when you boot the Arduino it can read the RTC and display it.

What model Arduino are you using?

These links may help;
https://www.freetronics.com.au/pages/rtc-real-time-clock-module-quickstart-guide#.WuAQ_C5MTIU
https://howtomechatronics.com/tutorials/arduino/arduino-ds3231-real-time-clock-tutorial/

Tom... :)
Everything runs on smoke, let the smoke out, it stops running....

lastchancename

You need an RTC that retains timekeeping between restarts.
e.g. DS1307 or DS3231 + battery
The Arduino has no awareness of where the sun, planets and moon are positioned.

Going upscale a bit, you could use NTP or cellular time.
Experienced responders have a nose for laziness, (they were beginners once)... Sure, there are trolls, chest-beaters, and pretenders - but the help you'll get here is about as good as it gets - if you try to help youself!.

larryd

First off, to get real time, you need an RTC.
A DS3231 is a good choice.

You should probably review this link.
https://playground.arduino.cc/Code/Time


Library from here:
https://github.com/PaulStoffregen/Time/tree/master/examples

Try 'TimeSerial' example
Use T1357041600 to set the time, change as needed.



You would need to set the time for the above to work.
https://www.epochconverter.com/



But you really need to look at an RTC if you want things to work over a power up/fail condition.




No technical PMs.
The last thing you did is where you should start looking.

abujuguluy

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html

You will need a RealTimeClock ,RTC, to keep the real time for you so that when you boot the Arduino it can read the RTC and display it.

What model Arduino are you using?

These links may help;
https://www.freetronics.com.au/pages/rtc-real-time-clock-module-quickstart-guide#.WuAQ_C5MTIU
https://howtomechatronics.com/tutorials/arduino/arduino-ds3231-real-time-clock-tutorial/

Tom... :)

hello sir, sorry for the bad posting. I am using arduino UNO, how about the log command in gobetwino? I can save the time stamp in Month/Date/Year Hour:Minute:Second format using the log command in gobetwino but how do i add the milliseconds?

i think here's the code

Code: [Select]
void readSerialString (char *strArray,long timeOut)
{
   long startTime=millis();
   int i;

   while (!Serial.available()) {
      if (millis()-startTime >= timeOut) {
         return;
      }
   }
   while (Serial.available() && i < serInLen) {
      strArray[i] = Serial.read();
      i++;
   }
}

abujuguluy

First off, to get real time, you need an RTC.
A DS3231 is a good choice.

You should probably review this link.
https://playground.arduino.cc/Code/Time


Library from here:
https://github.com/PaulStoffregen/Time/tree/master/examples

Try 'TimeSerial' example
Use T1357041600 to set the time, change as needed.



You would need to set the time for the above to work.
https://www.epochconverter.com/



But you really need to look at an RTC if you want things to work over a power up/fail condition.





is there no other way to do that without a RTC?

TomGeorge

Hi,
Quote
I can save the time stamp in Month/Date/Year Hour:Minute:Second format using the log command in gobetwino but how do i add the milliseconds?
The manual for Gobetwino,says that it only works to seconds, why do you need milliseconds?

https://playground.arduino.cc/Interfacing/GoBetwino

Tom.. :)
Everything runs on smoke, let the smoke out, it stops running....

abujuguluy

Hi,The manual for Gobetwino,says that it only works to seconds, why do you need milliseconds?

https://playground.arduino.cc/Interfacing/GoBetwino

Tom.. :)
Hi,The manual for Gobetwino,says that it only works to seconds, why do you need milliseconds?

https://playground.arduino.cc/Interfacing/GoBetwino

Tom.. :)
I need milliseconds because the time I am saving is the message sent time which needs milliseconds because I am using gsm in arduino to send it. And the delay of the messages must be Less than 1 second.

larryd

is there no other way to do that without a RTC?
You can use the Time library for hr min sec etc. but not ms.

Don't know of a way to get what you want.



No technical PMs.
The last thing you did is where you should start looking.

lastchancename

Quote
because I am using gsm in arduino to send it. And the delay of the messages must be Less than 1 second.
Any messages sent over the cellular network are nowhere near millisecond accuracy.
I'd be happy if it was under 1 second in most cases.
So many places where buffering and retries will occur that are out of your control.
Experienced responders have a nose for laziness, (they were beginners once)... Sure, there are trolls, chest-beaters, and pretenders - but the help you'll get here is about as good as it gets - if you try to help youself!.

Go Up