#include <Wire.h>
#include <Arduino.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "Adafruit_SHT31.h"
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3C for 128x64
#define LOGO_HEIGHT 16
#define LOGO_WIDTH 16
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
bool enableHeater = false;
Adafruit_SHT31 sht31 = Adafruit_SHT31();
const unsigned char termo [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x86, 0x00, 0x00, 0x03, 0xcf, 0x00, 0x00,
0x06, 0xc9, 0x38, 0x00, 0x06, 0x4f, 0x70, 0x00, 0x06, 0x46, 0x40, 0x00, 0x06, 0x40, 0xc0, 0x00,
0x06, 0x40, 0xc0, 0x00, 0x06, 0x40, 0x60, 0x00, 0x06, 0x40, 0x38, 0x00, 0x06, 0x40, 0x18, 0x00,
0x02, 0x40, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00,
0x06, 0x60, 0x00, 0x00, 0x0c, 0x20, 0x00, 0x00, 0x0c, 0x30, 0x00, 0x00, 0x0c, 0x30, 0x00, 0x00,
0x0c, 0x60, 0x00, 0x00, 0x07, 0xe0, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00
};
const unsigned char humi [] PROGMEM = {
0x00, 0x60, 0x00, 0x00, 0x60, 0x00, 0x00, 0xf0, 0x00, 0x01, 0xf8, 0x00, 0x03, 0xfc, 0x00, 0x03,
0xfc, 0x00, 0x07, 0xfe, 0x00, 0x0f, 0xff, 0x00, 0x0e, 0x3f, 0x00, 0x1c, 0xb3, 0x80, 0x1e, 0x27,
0x80, 0x1f, 0xcf, 0x80, 0x3f, 0x9f, 0xc0, 0x1f, 0x3f, 0x80, 0x1e, 0x47, 0x80, 0x1c, 0xd3, 0x80,
0x0f, 0xc7, 0x00, 0x0f, 0xff, 0x00, 0x03, 0xfc, 0x00, 0x01, 0xf8, 0x00
};
const unsigned char HAPPY [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x01, 0xff, 0xc0, 0x00, 0x03, 0xff, 0xe0, 0x00,
0x07, 0xff, 0xf0, 0x00, 0x0f, 0xff, 0xf8, 0x00, 0x1f, 0xff, 0xfc, 0x00, 0x3f, 0xff, 0xfe, 0x00,
0x3e, 0x3e, 0x3e, 0x00, 0x3c, 0x1c, 0x1e, 0x00, 0x7f, 0xff, 0xff, 0x00, 0x7f, 0xff, 0xff, 0x00,
0x7f, 0xff, 0xff, 0x00, 0x7c, 0x00, 0x1f, 0x00, 0x7c, 0x00, 0x1f, 0x00, 0x3c, 0x00, 0x1e, 0x00,
0x3e, 0x00, 0x3e, 0x00, 0x3e, 0x00, 0x3e, 0x00, 0x1f, 0x00, 0x7c, 0x00, 0x0f, 0xc1, 0xf8, 0x00,
0x07, 0xff, 0xf0, 0x00, 0x03, 0xff, 0xe0, 0x00, 0x01, 0xff, 0xc0, 0x00, 0x00, 0x3e, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00
};
const unsigned char SHR [] PROGMEM = {
0x00, 0x1c, 0x00, 0x00, 0x00, 0xff, 0x80, 0x00, 0x03, 0xff, 0xe0, 0x00, 0x07, 0xff, 0xf0, 0x00,
0x0f, 0xff, 0xf8, 0x00, 0x1f, 0xff, 0xfc, 0x00, 0x3f, 0xff, 0xfe, 0x00, 0x3f, 0x7f, 0x7e, 0x00,
0x7e, 0x7f, 0x3f, 0x00, 0x7d, 0xdd, 0xdf, 0x00, 0x7c, 0x1c, 0x1f, 0x00, 0xfc, 0x3e, 0x1f, 0x80,
0xff, 0xff, 0xff, 0x80, 0xff, 0xff, 0xff, 0x80, 0x7f, 0xff, 0xff, 0x00, 0x7f, 0xff, 0xff, 0x00,
0x7f, 0x00, 0x7f, 0x00, 0x3f, 0xff, 0xfe, 0x00, 0x3f, 0xff, 0xfe, 0x00, 0x1f, 0xff, 0xfc, 0x00,
0x0f, 0xff, 0xf8, 0x00, 0x07, 0xff, 0xf0, 0x00, 0x03, 0xff, 0xe0, 0x00, 0x00, 0xff, 0x80, 0x00,
0x00, 0x1c, 0x00, 0x00
};
const unsigned char SAD [] PROGMEM = {
0x00, 0x7f, 0x00, 0x00, 0x01, 0xff, 0xc0, 0x00, 0x07, 0xff, 0xf0, 0x00, 0x0f, 0xff, 0xf8, 0x00,
0x1f, 0xff, 0xfc, 0x00, 0x3f, 0xff, 0xfe, 0x00, 0x3f, 0xff, 0xfe, 0x00, 0x7f, 0xff, 0xff, 0x00,
0x7f, 0xff, 0xff, 0x00, 0xfe, 0x7f, 0x3f, 0x80, 0xfe, 0xff, 0xbf, 0x80, 0xff, 0xff, 0xff, 0x80,
0xff, 0xff, 0xff, 0x80, 0xff, 0xff, 0xff, 0x80, 0xff, 0xc1, 0xff, 0x80, 0xff, 0x00, 0x7f, 0x80,
0x7e, 0x3e, 0x3f, 0x00, 0x7e, 0x7f, 0x3f, 0x00, 0x3f, 0xff, 0xfe, 0x00, 0x3f, 0xff, 0xfe, 0x00,
0x1f, 0xff, 0xfc, 0x00, 0x0f, 0xff, 0xf8, 0x00, 0x07, 0xff, 0xf0, 0x00, 0x01, 0xff, 0xc0, 0x00,
0x00, 0x7f, 0x00, 0x00
};
void setup() {
Serial.begin(115200);
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
while (!Serial)
delay(10);
Serial.println("SHT31 test");
if (!sht31.begin(0x44)) { // 0x45 for alternate i2c addr
Serial.println("Couldn't find SHT31");
while (1) delay(1);
}
Serial.print("Heater Enabled State: ");
if (sht31.isHeaterEnabled())
Serial.println("ENABLED");
else
Serial.println("DISABLED");
display.clearDisplay();
display.drawBitmap(25,0,termo,25,25,WHITE);
display.drawBitmap(70,0,humi,20,20,WHITE);
display.display();
}
void loop() {
display_sht31();
delay(2000);
}
void display_sht31() {
float t = sht31.readTemperature();
float h = sht31.readHumidity();
if (! isnan(t)) { // check if 'is not a number'
Serial.print("Temp *C = "); Serial.print(t); Serial.print("\t\t");
} else {
Serial.println("Failed to read temperature");
}
if (! isnan(h)) { // check if 'is not a number'
Serial.print("Hum. % = "); Serial.println(h);
} else {
Serial.println("Failed to read humidity");
}
delay(1000);
display.setTextColor(WHITE);
display.setCursor(30, 8);
display.print(t);
display.drawBitmap(5,0,termo,25,25,WHITE);
display.setTextColor(WHITE);
display.setCursor(85, 8);
display.print(h);
display.drawBitmap(65,0,humi,20,20,WHITE);
display.display();
delay(1000);
display.clearDisplay();
if (t > 25.99 & t < 28.99) {
display.drawBitmap(46,20,HAPPY,25,25,WHITE);
display.display();
delay(5000);
display.clearDisplay();
}
if (t < 26) {
display.drawBitmap(46,20,SHR,25,25,WHITE);
display.display();
delay(5000);
display.clearDisplay();
}
if (t > 28) {
display.drawBitmap(46,20,SAD,25,25,WHITE);
display.display();
delay(5000);
display.clearDisplay();
}
}