Intel® Makers
Intel® Edison, Intel® Joule™, Intel® Curie™, Intel® Galileo
Announcements
Welcome - This is a Peer-to-Peer Forum only. Intel has discontinued these products but you may find support from other customers on this Forum
9868 Discussions

Questions about Linux and OpenCV on galileo board

DFrio
Beginner
2,410 Views

Hello,

I was wondering if it was possible to use OpenCV with Linux and the USB port.

If it is possible, how would I go about doing it? Could I control it from the arduino software?

Thanks!

9 Replies
ADRIAN_B_Intel
Employee
227 Views

hi,

i have escalated this to the board support package team.

in the meantime please ensure you are booting the large linux image from SD.

the little image goes on the 8MB flash chip and is slimmed down to fit so wouldnt have OpenCv as far as i know.

-adrian

FBasi1
New Contributor I
227 Views

I'm investigating the OpenCV support, at this time I guess there's no direct communication bridge between the "arduino like" environment and linux part. One idea could be to port the bridge library used by Arduino YUN.

Another idea could be to implement in the Galileo Arduino libs the dbus protocol, as a dbus server is already compiled in the kernel. This way it will be easy to communicate with the linux side.

What I'm currently doing, is to create a python web app using the CV module and poll it using the Arduino Ethernet driver, just connecting to localhost.

Hope this helps, feel free to write me if you need more details at mailto:fiore.basile@gmail.com fiore.basile@gmail.com

ADRIAN_B_Intel
Employee
227 Views

hi Fiore,

The arduino sketches on Galileo run as user space linux apps on the Quark SoC so you have access to linux right away without any Bridge API. Just make linux system(); calls from the sketch if you want.

void loop() {

// put your main code here, to run repeatedly:

char cmd[50];

sprintf(cmd, "uname -a > /dev/ttyGS0");

system(cmd);

delay(5000);

}

On the CV/Python issue.

There is python and openCV in the large SD image but there is an issue when importing CV into python.

They both work standalone and the engineers here are looking at fixing the issue for the next release.

-a

ADRIAN_B_Intel
Employee
227 Views

code below is easier:

void setup() {

// put your setup code here, to run once:

Serial.begin(9600);

}

void loop() {

// some linux code that prints stuff to serial monitor

system("uname -a > /dev/ttyGS0");

system("ls / > /dev/ttyGS0");

// some arduino code that prints stuff to serial monitor

Serial.print("Its linux Jim, but not as we know it !!\n");

delay(5000);

}

SHunt2
New Contributor I
227 Views

I'm able to call a process like this from my home director:

system("node /home/root/nodeGalileo/1_geoPlaces.js > /dev/ttyGS0");

This outputs a value to the serial monitor. How can I parse this value and evaluate it to decide what to do next? In other words how do I read strings back into the arduino environment from processes on the linux side.

Thanks!

ADRIAN_B_Intel
Employee
227 Views

hi,

everything in linux is a file so below is one way, it may not be the most efficient but it works !

see some example sketches below....

/*

 

This example shows how to use a system call to set current date & time with

 

UNIX 'date' command, then get the current time, redirect to a .txt file,

 

and read the contents of the text file back into the sketch.

 

*/

char buf[9];

void setup() {

 

 

Serial.begin(115200);

 

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);

 

fclose(fp);

 

 

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

 

Serial.println(buf);

 

delay(1000);

 

 

}

/*

 

This example shows how to read the temperature sensor on the Galileo's

 

onboard ADC, AD7298, using the iio (Industrial I/O) subsystem.

NOTE: This does not provide an accurate reading of the room tenmperature,

 

because the ADC is placed near the Quark SoC on the PCB, which gets quite warm.

 

As a result the ADC will always be a few degrees warmer than the actual room

 

temperature.

 

*/

char scale[4];

 

char raw[4];

 

char offset[4];

int raw_i;

 

