14 Replies Latest reply on Aug 25, 2017 3:56 PM by Intel Corporation

    Edison Outputing Incorrect Values into a File

    PatriotWest252

      Hello everyone,

       

      I am currently having an issue with getting data at 100 hertz with the Edison. I am working with Vector Nav sensor and I have tried putting the asynchronous output to 100 hertz with a baud rate of 128000, yet the data collection seems to be to fast for the Edison to handle. Instead of getting the data I want for example (at 2 hertz):

      11537:ÿÿÿÿÿÿÿÿÿÿÿÿÿÿ$VNRRG,17,-00.4570,+00.0643,+00.2167*5F

      ÿÿÿÿÿÿÿÿÿÿÿÿÿÿ$VNRRG,72,-172.119,+000.415,+000.251,+00.00000000,+000.00000000,+00000.000,+000.000,+000.000,+000.000,+00.067,-00.035,-09.548,-00.000048,+00.000778,+00.001273*50

       

      I get (at 100 hertz):

       

      11126:€ € € € € € € € xøx€ € € €€x €      ? € € € xøx€ € € € € €€x € € € xøx€ € € €€x € € € xøx€ € € €€x € € € xøx€ € € €€x € € € xx€ €€x € x € €€x € x €€x € €€x€€ø€€€€x €x €€€xx€x€€x€x€x x € € € €€€€øø€€xxø€xø€ € € €x€ x € € € € x € € € € xxxx€øø€x€€x €x€ø€€

       

      After fixing the sensors baud rate and asynchronous output, I tried modifying my arduino program by setting: Serial1.begin(1280000) and then having an if statement that gets the time the program starts and subtracts it by when the program finishes the data collection and it has to have a greater integer than 9, since 1/100*1000 would give 10 milliseconds for 100 hertz. Here's what I have which works up to 20 hertz but after that all I get is junk values:

        void loop(){

      timenow = millis();   

      if(timenow-timeold > 9) //10 milis is 100 hertz. 

        {                                                                  

           //register 72 data

           delay(50);

      Serial1.println("$VNRRG,72*XX");

       

           delay(50);

      Serial1.println("$VNRRG,17*XX");

           Serial1.flush();

        

           dataFile = SD.open(filename,FILE_WRITE);

       

           if (!dataFile){

               digitalWrite(LED_BUILTIN,LOW); // As long as there's isn't a datafile. 

                }

           dataFile.print(timenow); dataFile.print(":");

           serav2 = Serial1.available(); //bits that the vector nav sends back.

                if(serav2>0)

                  {

                       for(int i=0;i<serav2;i++)

                        {

                            char serial1 = char(Serial1.read());

                            dataFile.write(serial1);

                          }

                        dataFile.println(); dataFile.close(); // has written to card.

                  }

          else     {

            digitalWrite(LED_BUILTIN,LOW);

            delay(1000);

           digitalWrite(LED_BUILTIN,HIGH); delay(1000); digitalWrite(LED_BUILTIN,LOW);

          }

         

          timeold = timenow;

       

        } // end of if statement containing 9 milliseconds 

      } // end of loop

       

      After multiple tests it still gives me garbage values. Things I have tried: 1) Changing the setting on sensor 2) Setting Serial1.Begin(128000) and setting the if statement to '9' 3) Taking away the if statement (Which still gave me garbage values) 4) Using the SPI Library. I believe the Edison has a clock speed of 500mhz so I would believe 100 hertz should be fine. If anyone has any suggestions to get this program to work at 100 hertz so that the data file does not contain junk values but the actually sensor data, it would be greatly appreciated.

        • 1. Re: Edison Outputing Incorrect Values into a File
          Intel Corporation
          This message was posted on behalf of Intel Corporation

          Hi PatriotWest252,

          Thanks for your interest in the Intel® Edison™ Platform.

          I'm sorry to hear that you are having an issue with getting data at 100 hertz. In my experience, I've never seen anyone using a baud rate of 1280000. When I establish a serial connection with the Edison I used a baud rate of 115200, I would encourage to use baud rate. Please let me know if this correction helps solving your issue.

          We will be waiting for your reply, have a nice day!

          Best Regards,
          -Jose P.

          • 2. Re: Edison Outputing Incorrect Values into a File
            PatriotWest252

            Hello Jose P.,

             

            Thanks for the suggestion but I have tried that already and I am unable to get the data I need. It gives me this:

             

            11395:ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ$VœRRGX17X-0`\3459,+00.1222,+00.2630*55

            $VNRRG,72,-160.571,+000.597,+000.225,+00.00000000,+000.00000000,+00000.000,+000.000,+000.000,+000.000,+00.104,-00.028,-09.550,+00.000169,-00.000190,+00.000262*53

             

            it gives me some values back but I still get data points like the one above.  The reason I set the Serial.begin to 128000 is because the Vector Nav is able to output 100 hertz data but only to a baud rate of 128000; so my logical was to put that on the sensor and insert that value on the Arduino program so they can both be on equal terms. Is there a way to get 100 hertz on a 115200 baud rate? and If so, why am I not able to get clean values similar to:  

             

            10528:ÿÿÿÿÿÿÿÿÿÿÿÿÿÿ$VNRRG,17,-00.3431,+00.0219,+00.2526*56

            ÿÿÿÿÿÿÿÿÿÿÿÿÿÿ$VNRRG,72,-176.674,+000.592,+000.184,+00.00000000,+000.00000000,+00000.000,+000.000,+000.000,+000.000,+00.092,-00.041,-09.562,+00.000118,-00.000528,-00.000815*52

             

            ? Is my "if statement" logically set up correcting to get 100 hertz? Or is there a more efficient way of doing so. Thanks.

             

            Best,

            • 3. Re: Edison Outputing Incorrect Values into a File
              Intel Corporation
              This message was posted on behalf of Intel Corporation

              Hi PatriotWest252,

               

              Would you be so kind to share me the datasheet of your Vector Nav sensor? Also, please check the Hardware guide of the Edison http://download.intel.com/support/edison/sb/edisonmodule_hg_331189004.pdf , especially on page 24, in there you will find the supported baud rates.

               

              Best Regards,
              -Jose P.

              • 4. Re: Edison Outputing Incorrect Values into a File
                PatriotWest252

                Hey Jose P.,

                 

                Thanks for the source I am reading it right now as we speak. Here is the data sheet for the sensor I am working with.

                http://www.vectornav.com/products/vn-200/specifications

                 

                Best,

                • 5. Re: Edison Outputing Incorrect Values into a File
                  Intel Corporation
                  This message was posted on behalf of Intel Corporation

                  Hi PatriotWest252,

                   

                  Have you tried to use a simple serial example, like this one Arduino - SoftwareSerialExample ? Do you get the same results?

                   

                  We will be waiting for your results, have a nice day!

                   

                  Best Regards,
                  -Jose P.

                  • 6. Re: Edison Outputing Incorrect Values into a File
                    Intel Corporation
                    This message was posted on behalf of Intel Corporation

                    Hi PatriotWest252,

                    Were you able to fix your UART issue? Please let us know in order to assisty you.

                    Have a nice day!

                    Best Regards,
                    -Jose P.
                     

                    • 7. Re: Edison Outputing Incorrect Values into a File
                      PatriotWest252

                      Hello Jose P.,

                       

                      I tired that and it seems to not compile with the intel edison. In any case I have developed a new program to get 20 hertz (starting small) here is my updated code:

                      void setup(){

                      Serial1.begin(115200);

                      }

                      void loop(){

                       

                      dataFile = SD.open(filename, FILE_WRITE);

                                                 

                      if(dataFile)

                        {

                          

                        Serial1.println("$VNRRG,17*XX"); // does not print

                          Serial1.println("$VNRRG,17*XX"); delay(1); Serial1.println("$VNRRG,72*XX"); Serial1.flush();

                             dataFile.print(millis());

                             dataFile.print(":");

                       

                                while(Serial1.available()){ //bits that the vector nav sends back.

                       

                                 for(int i = 0; i<64;i++){

                               

                                   char serav2[i] = char(Serial1.read());

                                  char serial1 = serav2[i];

                                   dataFile.write(serial1);

                                 

                                          }

                                    for(int i = 64; i<128;i++){

                                     

                                          char serav2[i] = char(Serial1.read());

                                           char serial1 = serav2[i]; /

                                            dataFile.write(serial1);

                                 

                                          }

                                       for(int i = 128; i<192;i++){

                                               

                                                 char serav2[i] = char(Serial1.read());

                                                 char serial1 = serav2[i]; // End marker?

                                                  dataFile.write(serial1);

                                 

                                          }

                                          for(int i = 192; i<300;i++){

                               

                                     char serav2[i] = char(Serial1.read());

                                      char serial1 = serav2[i]; // End marker?

                                       dataFile.write(serial1);

                                 

                                          }

                                  } // end of while statement

                                 

                        dataFile.println(); dataFile.close(); // has written to card.

                       

                      delay(50);  // 20 hertz equal to 50 milliseconds

                      }

                       

                      This new program works, however, it only works if I put another register so that the other two other registers can be printed out clearly. For example:

                       

                      4432:ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ’•”%u±17,-00.2111,+00.0011,+00.3647*5F

                      $VNRRG,17,-00.2111,+00.0011,+00.3647*5F

                      $VNRRG,72,+179.096,+000.098,-000.077,+00.00000000,+000.00000000,+00000.000,+000.000,+000.000,+000.000,+00.018,+00.024,-09.564,+00.000335,-00.000511,-

                       

                      so it looks like the sensor and board are not on the same page. I can do this at 20 hertz but this still seems inefficient. The sensor is set to a 115200 baudrate running with a Asynchronous output of 20 hertz. Is there a way to get them both on the same page when outputting 20 or preferable 100 hertz? I have also noticed that Serial1.available has a buffer size of 64 bytes and yet the sensor is passing 255 bytes to be exact (that's why I added those for loops.) is there a better method of getting all those bytes with a different function of some kind? or is the Edison not capable of handling so many many bytes at the same time?

                       

                      Best,

                      • 8. Re: Edison Outputing Incorrect Values into a File
                        Intel Corporation
                        This message was posted on behalf of Intel Corporation

                        Hi PatriotWest252,

                         

                        I think that the problem with your code is the delay() function, for timing events longer than 10's of milliseconds it should be avoided, unless it's a simple sketch.

                         

                        I would encourage you to use interrupts, due to the case sensitive timing event that you are dealing with.

                         

                        Interrupts Arduino:

                         

                        - Arduino - Interrupts
                        Arduino - AttachInterrupt

                         

                        We will be waiting for your reply, have a nice day!

                         

                        Best Regards,
                        -Jose P.

                        • 9. Re: Edison Outputing Incorrect Values into a File
                          PatriotWest252

                          Hello Jose P,

                           

                          This is my updated code that works at 20 hertz but does not give exactly 20 hertz but close enough....

                           

                          void loop() {

                           

                            if(x == 1){

                             delay(5000); // 5 seconds

                            x++; // new code

                            }

                           

                            timenow = millis();

                           

                                if((timenow - timeold) ==  50){

                             

                                                 

                               delay(24); Serial1.println("$VNRRG,72*XX"); delay(23); Serial1.println("$VNRRG,17*XX"); Serial1.flush();

                            

                              dataFile = SD.open(filename,FILE_WRITE);

                           

                               if (!dataFile){

                                   digitalWrite(LED_BUILTIN,LOW); // As long as there's isn't a datafile.

                               }

                              dataFile.print(timenow); dataFile.print(":");

                               serav2 = Serial1.available(); //bits that the vector nav sends back.

                               if(serav2>0)

                                 {

                                 for(int i=0;i<serav2;i++)

                                   {

                                      char serial1 = char(Serial1.read());

                                       dataFile.write(serial1);

                                           

                                    }

                                  dataFile.println(); dataFile.close(); // has written to card.

                                 }

                              else{

                                digitalWrite(LED_BUILTIN,LOW);

                                delay(1000); digitalWrite(LED_BUILTIN,HIGH); delay(1000); digitalWrite(LED_BUILTIN,LOW);

                              }

                           

                            timeold = timenow;

                                      } // end if statement

                          else{

                           

                           

                            dataFile = SD.open(filename,FILE_WRITE);

                                    dataFile.print(timenow); dataFile.print(":");

                                                   //register 72 data    /*delay(48);*/    //47 and 46 gave me 96 miliseconds.   

                               delay(23); Serial1.println("$VNRRG,72*XX"); delay(22); Serial1.println("$VNRRG,17*XX"); Serial1.flush();

                            

                             // dataFile = SD.open(filename,FILE_WRITE);  // Yup, we need this.

                               if (!dataFile){

                                   digitalWrite(LED_BUILTIN,LOW); // As long as there's isn't a datafile.

                               }

                             //  dataFile.print(timenow); dataFile.print(":");

                               serav2 = Serial1.available(); //bits that the vector nav sends back.

                               if(serav2>0)

                                 {

                                 for(int i=0;i<serav2;i++)

                                   {

                                      char serial1 = char(Serial1.read());

                                       dataFile.write(serial1);

                                           

                                    }

                                  dataFile.println(); dataFile.close(); // has written to card.

                                 }

                              else{

                                digitalWrite(LED_BUILTIN,LOW);

                                delay(1000); digitalWrite(LED_BUILTIN,HIGH); delay(1000); digitalWrite(LED_BUILTIN,LOW);

                              }

                           

                            timeold = timenow;

                           

                            }

                           

                          }// end of program

                           

                           

                          Those delays I have give me a 47 millisecond and  extra 3 millisecond(program to run) delay to give a me a 50 millisecond delay for each data point, which is equivalent to 20 hertz. However, it skips from 50 milliseconds to 51 or 52 milliseconds, not perfect. If I apply this method to 50 hertz or even 100 hertz, no data gets printed out. My question would be then, how can I make the Intel Edison in full control of the sensor and how can my program run 100 hertz, or how can I set a more official timer that the sensor must abide by. This method works temporary, but I would still like 100 hertz which I believe both components are capable of doing. I read in the Vector Nav sensor manual that the sensor is already set to be a slave, so I believe the Edison can take control.

                           

                          Best,

                          • 10. Re: Edison Outputing Incorrect Values into a File
                            Intel Corporation
                            This message was posted on behalf of Intel Corporation

                            Hi PatriotWest252,

                             

                            Yes, there is a more efficient way to program this, you will need to create your own timer routine in Linux Create your own timer routine in Linux | My Linux and Telecom Experiences . Please do remember that using the delay() function won't give you the results that you are trying to achieve.

                             

                            Hope you find this information useful, have a nice day!

                             

                            Best Regards,
                            -Jose P.

                            • 11. Re: Edison Outputing Incorrect Values into a File
                              PatriotWest252

                              Hey Jose,

                               

                              So I'm a bit unclear about the Linux timer. Do I have to install the Linux operating system to use those library's? Or can I just enter it in the arduino IDE? I know the Edison has Linux already but I am just a bit unclear about that. I have the necessary code ready but I am just unsure about downloading Linux since I am currently using Windows 10. Looking forward to you response.

                               

                              Best,

                              • 12. Re: Edison Outputing Incorrect Values into a File
                                Intel Corporation
                                This message was posted on behalf of Intel Corporation

                                Hi PatriotWest252,
                                 
                                You can create/use the Linux timer in the Linux Yocto image in the Edison and it can be compiled as it is mentioned in the article post above (Create your own timer routine in Linux). It cannot be used in the Arduino IDE.
                                 
                                Hope this helps.
                                 
                                Regards,
                                -Yermi A.
                                 

                                • 13. Re: Edison Outputing Incorrect Values into a File
                                  PatriotWest252

                                  Hello Yermi A.,

                                  Thanks for that. How am I suppose to add my data processing code to the Linux timer? I was able to construct the timer in Linux and the only thing that is missing is the data processing code. Do I just add it to the Linux timer? or is there a way to combine a Arduino program with a Linux program? Here is my Linux timer code:

                                   

                                  void timer_handler (int signum)

                                  {

                                    struct timeval ts;

                                    static int count = 0;

                                   

                                    printf ("%d.%0.6d: ",ts.tv_sec,ts.tv_usec, ++count);

                                  }

                                   

                                  int main ()

                                  {

                                    struct sigaction sa;

                                    struct itimerval timer;

                                   

                                   

                                    /* Install timer_handler as the signal handler for SIGVTALRM.  */

                                    memset (&sa, 0, sizeof (sa));

                                    sa.sa_handler = &timer_handler;

                                    sigaction (SIGVTALRM, &sa, NULL);

                                   

                                  /* Configure the timer to expire after 10 msec... = 10000 microseconds or 50 msec... = 50000 microseconds  */

                                    timer.it_value.tv_sec = 0;

                                    timer.it_value.tv_usec = 50000;

                                    /* ... and every 50 msec after that.  */

                                    timer.it_interval.tv_sec = 0;

                                    timer.it_interval.tv_usec = 50000;

                                    /* Start a virtual timer.  It counts down whenever this process is

                                       executing.  */

                                    setitimer (ITIMER_VIRTUAL, &timer, NULL);

                                   

                                    /* Do busy work.  */

                                    while (1);

                                  }

                                   

                                  I appreciate the feedback!

                                   

                                  Best,

                                  • 14. Re: Edison Outputing Incorrect Values into a File
                                    Intel Corporation
                                    This message was posted on behalf of Intel Corporation

                                    Hi,
                                     
                                    You can combine your program in the Arduino IDE with the Linux timer you have done using the system() function, with this function your Arduino sketch can interact with Linux as you might through the terminal.
                                     
                                    To use that function you can compile your Linux timer code to get an executable, then in your Arduino IDE call the timer using system(“./path_to_your_executable/executable_name”).    
                                     
                                    Regards,
                                    -Yermi A.