Had a bit of trouble with this one. The I2C bus didn't seem to work even though it compiled fine, it just hung. Put in LED stuff to see where it hung. Used Bus Pirate to monitor the bus to try to figure out what was going on. I think it was the missing Wire.begin(). Used in-line code instead of using the Digilent Library directly since had problems with #include for their library. (Need to view page source for #includes??)
//#include
#include
#define ALERT_PIN 2
#define IOShieldTempAddr 0x48
int ld4 = 74;
void setup()
{
Serial.begin(115200);
Serial.println("Serial Port 115200");
pinMode(ALERT_PIN, INPUT);
pinMode(ld4, OUTPUT);
byte error, address;
Wire.begin();
uint8_t temp[2] = {0};
temp[0] = 0x01;
temp[1] = 0xC4;
Wire.beginTransmission(IOShieldTempAddr); // actual address, but need shift up and add r/w
Wire.send(temp, 2);
error = Wire.endTransmission();
digitalWrite(ld4, HIGH); // set the LED on
delay(2000);
Serial.print("error = ");
Serial.println(error);
if (error == 0){
digitalWrite(ld4, LOW); // set the LED on
}
//Set the range to bring the alert pin high if it's above 78F (25.5C), alert will stay
//high until the temp drops below 75.2F (24C).
//IOShieldTemp.setTempLimit(IOShieldTemp.convFtoC(78)); // 78.0F ~ 25.5C
//IOShieldTemp.setTempHyst(24); // 75.2F ~ 24.0C
}
void loop()
{
float tempF, tempC;
//Get Temperature in Celsius.
//tempC = IOShieldTemp.getTemp();
float tempResult;
int16_t wResult = 0;
uint8_t temp[2] = {0};
int index = 0;
Wire.beginTransmission(IOShieldTempAddr);
Wire.send(temp, 1);
Wire.endTransmission();
Wire.requestFrom(IOShieldTempAddr, 2);
while(Wire.available())
{
temp[index++] = Wire.receive();
}
// Convert the result
wResult = temp[1] | (temp[0] << 8);
tempResult = wResult/256.0;
// Convert the result to Fahrenheit.
//tempF = IOShieldTemp.convCtoF(tempC);
//
tempC = tempResult;
Serial.print(tempResult);
Serial.print(" C, ");
tempF = tempC*9.0/5.0+32.0;
Serial.print(tempF);
Serial.print(" F");
Serial.println();
delay(5000);
}