/**************************************************************************
This is an example for our Monochrome OLEDs based on SSD1306 drivers
Pick one up today in the adafruit shop!
------> http://www.adafruit.com/category/63_98
This example is for a 128x64 pixel display using I2C to communicate
3 pins are required to interface (two I2C and one reset).
Adafruit invests time and resources providing this open
source code, please support Adafruit and open-source
hardware by purchasing products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries,
with contributions from the open source community.
BSD license, check license.txt for more information
All text above, and the splash screen below must be
included in any redistribution.
**************************************************************************/
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <dht.h>
dht DHT;
#define DHT22_PIN 5
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display_sx(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
Adafruit_SSD1306 display_dx(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
void setup() {
Serial.begin(9600);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display_sx.begin(SSD1306_SWITCHCAPVCC, 0x3D)) { // Address 0x3D for 128x64
Serial.println(F("SSD1306 SX allocation failed"));
for(;;); // Don't proceed, loop forever
}
// Clear the buffer
display_sx.clearDisplay();
display_sx.setTextSize(2); // Draw 2X-scale text
display_sx.setTextColor(SSD1306_WHITE);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display_dx.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
// Clear the buffer
display_dx.clearDisplay();
display_dx.setTextSize(2); // Draw 2X-scale text
display_dx.setTextColor(SSD1306_WHITE);
}
void updateTemperatureHumidity() {
int chk = DHT.read22(DHT22_PIN);
if (chk == DHTLIB_OK) {
display_sx.clearDisplay();
display_sx.setCursor(0, 0);
display_sx.print(DHT.humidity, 1);
display_sx.print(" Hg");
display_sx.display();
display_dx.clearDisplay();
display_dx.setCursor(0, 0);
display_dx.cp437(true);
display_dx.print(DHT.temperature, 1);
display_dx.print(" ");
display_dx.print((char) 248);
display_dx.print("C");
display_dx.display();
}
}
void loop() {
updateTemperatureHumidity();
}