5 Replies Latest reply on Jul 29, 2016 2:41 PM by FGT

    use of rtc present on Galileo gen 2

    nayan.naveen

      i am new on Intel Galileo gen 2 .i am trying to use rtc for my project to measure temperature at any time interval

      but i am unable to use it.help me how to use rtc.

        • 1. Re: use of rtc present on Galileo gen 2
          Intel Corporation
          This message was posted on behalf of Intel Corporation

          Hello nayan.naveen,
           
          I'm not sure I understand what you're trying to do. Would you like to create a "log file" that stores both the temperature and the time of that reading? Is that right? If so, then this shouldn't be that hard if you've already got the temperature reading part. Assuming that you do, then you can simply create a file that stores both the temperature reading and the current date.
           
          The current date can be accessed through a system call on your code, how that is achieve depends on the language you are using.
          Could you please share with us your code? This would help us provide you an example of how to make a system call.
           
          -Peter.

          • 2. Re: use of rtc present on Galileo gen 2
            nayan.naveen

            Sir,

            you are right i am trying to create a log file to measure temperature at 1 min interval and save it to sdcard used in galileo .

            i am using LM35 for the purpose to measure temperature and and saved it to the sdcard providing some delay in my program.

            but i want to use rtc on Galileo to save temperature every minute.

            this is my code to  measure temperature and save it  to my sdcard

             

            /*
            * read temperature using LM35 from environment and save it to sdcard
            * card every second and read it again from sd card
            */
            #include <SD.h>
            File myFile;
            
            int   reading;
            int   LM35Feed = A0;
            float tCelsius;
            float tFahrenheit;
            float tKelvin;
            float millivolts;
            
            void setup()
            {
                Serial.begin(9600);
                  while (!Serial);
                 // wait for serial port to connect.
            }
            
            void loop()
            {
              for(int i=0;i<20;i++)
              {
                reading = analogRead(LM35Feed);
                millivolts= (reading/1024.0) * 5000;
                tCelsius = millivolts/10; //LM 35 Equation
                tFahrenheit= ( tCelsius * (9/5) ) + 32;
                tKelvin = tCelsius+273.15;
            
                sdWrite(tCelsius);
                sdWrite(tFahrenheit);
                sdWrite(tKelvin);
                delay(2000);
              }
              sdRead();
            }
            
            
            void sdWrite(float value)
            {
              myFile = SD.open("data.txt", FILE_WRITE);
              if (myFile) {
                myFile.println(value);
                myFile.close();
              } else {
                Serial.println("error opening test.txt");
              }
            }
            
            void sdRead()
            {
              myFile = SD.open("test.txt");
              if (myFile) {
                Serial.println("test.txt:");
                while (myFile.available()) {
                    Serial.write(myFile.read());
                }
                myFile.close();
              } else { 
                Serial.println("error opening test.txt");
              }
            }
            

             

            i have also used a code to set rtc on Galileo.

            • 3. Re: use of rtc present on Galileo gen 2
              Intel Corporation
              This message was posted on behalf of Intel Corporation

              I was not aware you were working in the Arduino environment. Nevertheless, as I mentioned this could be easily solved with a system call. 
              So, you let's assume you have just finished reading a value from your sensor, then you open a file, store the reading on this file and then you close the file, right? 
              After this you can make a system call that adds the current date of your board's system to the last line of your file. So, the command you should use would look like the following:

              system("echo -n $(date) >> /media/mmcblk0p1/test.txt");

              The path you see there is where your file is currently stored and this might change depending on your code. I'm assuming that you stored it the root of your SD Card so I added the path for the SD Card.

              Let me know if this helps.
              -Peter.

              • 4. Re: use of rtc present on Galileo gen 2
                Intel Corporation
                This message was posted on behalf of Intel Corporation

                Hi nayan.naveen,

                Do you have any updates about this? Do you still need help?

                -Peter.

                • 5. Re: use of rtc present on Galileo gen 2
                  FGT

                  Hi nayan.naveen,

                   

                  Your code looks a little bit strange to me...:

                   

                  a) Do you really want/need to print all the saved data every 20 samples?

                  voidloop()

                  {

                    for(inti=0;i<20;i++)

                    {

                        ... // writing samples here

                    }

                    sdRead();

                  }

                   

                  b) The file will have only one sample, because you open the file for writing;

                  ...

                  voidsdWrite(floatvalue)

                  {

                    myFile=SD.open("data.txt",FILE_WRITE);

                    ...

                  }

                  Thus, every time the file is open an empty file is created. You should open in "append mode", not in "write mode".

                   

                  c) do you really need an RTC?  I think that using

                   

                  delay(60000);

                   

                  would be enough for 1 minute interval...

                   

                  If you need to record timestamps as well as samples, then you can use Peter suggestion.

                   

                  HTH,

                   

                  Fernando.