Receive signal from datalogger

Setup:
I am using a MEGA2560 to control an array of 20 air intake solenoid valves. Each intake valve opens for 5 minutes. The airflow from the solenoids goes into an sampling instrument hooked to a datalogger (Campbell CR10X), which records the sample value at the end of each 5 minute period. The Arduino cycles through the 20 values continuously.

Problem:
I would like to synchronize the Arduino to the datalogger at 100 minute intervals (the full sampling cycle). Rather than have the Arduino and the datalogger completely independent and synchronized solely by time, I would like to send a signal from the datalogger to the Arduino at the start of each full cycle. This way, when I periodically upload changes to my datalogger program (thus restarting the cycle) the Arduino would automatically restart back to the first solenoid in the series and be synced with the datalogger. This would also take care of any drift between the timer on the Arduino and the timer on the datalogger.

Question:
What is the best way to accomplish this? I would need to know what kind of input to the Arduino is best (the datalogger can send a 5V +/- 0.1V pulse with a duration of 1ms, 10ms, 100ms, or 1s), as well as the programming function that would best handle the input.

Thank you.
-Dave

the datalogger can send a 5V +/- 0.1V pulse

That's good.

with a duration of 1ms, 10ms, 100ms, or 1s

Which duration to use depends on how often the Arduino checks the state of the pin that this signal is attached to.

as well as the programming function that would best handle the input.

You can use digitalRead() to read the pin, or send the pulse to pin 2 or 3 and have it trigger an input.

Which approach is "best" depends on what the Arduino is doing (no delay()s hopefully) and your definition of best.

Problem:
I would like to send a signal from the datalogger to the Arduino at the start of each full cycle.

This is the classic example of where you would use an interrupt. I think this is what Paul meant here: or send the pulse to pin 2 or 3 and have it trigger an input except he meant to use 'interrupt' instead of 'input'. I wouldn't consider doing it any other way, this is exactly what external interrupts are meant for.

Don

...but he needs it to monitor 20 channels. How will it know which channel needs servicing?
Texy

...but he needs it to monitor 20 channels. How will it know which channel needs servicing?

He said: I would like to send a signal from the datalogger to the Arduino at the start of each full cycle.
I would assume that he reads all of the channels at this point.

Don

I would assume that he reads all of the channels at this point.

No, each channel is read in sequence during the 100 minute cycle; 1 channel every 5 minutes.

I do have a delay() in the program. The delay is what keeps each solenoid activated for five minutes. If I am correct, I can still have the delay as long as it is not inside the function called by attachInterrupt(), no? So presumably I can have the interrupt function change the state of a variable, and upon that state change have the loop start back at the beginning of the solenoid array?

dmarvs:

I would assume that he reads all of the channels at this point.

No, each channel is read in sequence during the 100 minute cycle; 1 channel every 5 minutes.

I do have a delay() in the program. The delay is what keeps each solenoid activated for five minutes. If I am correct, I can still have the delay as long as it is not inside the function called by attachInterrupt(), no? So presumably I can have the interrupt function change the state of a variable, and upon that state change have the loop start back at the beginning of the solenoid array?

I would say thats ALL your interrupt needed to do. Then the loop of the main program needs to monitor that flag/variable and react accordingly. I,m new to arduino's, but not new to micro's in general, but that sounds entirely feasible.
Texy

So presumably I can have the interrupt function change the state of a variable, and upon that state change have the loop start back at the beginning of the solenoid array?

Yes, and no. The ISR can change the state of a variable. However, when the ISR ends, control returns to the instruction following the one that had been executing when the interrupt occurs, not to the start of loop. If the code had been in a delay, the delay will resume.

You really should get rid of the delay(). If you were controlling the solenoids manually, you could use an egg timer to determine whether the solenoid had been open long enough, or you could use a watch and a notepad.

If you are using the egg timer, you open the solenoid, flip the timer over, and watch the timer. You can't do anything else, then, except watch the timer, so you can shut the solenoid off when the sand all runs down.

If you use a watch and paper, you write down the time that you open the solenoid. Periodically, you check your watch, and compare it to the time that you wrote down. If it is time, you turn the solenoid off. Meanwhile, though, you can read a book or watch TV, as long as you check your watch and the delta time fairly often.

The delay function is like the egg-timer. The millis() function is like your watch. A variable to hold the time replaces the note pad.

Since you're no longer tied up in long delay()s, you might not even need the interrupt handlers anymore. You can poll the pins, instead, reducing the complexity of the code significantly.