arkhipenko / TaskScheduler

Cooperative multitasking for Arduino, ESPx, STM32, nRF and other microcontrollers
http://playground.arduino.cc/Code/TaskScheduler
BSD 3-Clause "New" or "Revised" License
1.26k stars 230 forks source link

Real sensor delay #64

Closed dragoblaztr closed 6 years ago

dragoblaztr commented 6 years ago

I'm looking at example 5, and I have a question about how do I get the real sensor delay instead a simulated one like in this example?

arkhipenko commented 6 years ago

In my experience, unless a sensor has a capability of sending you a pin interrupt, there is no other way, so what I usually do is wait a reasonable amount of time and then timeout.

For instance, the ultrasonic sensor changes from low to high when it starts measuring, and then from high to low when it's done, so there are falling/rising edges to anchor on. However, there is a reasonable expectation of either a distance you are interested in, or a max range, after which you stop caring. check this out: Event-based ultrasonic distance measurement

Gyroscopes have a designated interrupt pin for data ready purposes. Some Thermo sensors just take a predefined time (like a 100 Ms) for measurements.

What sensor are you working with?

dragoblaztr commented 6 years ago

I'm using MAX6675 thermpcouple, how can I configure that sketch to measure that sensor timeout, since I noticed than in that example is like this:

tSensor2.setInterval( random(1200) );

tSensor2.getInterval()

Thanks in advance

arkhipenko commented 6 years ago

Example 5 simulates the behaviour of an ultrasonic sensor, which is measuring the time of sound wave travel, which, depending on the distance, is variable. Hence use of random() in the example.

Thermocouple does not have a delay, and as far I was able to find out here: datasheet uses serial interface to send the measurement back to sketch (page 5). So there is no delay. You just use this library adafruit and read the value.

I am not even sure you need to use code from example 5. Example 5 is a case of triggering events based on a number of sensors with unpredictable completion time. Does not seem like this is the case in your example.

dragoblaztr commented 6 years ago

Ok, I'll take it on mind, thanks for the advice.

Issue closed