Temp&Humidity Module Sampling Time Question

I am testing this Temp&Humidity Module, but I find the Temp&Humidity data only store in MeasurementComplete event.
I can’t find the method to read the Temp&Humidity without using event.
The example http://wiki.tinyclr.com/index.php?title=Temp%26Humidity_Module say "Then add the following code to print the temperature and humidity values to the debug window 4 times per second. " . So I guess the sampling rate is 4 sample per second.
But how can I change the sampling time, for example I want sample the Temp&Humidity 1 sample per 10 second, how can I do it?

And I Find the

// Summary:
// Starts continuous measurements.
//
// Remarks:
// When you call this method, the Gadgeteer.Modules.Seeed.TemperatureHumidity
// sensor takes a measurement, raises the Gadgeteer.Modules.Seeed.TemperatureHumidity.MeasurementComplete
// event when the measurement is complete, and repeats. To stop continuous
// measurements, call the Gadgeteer.Modules.Seeed.TemperatureHumidity.StopContinuousMeasurements()
// method.
// To prevent the sensor from overheating, there is approximately a 3.6 second
// wait between measurements.

So "Then add the following code to print the temperature and humidity values to the debug window 4 times per second. " should be 1 times per 4 second?

Hi Tzu,

I don’t have my code with me, but this is what I did to get 1 reading per minute:
[ol]Hook into the MeasurementComplete event.
Set up a timer that fires every 60 seconds, or what every you need.
In the Timer’s Tick event add code that starts the TemeratureMesurement via the function on the module.
After the conversion is complete the MesurementComplete will fire.[/ol]

If you need better code then I can see if I can get to my code…

Thanks, I can do that.

        double temp, Humid;

        void ProgramStarted()
        {
           

            timer = new GT.Timer(10000); // every second (1000ms)
             timer.Tick += new GT.Timer.TickEventHandler(timer_Tick);
         
            Debug.Print("Program Started");

            temperatureHumidity.MeasurementComplete += new TemperatureHumidity.MeasurementCompleteEventHandler(temperatureHumidity_MeasurementComplete);
            temperatureHumidity.StartContinuousMeasurements(); 
            timer.Start();                                
        }

        void timer_Tick(GT.Timer timer)
        {
                       
            Debug.Print("Temperature1: " + temp + " Relative Humidity1: " + Humid);
        }

        void temperatureHumidity_MeasurementComplete(TemperatureHumidity sender, double temperature, double relativeHumidity)
        {
           
            temp = temperature;
            Humid = relativeHumidity;

        }

Do not call:

temperatureHumidity.StartContinuousMeasurements();

In the timer_Tick you must call something like:

temperatureHumidity.StartMeasurement(); 

There is no the method of temperatureHumidity.StartMeasurement();, only temperatureHumidity.RequestMeasurement();
So I use temperatureHumidity.RequestMeasurement();

But the first reading is 0, why.

Debug.output

Program Started
The thread ‘’ (0x4) has exited with code 0 (0x0).
Temperature1: 0 Relative Humidity1: 0
Temperature1: 24.640000000000001 Relative Humidity1: 57.359999999999999
Temperature1: 24.609999999999999 Relative Humidity1: 57.359999999999999

double temp, Humid;
 
        void ProgramStarted()
        {
 
 
            timer = new GT.Timer(10000); // every second (1000ms)
             timer.Tick += new GT.Timer.TickEventHandler(timer_Tick);
 
            Debug.Print("Program Started");
 
            temperatureHumidity.MeasurementComplete += new TemperatureHumidity.MeasurementCompleteEventHandler(temperatureHumidity_MeasurementComplete);
            
            timer.Start();                                
        }
 
        void timer_Tick(GT.Timer timer)
        {
             temperatureHumidity.RequestMeasurement(); 
            Debug.Print("Temperature1: " + temp + " Relative Humidity1: " + Humid);
        }
 
        void temperatureHumidity_MeasurementComplete(TemperatureHumidity sender, double temperature, double relativeHumidity)
        {
            
            temp = temperature;
            Humid = relativeHumidity;
 
        }

Now move the Debug.Print to the temperatureHumidity_MeasurementComplete function.

Currently you print the values before the conversion is complete…

The same

Program Started
The thread ‘’ (0x4) has exited with code 0 (0x0).
Temperature1: 0 Relative Humidity1: 0
Temperature1: 24.699999999999999 Relative Humidity1: 57.18
Temperature1: 24.710000000000001 Relative Humidity1: 57.25

You did put the debug.print last, right?


        void temperatureHumidity_MeasurementComplete(TemperatureHumidity sender, double temperature, double relativeHumidity)
        {
 
            temp = temperature;
            Humid = relativeHumidity;
            Debug.Print("Temperature1: " + temp + " Relative Humidity1: " + Humid);
        }

Sorry,my mistake.
It works now.
Thank you.

Pleasure. :slight_smile:

Any idea to make a measurement only when I need?
I try to explain. I need a class that have a function that returns some measurements from some sensors. So this function’s code may call tempHumidity and get values, call other sensors and get other values, and return an object containing all measurement from all sensors.

So I think is not possible a pattern when I request temp measurement, then handle the event that reports that data is available. I may exit the function returning requested data.
Or not?

thanks