Page 1 of 1

Temperature Library

Posted: Tue May 08, 2012 11:58 am
by acburk
Hi, I'm having problems with the temperature sensor ( http://shop.moderndevice.com/products/t ... ure-sensor ) since updating to Arduino 1.0 IDE and using the new temperature library. It's like it just freezes on GetTemperature(). Anyone else having this problem or know a solution?

Re: Temperature Library

Posted: Mon May 14, 2012 9:06 am
by motarius
Yup, I ran into a similar problem. I seem to remember that this would happen when I requested temperature from an invalid address. But I could also see it happening if it's not wired correctly. The way the Lib Temperature is written, after it requests a value from a temperature node it will enter a while loop that will wait for data to be received on the bus. If no data is ever received it will just keep waiting in that loop forever. So the solution to this problem was to put bounds on this loop, an int counter that would function like a timeout. Here's a snippet from my revised library, to illustrate:

Code: Select all

uint8_t LibTemp::getRegisterValue(uint8_t deviceAddress, uint8_t registerID, uint8_t responseBytesExpected, uint8_t timeout_ms)
	{
	unsigned long startTime = millis();
	sendCommand(deviceAddress,registerID); //just like send command but this time we wait for input
	Wire.requestFrom(deviceAddress, responseBytesExpected);

	    while(Wire.available() <= 0)
	    	{
	    	if (millis() - startTime >= timeout_ms)
	    		{
				break; 
				}
	    	}

    return Wire.read();
	}

Re: Temperature Library

Posted: Mon Jun 04, 2012 10:31 pm
by DaveW
I just purchased the MD0530 temperature/humidity sensor and the MD0545 temperature sensor. I downloaded the sample code from GITHUB to the Arduino 1.0.1 IDE, but when I try to compile the code to upload to an Arduino Uno from my mac I get errors.

For MD0530 I get 'LibHumidity' does not name a type.
For MD0545 I get 'LibTempTMP421' does not name a type.

Does anyone have an idea what could be causing this and how to fix it?

-DaveW