/*
 * Doppio Oled con Arduino Uno e 2 canali I2C
 * Gruppo Utenti Linux Livorno https://linux.livorno.it
 */
#include <dht.h>
#include <U8g2lib.h>

dht DHT;

#define DHT22_PIN 5

#define SDA_RIGHT A2
#define SCL_RIGHT A3
#define SCREEN_RESET U8X8_PIN_NONE

// SSD1306 display connected with hardware I2C (A4=SDA, A5=SCL)
U8X8_SSD1306_128X64_NONAME_HW_I2C screen_left(SCREEN_RESET);
// SSD1306 display connected with software I2C
U8X8_SSD1306_128X64_NONAME_SW_I2C screen_right(SCL_RIGHT, SDA_RIGHT, SCREEN_RESET);

void setup() {
  Serial.begin(9600);

  screen_left.begin();
  //screen_left.enableUTF8Print();
  screen_left.setFont(u8x8_font_chroma48medium8_r);

  screen_right.begin();
  //screen_right.enableUTF8Print();
  screen_right.setFont(u8x8_font_chroma48medium8_r);
}

void updateTemperatureHumidity() {
  int result = DHT.read22(DHT22_PIN);
  if (result == DHTLIB_OK) {
    Serial.print("humidity ");
    Serial.print(DHT.humidity);
    Serial.print(" temperature ");
    Serial.println(DHT.temperature);

    screen_left.clear();
    screen_left.setCursor(1, 0);
    screen_left.print(DHT.humidity, 0);
    screen_left.print("% Hg");

    screen_right.clear();
    screen_right.setCursor(1, 0);
    screen_right.print(DHT.temperature, 1);
    screen_right.print(" °C");
  }
}

void loop() {
  updateTemperatureHumidity();
  delay(2000);
}