int scale_i;

 

int offset_i;

int temp;

void setup() {

 

 

Serial.begin(115200);

 

 

}

void loop() {

 

 

temp = getADCTemp();

 

Serial.print("Temperature is ");

 

Serial.print(temp);

 

Serial.println(" degrees celcius.");

 

delay(1000);

 

 

}

int getADCTemp(){

FILE *fp_raw;

 

fp_raw = fopen("/sys/bus/iio/devices/iio:device0/in_temp0_raw", "r"); //read the values from scale, raw and offset files.

 

fgets(raw, 4, fp_raw); //we need all three values, because the formula for

 

fclose(fp_raw); //calulating the actual temperature in milli-degrees Celcius

 

//is: TEMP = (RAW + OFFSET) * SCALE

 

FILE *fp_scale;

 

fp_scale = fopen("/sys/bus/iio/devices/iio:device0/in_temp0_scale", "r");

 

fgets(scale, 4, fp_scale);

 

fclose(fp_scale);

 

 

FILE *fp_offset;

 

fp_offset = fopen("/sys/bus/iio/devices/iio:device0/in_temp0_offset", "r");

 

fgets(offset, 4, fp_offset);

 

fclose(fp_offset);

 

 

raw_i = atoi(raw); //we have the values now, but they are in ASCII form-

 

scale_i = atoi(scale); //we need them as integers so we can use them for calculations.

 

offset_i = atoi(offset);

 

 

int temp = (raw_i + offset_i) * scale_i; //Calculate temperature in milli-degrees celcius

 

temp /= 1000; //divide by 1000 to convert to degrees celcius

 

return temp;

 

 

}

/*

 

This example uses Linux system calls to create a python script which writes

 

number 0-9 to a file, log.txt, one number per second. Then execute the

 

python script in the background, and regularly read the contents of the logfile

 

in the sketch while the python script is updating it.

 

*/

char output[3];

void setup() {

 

 

Serial.begin(115200);

 

 

system("echo '# !/usr/bin/python' > myScript.py");

 

system("echo 'import time' >> myScript.py");

 

system("echo 'for i in range(10):' >> myScript.py");

 

system("echo ' with open(\"log.txt\", \"w\") as fh:' >> myScript.py");

 

system("echo ' fh.write(\"{0}\".format(i))' >> myScript.py");

 

system("echo ' time.sleep(1)' >> myScript.py");

 

system("chmod a+x myScript.py");

 

system("./myScript.py &");

 

}

void loop() {

 

 

FILE *fp;

 

fp = fopen("log.txt", "r");

 

fgets(output, 2, fp);

 

fclose(fp);

 

Serial.println(output);

 

delay(1000);

 

 

}
MHoll8
Novice
227 Views

Thanks for this very helpful tutorial on how to access the Linux functionality from arduino sketches. Adding file access to arduino is a major advance. Is there a single document somewhere that describes all the extentions that Intel has made to the arduino language? Calls like system(), and all the file access commands like fopen(), fgets(), fclose(). What other goodies have you added?

AT9
Honored Contributor II
227 Views

I don't know of any such document, so I'll leave this to others to add comments, but in general your sketch is actually compiled into a normal 32-bit Linux binary program and run under Linux running on Galileo, so you have the full power of Linux :-) and can use pretty much all/most of standard Linux/POSIX functions, just keep in mind that's not a full-blown glibc, but an embedded uclibc. You can find the documentation either in the uclibc docs dir inside the tarball at uclibc.org, or just use Google and find some generic Linux/UNIX programming manual.

SHunt2
New Contributor I
227 Views

Thanks that's super helpful - I've been using this example and an article (with a slightly more elegant) implementation posted here: https://www.sparkfun.com/news/1360 Enginursday: Exploring the Arduino/Intel Galileo - News - SparkFun Electronics

I suppose this is better than reading from the serial port because you have more control with a file system.

Reply