Code: Select all
/*
Read the temperature from an LM75-derived temperature sensor, and display it
in Celcius every 250ms. Any LM75-derived temperature should work.
*/
#include <Temperature_LM75_Derived.h>
// The Generic_LM75 class will provide 9-bit (±0.5°C) temperature for any
// LM75-derived sensor. More specific classes may provide better resolution.
//Generic_LM75 temperature;
Generic_LM75 temperature(0x49);
void scanI2C() {
byte error, address;
int nDevices;
Serial.println("Scanning...");
nDevices = 0;
for(address = 1; address < 127; address++ ) {
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0) {
Serial.print("I2C device found at address 0x");
if (address<16) {
Serial.print("0");
}
Serial.println(address,HEX);
nDevices++;
}
else if (error==4) {
}
}
if (nDevices == 0) {
Serial.println("No I2C devices found\n");
}
else {
Serial.println("done\n");
}
}
void setup() {
Serial.begin(115200);
Wire.begin();
}
float readI2CTemperature() {
//Serial.print("Temperature = ");
//Serial.print(temperature.readTemperatureC());
return temperature.readTemperatureC();
}
void loop() {
Serial.println(readI2CTemperature());
}