how to run a program on arduino in loop?

Hello everybody,

so,my friend and I have written a small program in C and uploaded it into an Arduino YUN,for a course we are attending at University. This program is quite simple,it interfaces with a webcam,connected to the usb port on Arduino YUN, through a driver and takes pictures.

The problem is that,at the moment,we run this program through ssh using putty,accessing via ssh to Arduino YUN's memory and executing the program.

Is there a way to execute this program automatically? without accessing through ssh?

is there a piece of code that must be written into the loop() function?

thank you everybody for the attention =)

Why can't you just use a "while" loop?

I don't know what your code is, so I can only make guesses at what you are trying to do...

Ps991:
Why can't you just use a "while" loop?

I don't know what your code is, so I can only make guesses at what you are trying to do...

we have written this program in C and put it into arduino yun through ssh. It's not an arduino sketch,is a C program. We want to make the Arduino YUN execute it automatically,in loop

I dont have a YUN, but its linux, so I'm assuming you can write a program that upon startup a program runs that executes this program of yours.

Im also just guessing that the ATmega32u4 can talk to the linux portion and request that you execute the program, so maybe start looking there?

Edit, my first web search gives me this...

Just use chron.

Mark

I think he means cron, nothing relative comes up with chron

Do you mean the loop function in the arduino sketch?

If yes take a look here:

With the process class provided by the Bridge library you can run programs and scripts on the linux side and you can also read its output.

Angelo9999:
Do you mean the loop function in the arduino sketch?

If yes take a look here:
http://www.arduino.cc/en/Tutorial/Process

With the process class provided by the Bridge library you can run programs and scripts on the linux side and you can also read its output.

maybe this is the right way of solving this problem,I will let you know if we find any other issues; I will check also the process class and cron. Thank you guys :slight_smile:

Use the runShellcommand(), you may run program stored in linux called in loop() from microcontroller.

I think it all depends on when/why you want to run your C program, and what you will be doing with the output.

It's most efficient to try and implement it all on the Linux side. Either add a while loop to your process, add it as a cron task, or write a shell script that is run at startup, and periodically calls your C program.

However, if any of these apply, then you will likely want to use some variation of the Process() class in an Arduino sketch:

  • you need to send results of your C code over the micro-USB port to a computer
  • you need to use incoming data from the micro-USB port to trigger your C code
  • you need the results of the C codeto control some shield connector outputs
  • you need some shield connector inputs to to trigger your C code

So yes, you can make a Process() call within the loop() function of a sketch. But if you don't need to do anything in the list above, it's more efficient to do it in Linux: the host USB port, the networking (wireless and Ethernet) and the SD card are all controlled directly from Linux.

Plan B:

Use mjpg_streamer and output_file.so take picture.

/usr/bin/mjpg_streamer -i "input_uvc.so -y --device /dev/video0"  -o  "output_file.so  -f /mnt/sda1/pic -d 1500"

"-d 1500" means every 1.5 sec save one shot.

http://forum.arduino.cc/index.php?topic=305773.msg2177034#msg2177034

mjpg_streamer -o "output_file.so --help"

MJPG Streamer Version: svn rev: exported
 ---------------------------------------------------------------
 Help for output plugin..: FILE output plugin
 ---------------------------------------------------------------
 The following parameters can be passed to this plugin:

 [-f | --folder ]........: folder to save pictures
 [-m | --mjpeg ]........: save the stream to an mjpeg file
 [-d | --delay ].........: delay after saving pictures in ms
 [-s | --size ]..........: size of ring buffer (max number of pictures to hold)
 [-e | --exceed ]........: allow ringbuffer to exceed limit by this amount
 [-c | --command ].......: execute command after saving picture

 [-i | --input ].......: read frames from the specified input plugin

 ---------------------------------------------------------------
output_init() return value signals to exit

Make it auto start:

nano /etc/rc.local
...
(/usr/bin/mjpg_streamer -i "input_uvc.so -y --device /dev/video0"  -o  "output_file.so  -f /mnt/sda1/pic -d 1500")&
...