/*
 * 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);
}
uno:A5.2
uno:A4.2
uno:AREF
uno:GND.1
uno:13
uno:12
uno:11
uno:10
uno:9
uno:8
uno:7
uno:6
uno:5
uno:4
uno:3
uno:2
uno:1
uno:0
uno:IOREF
uno:RESET
uno:3.3V
uno:5V
uno:GND.2
uno:GND.3
uno:VIN
uno:A0
uno:A1
uno:A2
uno:A3
uno:A4
uno:A5
oled2:DATA
oled2:CLK
oled2:DC
oled2:RST
oled2:CS
oled2:3V3
oled2:VIN
oled2:GND
oled1:DATA
oled1:CLK
oled1:DC
oled1:RST
oled1:CS
oled1:3V3
oled1:VIN
oled1:GND
dht1:VCC
dht1:SDA
dht1:NC
dht1:GND