I added delay(1); into the empty while loop again. This enabled me to get an incorrect temp and an incorrect humid reading without the watchdog timer resetting. Here's my sketch:
/****************************************************************
* ReadSHT2x
* An example sketch that reads the sensor and prints the
* relative humidity to the PC's serial port
*
* Tested with:
* - SHT21-Breakout Humidity sensor from Modern Device
* - SHT2x-Breakout Humidity sensor from MisensO Electronics
***************************************************************/
#include <Wire.h>
#include <SHT2x.h>
void setup()
{
Serial.begin(115200);
//delay(5000);
Serial.println();
Serial.println("Starting Wire...");
Wire.begin(2, 0);
Serial.println("Wire Started");
}
void loop()
{
Serial.println();
Serial.print("Humidity(%RH): ");
Serial.print(SHT2x.GetHumidity());
Serial.print(" Temperature(C): ");
Serial.println(SHT2x.GetTemperature());
delay(1000);
}
and here's the modified library code:
/*
SHT2x - A Humidity Library for Arduino.
Supported Sensor modules:
SHT21-Breakout Module - http://www.moderndevice.com/products/sht21-humidity-sensor
SHT2x-Breakout Module - http://www.misenso.com/products/001
Created by Christopher Ladden at Modern Device on December 2009.
Modified by Paul Badger March 2010
Modified by www.misenso.com on October 2011:
- code optimisation
- compatibility with Arduino 1.0
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <inttypes.h>
#include <Wire.h>
#include "Arduino.h"
#include "SHT2x.h"
/******************************************************************************
* Global Functions
******************************************************************************/
/**********************************************************
* GetHumidity
* Gets the current humidity from the sensor.
*
* @return float - The relative humidity in %RH
**********************************************************/
float SHT2xClass::GetHumidity(void)
{
return (-6.0 + 125.0 / 65536.0 * (float)(readSensor(eRHumidityHoldCmd)));
}
/**********************************************************
* GetTemperature
* Gets the current temperature from the sensor.
*
* @return float - The temperature in Deg C
**********************************************************/
float SHT2xClass::GetTemperature(void)
{
return (-46.85 + 175.72 / 65536.0 * (float)(readSensor(eTempHoldCmd)));
}
/******************************************************************************
* Private Functions
******************************************************************************/
uint16_t SHT2xClass::readSensor(uint8_t command)
{
uint16_t result;
Wire.beginTransmission(eSHT2xAddress); //begin
Wire.write(command); //send the pointer location
delay(100);
Wire.endTransmission(); //end
delay(100);
Wire.requestFrom(eSHT2xAddress, 3);
while(Wire.available() < 3) {
delay(1);; //wait
}
//Store the result
result = ((Wire.read()) << 8);
result += Wire.read();
result &= ~0x0003; // clear two low bits (status bits)
return result;
}
SHT2xClass SHT2x;
Output now shows the following and then hangs:
Starting Wire...
Wire Started
Humidity(%RH): 118.99 Temperature(C): 128.86