Arduino Yun skipping seconds

I have started to make a clock with Arduino and I'm using the Yun to get the time. I'm running the "TimeCheck" example that prints the current time to the serial monitor and I've noticed that it skips seconds. From the serial monitor:
2:12:13
2:12:15
2:12:16
2:12:17
2:12:18
2:12:19
2:12:20
2:12:21
2:12:22
2:12:23
2:12:24
2:12:26

It skiped 14 and 25.

Please Help!
Thanks!

It is not meant to be an accurate time keeper. It is an example using date(1) and string parsing.

Please do NOT write "help!" We do not know what your goals is, so this message looks like noise. What are you trying to do?

Jesse

jessemonroy650:
It is not meant to be an accurate time keeper. It is an example using date(1) and string parsing.

Please do NOT write "help!" We do not know what your goals is, so this message looks like noise. What are you trying to do?

Jesse

Say what ???

Getting output every second should not be a burden for even the slowest processor and it does not matter what you trying to do. You made pretty clear case explaining what does not work.
.
Can you blink the LED 13 every second?
Can you print Serial.print(miliss() every 1000 ms?
Maybe the string class is really that bad as everybody is saying.
Just for laughs - can you SLOW down your COM baud rate and experience similar problem ?
Or put the clock output into a for loop and output SAME time 10 times and see what you get?

Or maybe this "sample code" is using delay()???

Why is this form replacing question marks with smiley faces?

Vaclav:
Getting output every second should not be a burden for even the slowest processor and it does not matter what you trying to do.

True, it should not be a burden, as long as you do things efficiently. If you write bloated inefficient code, you will have trouble doing it all in the time you want.

The example shows how a sketch can run a command on the Linux side, get the information back into the sketch, and then parse it. It is not written to be an efficient way to display the time and not miss any updates.

If you wanted to keep track of the time at home, but you don't know the correct time, which would be more efficient:

  • Run over to your neighbor's house, read the time, then run home. Repeat running over to your neighbor every second to see the current time.
  • run over to your neighbor's house, read the time, set your watch, then run home. Then stay home and keep looking at your watch for the current time

That second option would be a lot more efficient, wouldn't it? Well, the example code is doing the first option.

Why is this form replacing question marks with smiley faces?

Because using three question marks at the end of a sentence is not good grammatical form. So, the forum uses that as a shortcut for inserting a confused smiley face. Just as a semicolon followed by a closing parenthesis puts in a wink and a colon and open parenthesis inserts a frown.

Vaclav:
Maybe the string class is really that bad as everybody is saying.

There is no "string" class, so no-one is saying it is bad.

Vaclav:
Getting output every second should not be a burden for even the slowest processor and it does not matter what you trying to do. You made pretty clear case explaining what does not work.

It is not a problem related to string class or computational power. Between asking for date and receiving it there is the bridge protocol, and there is the date command execution. That command is executed by an operating system that sometimes can be busy and can give you the output with a little delay, enough to skip a second.

Angelo9999:
It is not a problem related to string class or computational power. Between asking for date and receiving it there is the bridge protocol, and there is the date command execution. That command is executed by an operating system that sometimes can be busy and can give you the output with a little delay, enough to skip a second.

Thanks,
It is always nice to get the real answer from someone who did the research.
Kudos

@nick13579,
Did you get your question answer? Did you have a goal in mind?
Jesse

@Vaclav
There are no delays within the code.

Move most business logic into AR9331 instead of ATmega32u4 .

#include <Process.h>
Process p;                    // process used to get the date
void setup() {
  Bridge.begin();        // initialize Bridge
  Serial.begin(9600);    // initialize serial
  while (!Serial);              // wait for Serial Monitor to open
  Serial.println("Time Check");  // Title of sketch
}
void loop() {
  p.runShellCommand("date +%H:%M:%S");  // command you want to run
  while (p.available() > 0) {
    char c = p.read();
    Serial.print(c);
  }
  //Serial.println();
  delay(500);
}
17:31:22
17:31:22
17:31:23
17:31:24
17:31:24
17:31:25
17:31:25
17:31:26

if one second per output is required, wrote that business logic into shell script or python.

AR9331: 400Mhz/32bits CPU
ATmega32u4: 16Mhz/8bits MCU

Up to hundred time performance difference.

@sonnyyu, does that code "Move most business logic into AR9331 instead of ATmega32u4 ."?

nick13579:
@sonnyyu, does that code "Move most business logic into AR9331 instead of ATmega32u4 ."?

Yes.

@sonnyyu, so would I put my code inside the while loop?

Post your code, please.

#include <Process.h>
Process p;                    // process used to get the date
void setup() {
 Bridge.begin();        // initialize Bridge
 Serial.begin(9600);    // initialize serial
 while (!Serial);              // wait for Serial Monitor to open
}
void loop() {
 p.runShellCommand("date +%H%M%S");  // command you want to run
 while (p.running()); //Wait it complete
 String result = "";
 while (p.available() > 0) {
   char c = p.read();
   result = result + c;
   //Serial.print(c);
 }
 Serial.println(result);
 //displayNumber( (int) result)
 delay(500);
}
void displayNumber( int number)
{
// displayNumber
}

@Sonnyyu
Would I be able to use two process things(don't know what it's called), like:

Process date; //One I want to use
Process p; //One from your code

The Arduino language is based on C/C++, make sure don't use C/C++ key word.

p is much safe, but date might be OK. test it yourself.

nick13579:
Would I be able to use two process things(don't know what it's called)

"Process" is a class, a type definition. It's basically a definition of how the object should behave.

"date" and "p" are both instances of an object, of type Process.

A class describes what a thing is and what it can do, while the object represents the actual thing. Think of it like "ArduinoProgrammer" is the class: it describes a particular type of person with certain capabilities. "nick13579", "sonnyyu", and "ShapeShifter" are objects, they are actual instances of the "ArduinoProgrammer" class.

Yes, you can have two objects of type Process, and they will behave independently of each other. Just like you can have multiple instances of int or byte variables. I have a sketch which simultaneously runs four Process objects at the same time, all running the same Python code on the Linux side, but with different parameters. They all four run at the same time, but independently of each other (it's like they don't know the other instances exist.)

For some reason my Arduino yun can't connect to the internet anymore. I tried to use an Ethernet cable but that doesn't work. I'm using an app called Fing to find it but the yun doesn't show up.

Nevermind I got it back online.