#define DHT_NODE_ADDRESS 1 // I2C address of the DHT22 slave module #include #include #define DHTPIN 4 // DHT connected to ATtiny412 pin 4 (PA3) #define DHTTYPE DHT22 // DHT 22 (AM2302) DHTStable DHT; // initialize the DHT library // Initialize the humidity and temperature variables int humidity = 0; int temperature = 0; void setup() { Wire.begin(DHT_NODE_ADDRESS); // join i2c bus with defined address Wire.onRequest(requestEvent); // register event } void loop() { DHT.read22(DHTPIN); // Read DHT22 data. temperature = DHT.getTemperature(); humidity = DHT.getHumidity(); delay(2000); /* Add 2 second delay in the loop */ } void requestEvent() { Wire.write(temperature); // respond with message of 4 bytes Wire.write(humidity); // respond with message of 4 bytes }