/*
Mini weather station using AtTiny85
*/
#include <TinyDHT.h>
#include <TinyWireM.h>
#include <Tiny4kOLED.h>
#define DHTPIN PB1
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
const unsigned char img_thermometer[] PROGMEM = {
0x00, 0xfe, 0x03, 0xfe, 0x50,
0x00, 0xff, 0x00, 0xff, 0x55,
0x60, 0x9f, 0x80, 0x9f, 0x65,
};
void splash() {
oled.clear();
oled.setCursor(50, 0);
oled.print(F("Mini"));
oled.setCursor(5, 2);
oled.print(F("Weather Station"));
oled.setCursor(20, 4);
oled.print(F("IoT Projects"));
oled.setCursor(50, 6);
oled.print(F("Ideas"));
}
void prepareDisplay() {
unsigned int i, k;
unsigned char ch[5];
oled.clear();
oled.begin();
oled.setCursor(15, 0);
oled.print(F("ATtiny85 Mini"));
oled.setCursor(1, 2);
oled.print(F("Weather Station"));
oled.bitmap(2, 5, 7, 8, img_thermometer);
oled.setCursor(15, 4);
oled.print(F("Temp: 32.0 °C"));
oled.setCursor(15, 6);
oled.print(F("Humi: 67.0 %"));
}
void setup() {
//if (F_CPU == 16000000) clock_prescale_set(clock_div_1); // 5V Trinket: run at 16 MHz
dht.begin(); // Initialize DHT Teperature Sensor
oled.begin(128, 64, sizeof(tiny4koled_init_128x64br), tiny4koled_init_128x64br);
// Two fonts are supplied with this library, FONT8X16 and FONT6X8
oled.setFont(FONT8X16);
// To clear all the memory
oled.clear();
oled.on();
splash();
delay(3000);
prepareDisplay();
}
void loop() {
static long startTime = 0;
long currentTime;
// Get current time
currentTime = millis();
// Checks 1 second passed
// if ((currentTime - startTime) > 3000) {
startTime = currentTime;
// Update temperature
int16_t temperature = dht.readTemperature();
// Set cursor
oled.setCursor(15, 4);
oled.print("Temp: ");
// Print to display
oled.print(temperature, 1);
oled.print(" °C ");
// Update humidity
uint8_t humidity = dht.readHumidity();
// Set cursor
oled.setCursor(15, 6);
oled.print("Humi: ");
// Print to display
oled.print(humidity, 1);
oled.print(" % ");
oled.bitmap(2, 5, 7, 8, img_thermometer);
// }
}