2 Replies Latest reply on Aug 5, 2014 7:36 AM by SpiderKenny

    Accessing RTC via arduino code




      I want to gain more understanding on accessing the Galileo's RTC. Currently all I have seen is the system command being used to access the Linux OS and set and retrieve the time. This uses the following commands in Arduino:

      char buf[9];



      void setup() {



        system("date 010112002013"); //sets the date & time to 12:00 1st Jan 2013






      void loop() {


        system("date '+%H:%M:%S' > /home/root/time.txt");  //get current time in the format- hours:minutes:secs

                                                           //and save in text file time.txt located in /home/root

        FILE *fp;

        fp = fopen("/home/root/time.txt", "r");

        fgets(buf, 9, fp);



        Serial.print("The current time is ");







      I am unfamiliar with Linux and asuch do not really understand what is happening here. I need to establish a timer between two points in time. What resources are suggested for me to understand what is going on and how to make the RTC accessible to me?



        • 1. Re: Accessing RTC via arduino code

          There is a shift in thinking between boards like Arduino UNO and boards like Galileo, BeagleBone and R-PI.

          'Traditional' arduino boards have direct access to hardware resources such as IO, ADC, RTC and so on. In the Galileo, and others, there is an operating system in place.

          The operating system abstracts the hardware and users code cannot access hardware directly. (This is even true with GPIO on Galileo - your code is not directly setting registers on output ports in the processor, but is rather passing information to a kernel driver which access the hardware).


          So, in order to access hardware features, such as RTC, you need to understand how the Operating System makes them available to you.

          Galileo uses Linux as it's operating system and it has a rich and power set of features for accessing real time, elapsed time and for timing intervals in code.


          There is a fabulous book on Linux, which is extremely useful: The Linux Programming Interface

          Although not specific to Galileo it gives a great insight into how Linux works, and covers subjects such as timing in great depth.

          • 2. Re: Accessing RTC via arduino code

            If you are doing some serious work on Galileo, I would highly recommend ditching the Arduino IDE and getting to grips with one of the Linux distributions with Dev Tools included.

            You can then write native code directly targeting Linux, on Galileo.