Yun & RTC

Hello everyone,
I need to use a RTC on my Yun. Do you have any advice on which one to choose?

With the time available from the Linino I don't see why you want it but...

I have one of these: https://www.sparkfun.com/products/99, not too expensive or extremely accurate but with the NTP available on Linino it wouldn't be very hard to update it ever so often. When shopping consider whether the unit includes a battery it can cost as much as the RTC.

You would need to find a supplier a bit closer to you probably.

Hello noblepepper,
I have bought this: RTC SHIELD PER ARDUINO- IN KIT. I was impatient! XD
Is in the kit but it works well and is cheap.

I need a RTC to have the time even in the absence of Internet / NTP server.
I use the time of Linino to set the time of the RTC.

thanks

That looks like a good unit and price, the shield setup is much nicer than the breakout I have. Would you post the code you are using to set the RTC using the linino?

Sure! With pleasure…

#include <Process.h>
#include <Wire.h>
#include "RTClib.h"

RTC_DS1307 RTC;

void setup() {
  Serial.begin(9600);
  Wire.begin();

  Serial.print("Waiting for Linino boot");  
  for(int i=0;i<60;i++){
    Serial.print(".");
    delay(1000);
  }
  Serial.println("");

  Bridge.begin();
  
  RTC.begin();
  RTC.sqw(1);		//0 Led off - 1 Freq 1Hz - 2 Freq 4096kHz - 3 Freq 8192kHz - 4 Freq 32768kHz
  
  String DateL = "";
  String TimeL = "";
    
  Serial.print("Setting time zone... ");
  ProcExec("echo","'CET-1CEST,M3.5.0,M10.5.0/3' > /etc/TZ");
  Serial.println("done.");
  
  Serial.print("Syncing time with NTP... ");
  ProcExec("ntpd","-nqp 0.openwrt.pool.ntp.org");
  Serial.println("done.");
  Serial.println("");
  
  DateL = ProcExec("date","+%Y-%m-%d");
  Serial.print("Linino Date:");
  Serial.println(DateL);

  TimeL = ProcExec("date","+%T");  
  Serial.print("Linino Time:");
  Serial.println(TimeL);
  
  int dt[6];
  dt[0]=DateL.substring(0,4).toInt();
  dt[1]=DateL.substring(5,7).toInt();
  dt[2]=DateL.substring(8).toInt();
  dt[3]=TimeL.substring(0,2).toInt();
  dt[4]=TimeL.substring(3,5).toInt();
  dt[5]=TimeL.substring(6).toInt();
  
  RTC.adjust(DateTime(dt[0],dt[1],dt[2],dt[3],dt[4],dt[5]));
}

void loop() {
    DateTime now = RTC.now();
    
    Serial.print(now.year(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.day(), DEC);
    Serial.print(' ');
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();
    
    Serial.println();
    delay(3000);
    
}

String ProcExec(String Comm, String Par) {
  String Res = "";
  Process p;
  p.begin(Comm);
  p.addParameter(Par);
  p.run();

  while (p.available()>0) {
    char c = p.read();
    Res += c;
  }
  return Res;
}

I just found this code and I found that the setting of the time zone does not work. Turns out that pipes don't work with the "run" command. So instead to set the time zone. I used the "runShellCommand". I validated by reading the file with "cat".

Console.print("Setting time zone... ");
Process e;
//e.runShellCommand("echo 'EST5EDT,M3.2.0,M11.1.0' > /etc/TZ");
e.runShellCommand("echo 'PST8PDT,M3.2.0,M11.1.0' > /etc/TZ");
while(e.running());
Console.println("done.");

Console.print("Read time zone... ");
Process c1;
c1.begin("cat");
c1.addParameter("/etc/TZ");
c1.run();
while (c1.available()>0) {
char c = c1.read();
Console.print (c);
}
Console.println("done.");

hi. i’m using this script on my yun but how can i set the time zone to output the time for my country. the time zone i set in the web console is for Johannesburg south Africa

pieter1992:
hi. i'm using this script on my yun but how can i set the time zone to output the time for my country. the time zone i set in the web console is for Johannesburg south Africa

nano /etc/config/system
config system
        option hostname 'Arduino'
        option timezone 'SAST-2'
        option zonename 'Africa/Johannesburg'
root@Arduino:/# date
Sun Jan 10 04:06:54 SAST 2016

Plan B:

uci set system.@system[0].timezone=SAST-2
uci set system.@system[0].zonename=Africa/Johannesburg
uci commit system

check on ebay for DS3231, they are cheap and work well for me. Also includes a 32K (bits) memory chip which comes in useful

philgrocks:
Turns out that pipes don't work with the "run" command.

That makes sense. The redirection operator (it's not actually a pipe, that's "|" and used to pass output to another process, not a file) is handled by the command interpreter shell, which sets up the calling environment properly before starting the process. (In this case, it opens /etc/TZ, and sets it up so that echo's STDOUT points to that file.) The redirection (and pipe) operator is actually a parameter processed by the command shell.

When you use run(), it is simply launching echo, and passing the redirection operator and the file name to echo, which doesn't understand it. When you use runShellCommand(), it is actually launching an instance of the shell command processor, and passing the whole string to it. In this case, the shell sees the redirection operator and sets things up properly before it launches echo.

So there is indeed a valid reason to have both versions of run functions. Normally, using runShellCommand() just introduces overhead, but this is one case where the overhead is needed.

So instead to set the time zone. I used the "runShellCommand".

Isn't this a one time operation? Wouldn't it be a whole lot simpler to just type the command at the SSH shell prompt and be done with it?

echo 'PST8PDT,M3.2.0,M11.1.0' > /etc/TZ

Plan B;C:

sonnyyu:
RTC is required setup correct time initially.

Using GPS to update RTC and then re-adjust RTC for current timezone.

Using GPS to update RTC and then re-adjust RTC for current timezone. - Programming Questions - Arduino Forum

Using long wave time signal/synchronize with atomic clock

DCF77 out of range? - Sensors - Arduino Forum