#include "U8glib.h"
#include <SD.h>
#include "RTClib.h"
#include "DHT.h"
#define DHT11Pin 2
#define DHTType DHT22
RTC_DS1307 rtc;
#define CS_PIN 10
String sd_status;
String clock_status;
String Date;
String Time;
DHT HT(DHT11Pin,DHTType);
float humi;
float tempC;
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE|U8G_I2C_OPT_DEV_0); // I2C / TWI
const unsigned char plug [] PROGMEM = {
// 'Pictogrammers-Material-Power-plug, 16x16px
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xc0, 0x3f, 0xe0, 0x3f, 0xfc, 0x07, 0xfc,
0x07, 0xfc, 0x3f, 0xfc, 0x3f, 0xe0, 0x07, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
// 'Icons8-Windows-8-Industry-Processor', 16x16px
const unsigned char cpu_icon [] PROGMEM = {
0x0a, 0x50, 0x00, 0x00, 0x3f, 0xfc, 0x2f, 0xfc, 0xbf, 0xfd, 0x3f, 0xfc, 0xbf, 0xfd, 0x3f, 0xfc,
0x3f, 0xfc, 0xbf, 0xfd, 0x3f, 0xfc, 0xbf, 0xfd, 0x3f, 0xf4, 0x3f, 0xfc, 0x00, 0x00, 0x0a, 0x50
};
// 'Pictogrammers-Material-Sd', 16x16px
const unsigned char sd_icon [] PROGMEM = {
0x00, 0x00, 0x01, 0xf8, 0x07, 0xf8, 0x0e, 0xa8, 0x1e, 0xa8, 0x1f, 0xf8, 0x1f, 0xf8, 0x1f, 0xf8,
0x1f, 0xf8, 0x1f, 0xf8, 0x1f, 0xf8, 0x1f, 0xf8, 0x1f, 0xf8, 0x1f, 0xf8, 0x1f, 0xf8, 0x00, 0x00
};
// 'Custom-Icon-Design-Mono-General-3-Wifi', 16x16px
const unsigned char Wifi_icon [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x07, 0xe0, 0x1f, 0xf8, 0x70, 0x0e, 0xe0, 0x07, 0x07, 0xe0, 0x1e, 0x78,
0x18, 0x18, 0x03, 0xc0, 0x07, 0xe0, 0x00, 0x00, 0x01, 0x80, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00
};
const unsigned char empty_icon [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
const unsigned char Temperature_2 [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x07, 0x80, 0x1f, 0x00,
0x0c, 0x80, 0x3f, 0x80, 0x08, 0x80, 0x7f, 0x80, 0x0c, 0x80, 0x7f, 0xc0, 0x0f, 0x80, 0xff, 0xe0,
0x0f, 0x81, 0xff, 0xe0, 0x0f, 0x81, 0xff, 0xf0, 0x0f, 0x83, 0xff, 0xf0, 0x0f, 0x83, 0xff, 0xf8,
0x0f, 0x83, 0xff, 0xf8, 0x0f, 0x87, 0xff, 0xf8, 0x0f, 0xc7, 0xff, 0xf8, 0x1f, 0xc7, 0xff, 0xf8,
0x1f, 0xe3, 0xff, 0xf8, 0x1f, 0xe3, 0xff, 0xf8, 0x1f, 0xc3, 0xff, 0xf0, 0x1f, 0xc1, 0xff, 0xf0,
0x0f, 0x80, 0xff, 0xe0, 0x00, 0x00, 0x7f, 0x80, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
const unsigned char Therm_icon [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00,
0x00, 0xcc, 0x00, 0x00, 0x00, 0xcc, 0x00, 0x00, 0x00, 0xcc, 0xff, 0xc0, 0x00, 0xcc, 0xff, 0xc0,
0x00, 0xcc, 0x00, 0x00, 0x00, 0xcc, 0x00, 0x00, 0x00, 0xcc, 0xff, 0x00, 0x00, 0xcc, 0xff, 0x00,
0x00, 0xcc, 0x00, 0x00, 0x00, 0xcc, 0x00, 0x00, 0x00, 0xcc, 0xff, 0xc0, 0x00, 0xcc, 0xff, 0xc0,
0x00, 0xcc, 0x00, 0x00, 0x00, 0xcc, 0x00, 0x00, 0x00, 0xcc, 0xff, 0x00, 0x00, 0xcc, 0xff, 0x00,
0x00, 0xcc, 0x00, 0x00, 0x00, 0xcc, 0x00, 0x00, 0x01, 0x86, 0x00, 0x00, 0x03, 0x03, 0x00, 0x00,
0x03, 0x33, 0x00, 0x00, 0x03, 0x33, 0x00, 0x00, 0x03, 0x03, 0x00, 0x00, 0x01, 0x86, 0x00, 0x00,
0x01, 0xfe, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
// 'Custom-Icon-Design-Pretty-Office-7-Calendar', 32x32px
const unsigned char Date_icon [] PROGMEM = {
0x00, 0xe0, 0x06, 0x00, 0x00, 0xf0, 0x0f, 0x00, 0x00, 0xf0, 0x0f, 0x00, 0x01, 0xf0, 0x0f, 0x00,
0x00, 0xf0, 0x0f, 0x00, 0x00, 0xf0, 0x0f, 0x00, 0x00, 0xe0, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xfc, 0x7f, 0xff, 0xff, 0xfc, 0x7f, 0xff, 0xff, 0xfc,
0x7f, 0xff, 0xff, 0xfc, 0x7f, 0x9f, 0xff, 0xfc, 0x7e, 0x6f, 0xff, 0xfc, 0x7f, 0xf7, 0xff, 0xfc,
0x7b, 0xf7, 0xff, 0xfc, 0x7b, 0xf7, 0xff, 0xfc, 0x79, 0xf7, 0xff, 0xfc, 0x7c, 0xe7, 0xff, 0xfc,
0x7e, 0x1f, 0xff, 0xfc, 0x7f, 0xff, 0xff, 0xfc, 0x7f, 0xff, 0xff, 0xfc, 0x3f, 0xff, 0xff, 0xfc,
0x3f, 0xff, 0xff, 0xfc, 0x1f, 0xff, 0xff, 0xf8, 0x00, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00
};
const unsigned char Sun_icon [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xe0, 0x00, 0x00, 0x07, 0xfc, 0x00, 0x00, 0x0c, 0x0e, 0x00, 0x00, 0x08, 0x02, 0x00, 0x00,
0x10, 0x01, 0x00, 0x00, 0x30, 0x03, 0x80, 0x00, 0x30, 0x1f, 0xe0, 0x00, 0x10, 0x3f, 0xf0, 0x00,
0x10, 0x7f, 0xff, 0x00, 0x30, 0xff, 0xff, 0xc0, 0x10, 0xff, 0xff, 0xe0, 0x09, 0xff, 0xff, 0xf0,
0x0d, 0xff, 0xff, 0xf8, 0x07, 0xff, 0xff, 0xf8, 0x0f, 0xff, 0xff, 0xfc, 0x1f, 0xff, 0xff, 0xfc,
0x1f, 0xff, 0xff, 0xfc, 0x3f, 0xff, 0xff, 0xfc, 0x3f, 0xff, 0xff, 0xfc, 0x3f, 0xff, 0xff, 0xfc,
0x3f, 0xff, 0xff, 0xf8, 0x3f, 0xff, 0xff, 0xf8, 0x1f, 0xff, 0xff, 0xf0, 0x0f, 0xff, 0xff, 0xe0,
0x07, 0xff, 0xff, 0xc0, 0x03, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
void draw(void) {
// graphic commands to redraw the complete screen should be placed here
u8g.drawBitmapP(0, 0, 2, 16, plug);
if (clock_status!="Fail")
u8g.drawBitmapP(20, 0, 2, 16, cpu_icon);
else if (clock_status=="Fail")
u8g.drawBitmapP(20, 0, 2, 16, empty_icon);
if (sd_status=="Done")
u8g.drawBitmapP(40, 0, 2, 16, sd_icon);
else if (sd_status=="Fail")
u8g.drawBitmapP(50, 0, 2, 16, empty_icon);
u8g.drawBitmapP(60, 0, 2, 16, Wifi_icon);
u8g.setFont(u8g_font_8x13);
u8g.setPrintPos(78,13);
u8g.print("FRESCO");
}
void draw_1(void){
u8g.firstPage(); // first page
do {
draw();
delay(100);
u8g.setFont(u8g_font_8x13);
u8g.setPrintPos(3,30);
u8g.print("Date & Time");
u8g.setPrintPos(0,45);
u8g.print(Date);
u8g.setPrintPos(0,60);
u8g.print(Time);
u8g.drawBitmapP(90, 25, 4,32,Date_icon);
}
while( u8g.nextPage() );
delay(2000);
u8g.firstPage(); // first page
do {
draw();
delay(100);
u8g.setFont(u8g_font_8x13);
u8g.setPrintPos(3,30);
u8g.print("Tamb & Hum 1");
u8g.setPrintPos(5,40);
u8g.print(tempC);
u8g.setPrintPos(45,40);
u8g.print("C");
u8g.setPrintPos(10,60);
u8g.print(humi);
u8g.setPrintPos(55,60);
u8g.print("%");
u8g.drawBitmapP(90, 25, 4,32,Temperature_2);
}
while( u8g.nextPage() );
//u8g.firstPage(); // first page
delay(2000);
u8g.firstPage(); // first page
do {
draw();
delay(100);
u8g.setFont(u8g_font_8x13);
u8g.setPrintPos(3,30);
u8g.print("Tamb & Hum 2");
u8g.setPrintPos(5,40);
u8g.print(tempC*2);
u8g.setPrintPos(45,40);
u8g.print("C");
u8g.setPrintPos(10,60);
u8g.print(humi/2);
u8g.setPrintPos(55,60);
u8g.print("%");
u8g.drawBitmapP(90, 25, 4,32,Temperature_2);
}
while( u8g.nextPage() );
delay(2000);
}
void setup() {
Serial.begin(9600);
HT.begin();
Serial.print("Initializing SD card... ");
if (!SD.begin(CS_PIN)) {
Serial.println("Card initialization failed!");
sd_status = "Fail";
while (true);
}
Serial.println("initialization done.");
sd_status = "Done";
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
clock_status = "Fail";
Serial.flush();
abort();
}
u8g.firstPage(); // first page
do {
draw();
}
while( u8g.nextPage() );
}
void loop() {
humi = HT.readHumidity();
//Serial.println(humi);
tempC = HT.readTemperature();
DateTime now = rtc.now();
Serial.print("Current time: ");
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.println(now.day(), DEC);
//
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
Date = String(now.year(), DEC)+String(":")+String(now.month(), DEC)+String(":")+String(now.day(), DEC);
Time = String(now.hour(), DEC)+String(":")+String(now.minute(), DEC)+String(":")+String(now.second(), DEC);
u8g.firstPage(); // first page
do {
draw_1();
}
while( u8g.nextPage() );
}