3 Replies Latest reply on Dec 18, 2014 6:26 PM by jzd

    how to print on edison stdout via arduino IDE(sketch.elf)

    jzd

      I write a arduino program via Arduino IDE and i need it to print data in the stdout of edison. Because I will manually start the program (/sketch/sketch.elf) in the shell of edison.

       

      But I tried printf and system("echo xxx"), they will not print any data on shell. It seems the arduino IDE redirect the stdout. Does anyone know how to make the adruno program to print data on edison stdout?

        • 1. Re: how to print on edison stdout via arduino IDE(sketch.elf)
          JPMontero_Intel

          Hi jzd,

           

          I was able to send to port ttyMFD2 the output of command date by using the Arduino IDE. I used the following command: system(“date >> /dev/ttyMFD2”); The idea of this is to send the output to the Linux console, you just need to change the date command with the one you want to execute in Linux. Is this what you are trying to do?

           

          Regards,
          JPMontero_Intel

          • 2. Re: how to print on edison stdout via arduino IDE(sketch.elf)
            KurtE

            There are a few different things you can do.

             

            1. Use what is there.  That is, in the Arduino IDE source code for the function main,

             

            It sets up to have:

                everything that went to stdout goes to the file /tmp/log.txt

                everything that went to stderr goes to the file /tmp/log_err.txt

             

            I look at the file contents using some form of terminal connection (debug terminal or ssh connection).  Note:  the /tmp directory is in RAM so you reboot and it is gone.  When I am debugging some Arduino stuff, I have sketch to reboot, which copies the two files to my home directory.

             

            2. Modify Main to do something else.

             

            3. Have your stuff output to something else.  Like JPMontero_Intel mentioned, you can output to main console terminal, by using the Serial2 object within Arduino IDE

            • 3. Re: how to print on edison stdout via arduino IDE(sketch.elf)
              jzd

              I choose to comment out the following part in main.cpp, and now i can see the output when i loggin via ssh or serial

              /*

              stdout = freopen("/tmp/log.txt", "w", stdout);
              if (stdout == NULL){
                  fprintf(stderr, "unable to remap stdout !\n");
                  exit(-1);
              }

              fflush(stdout);

              stderr = freopen("/tmp/log_er.txt", "w", stderr);
              if (stderr == NULL){
                  printf("Unable to remap stderr !\n");
                  exit(-1);
              }
              fflush(stderr);

              */