How to run 2 programs at the same time on Arduino?

Hi,
Can anyone provide me any information about the following question? Thanks!
I need to control some appliances and monitor their energy consumption at the same time. It's a little difficult to schedule them in one program. I have some arduino uno boards, can they run 2 programs at the same time? Or if there are some other Arduino boards can run 2 programs at the same time (it seems the Arduino YUN could do that)?

Thanks!
??!

Stille:
It's a little difficult to schedule them in one program.

A single sketch can control multiple independent activities, if you design it correctly.

Google Arduino RTOS

If you study the Blink Without Delay example sketch you will see how to control the time of things without using the delay() function which just brings everything to a standstill.

I wrote a more extensive demo sketch that shows how the technique can be used to control several things at the same time. Demonstration code for several things at the same time - Project Guidance - Arduino Forum

Don't even think about an Arduino Real Time Operating System (RTOS) unless you are already an expert.

...R

Don't even think about an Arduino Real Time Operating System (RTOS) unless you are already an expert.

OK, that is a fair statement and I agree; but the Op is mucking in the waters of control systems for appliances, so I think it is fair to point them into an area that provides the foundational capabilities that are necessary to multi-task.

Additionally, your replacement code for Blink Without Delay should be in the Arduino 1.5.x beta distributions. The original example is simply not satisfactory.

Ray

You can combine your two programs into one single sketch or combine two Arduino boards. I mean if you already have the additional boards go ahead and approach it that way.

mrburnette:
the foundational capabilities that are necessary to multi-task.

I don't agree that any form of RTOS is necessary to multi-task. The standard Arduino runtime environment with a single-threaded sketch is perfectly adequate as long as the sketch is designed correctly so that multiple activities can be controlled in parallel.

oohh here we go again :roll_eyes:

Just because person X uses the Arduino RTOS or a the Button library does not make the Arduino more/less capable. It is a single CPU (with interrupts). All that stuff does is save person X thinking about the code, add some overhead (meaning less cycles to do what the point was). So I am with PeterH. On the other hand not everyone is capable or has the time to understand the "multitask / parallel" code pattern.

I'd like to nominate the "Two blinking LEDS" sketch to replace/enhance the next distribution. It was written by several of the regular contributors and thus is quite good.

Interesting views from senior members.

The Op in the intro used the word "schedule" ... not "run" or "process" or "execute" or any of the terms generally associated with a newbie asking about two sections of code executing in a loop. Additionally, the words "appliances" and "monitor" were thrown in which suggest that we are not in the LED play area.

There are many ways to get from A to Z, but if the Op is off playing in realm of control systems, s/he needs to know that a technology is available in RTOS and as with most any solution that has multiple paths to closure, there are pros and cons to using RTOS. In the complexity area, it may be an overkill but it could be just the perfect solution for the Op.

Ray

PeterH:

mrburnette:
the foundational capabilities that are necessary to multi-task.

I don't agree that any form of RTOS is necessary to multi-task. The standard Arduino runtime environment with a single-threaded sketch is perfectly adequate as long as the sketch is designed correctly so that multiple activities can be controlled in parallel.

I agree, it's just a matter of using proper program structure and avoiding or at least fully understanding any 'blocking' functions. A RTOS may help a programmer that wants or needs to 'live' in a more abstract environment, but it can only hurt the performance of the 8 bit AVR chip.

Lefty

hi,
i want to run blink and debounce program same time plz some help me for the program to run on arduino uno
plzzz

You have posted your question in a 3-years-dead Thread but you don't seem to have taken the trouble to read the Thread first. If you had you would have found the answer in Reply #3

...R