Temperature/humidity sensor issue

I recently purchased the Lynx Green kit and I’m having problems with the temperature/humidity sensor. sometimes it works and sometimes it does not. It seems at times it goes into a loop while reading data and never exits. The light and moisture sensors work properly.

Is this a bad sensor or am I doing something wrong?

this is my main.cpp:

 #include <Modules/TempHumidity.h>
 #include <Modules/LightSense.h>

using namespace gadgeteering;
using namespace gadgeteering::mainboards;
using namespace gadgeteering::modules;
using namespace gadgeteering::system;

int main(int argc, char** argv)
	fez_lynx_s4 board;

	double temp;
	double humidity;
	temp_humidity tempHumidity(4);

	light_sense light(1);

	for(int x=0; x<10; x++)
		unsigned int l = light.get_illuminance();

		tempHumidity.take_measurements(temp, humidity);

	return 0;

this is the code in TempHumidity.cpp which never exits:

//It will take up to 80ms to read. Sensor will
// pull DATA line low when ready
// TODO make this blocking (interrupt?)
while (this->data.read())


You do a While on a read. Does this method returns ture/false or the number of read bytes ? In the second case, you should try :

while(this->data.Read() > 0)

Try to put a complete code that will make your problem simpler to diag…

The TempHumidity module is a Seeed module and the C++ Gadgeteering code was a straight port to C++ of their C# driver. It looks like the sensor never pulls the line low like it should so you are stuck looping. I would try different sockets and/or a simpler project with just that module.

@ John - I tried both using a different socket and a project with just the single sensor and still had the same issue. Is this a code, sensor or mainboard issue?

@ LouisCpro - the code in main.cpp is my complete code. The while statement is part of the sdk (TempHumidity.cpp). I tried modifying the sensor code as you suggested by using “while(this->data.Read() > 0)”. still had the same issue.


How often does it work and not work usually?

@ John - about 50% of the time I can get one or two readings before it hangs. the other 50% I never get a reading.