3 Replies Latest reply on Jun 18, 2015 8:13 AM by Intel_Peter

    intel galileo + arduino

    akanksha

      I want to use my opencv libraries with intel galileo. now there are I believe two methods to do that either I can use eclipse or use Arduino IDE to use OpenCV libraries with the same. My questions are :

      1. How can I use arduino to access opencv libraries?

      2. Everytime I power down galileo the next time I switch it on the sketch uploaded earlier is lost . How to overcome this problem?

        • 1. Re: intel galileo + arduino
          Intel_Peter

          Hello akanksha,

           

          As you may know, internally, your Galileo is running a tiny distribution of Linux called Yocto. As you mentioned you can use Eclipse and Arduino IDEs, however these are not the only options that you have. As you can see in Downloads | Intel® Developer Zone there a total of four supported IDEs, the two mentioned above plus the Intel XDK and Wyliodrin. Nevertheless those are not all the options either, if you have a Console Serial Cables you can access your Galileo's Linux and  compile directly from it, this will give you the possibility of using other programming languages like Python.

          Now, you were wondering how to use your OpenCV libraries using an Arduino sketch. Well, you can do this by making a system call with the "system" command. I will explain the command with a simple example of a call to the Linux's "date" command:

           

          ...
          system("date");
          ...
          

           

          But first you will need to install the OpenCV libraries on your board. You will find the library in DOWNLOADS | OpenCV.

          Regarding how to make a persistent Arduino sketch on your Galileo, you'll need to use the complete Yocto image. You will find a explanation on how to use it in Intel® Galileo Boards and Kits — SD Card Setup and Sketch Persistent.

           

          Peter.

          1 of 1 people found this helpful
          • 2. Re: intel galileo + arduino
            akanksha

            @Intel_Peter

             

            Thanks !!

            But I wanted to specifically know that suppose if I write a code using opencv libraries in a text editor and now i want it to be saved in my galileo flash and execute it there itself how can I do that. I have saved a cpp file on my board but i am not able to execute it. I hope I am clear with my question. I am using the console serial cable and ethernet cable you mentioned.

            • 3. Re: intel galileo + arduino
              Intel_Peter

              Oh, I see… Well, as I mentioned in my previous post, if you are entering the Edison's Linux console, you get a bunch of extra possibilities. I mean, you can have your code in a .c, .js, .py, .java, etc. and compile it within Linux. Let me show you an example of what I mean:

               

              For this example I'll use the blink example you can find in mraa/Blink-IO.cpp at master · intel-iot-devkit/mraa · GitHub

               

              You can have the following code stored in a file called blink.cpp which is at the same time stored on your board's memory:

               

              #include <signal.h>
              #include <stdio.h>
              #include <stdlib.h>
              #include <stdlib.h>
              #include <unistd.h>
              
              #include "mraa.hpp"
              #define DEFAULT_IOPIN 13          //I modified this line from the original example to make it the on-board LED
              
              static int iopin;
              int running = 0;
              
              void
              sig_handler(int signo)
              {
                  if (signo == SIGINT) {
                      printf("closing IO%d nicely\n", iopin);
                      running = -1;
                  }
              }
              int
              main(int argc, char** argv)
              {
                  if (argc < 2) {
                      printf("Provide an int arg if you want to flash on something other than %d\n", DEFAULT_IOPIN);
                      iopin = DEFAULT_IOPIN;
                  } else {
                      iopin = strtol(argv[1], NULL, 10);
                  }
              
                  signal(SIGINT, sig_handler);
              
                  //! [Interesting]
                  mraa::Gpio* gpio = new mraa::Gpio(iopin);
                  if (gpio == NULL) {
                      return MRAA_ERROR_UNSPECIFIED;
                  }
                  mraa_result_t response = gpio->dir(mraa::DIR_OUT);
                  if (response != MRAA_SUCCESS) {
                      mraa::printError(response);
                      return 1;
                  }
              
                  while (running == 0) {
                      response = gpio->write(1);
                      sleep(1);
                      response = gpio->write(0);
                      sleep(1);
                  }
                  delete gpio;
                  return response;
                  //! [Interesting]
              }
              
              
              

               

              Then, since this is c++ code, you could use the g++ compiler to compile it, create an executable file and then run it. You can do this with the following command:

               

              g++ blink.cpp -o blink -lmraa
              
              
              

               

              This command creates a file called blink which is an executable, with the following you can run it:

               

              ./blink
              
              

               

              Do note that for this specific example you need to have installed the MRAA library (If you are interested in installing MRAA, you can find it on AlexT's Edison Package Repo). You could use the same process in your project but using OpenCV instead of MRAA.

              Let me know if my example is clear enough. I'll be glad to help if otherwise.

               

              Peter.

              1 of 1 people found this helpful