A bit about it
This project uses the Freetronics OLED Display and DHT22 module from Freetronics (with a few modifications to make it fit). It also includes a DS1307 RTC Module for time and 4 SMD LEDs for status. Put it in a case with a old NOKIA phone charger and switch and combine with Arduino and my OLED Shield and you get this a Temperature, Humidity and Time + Date on OLED Display.
The first stage of CODE
The first stage of CODE
Warning: Embedding code files within the project story has been deprecated. To edit this file or add more files, go to the "Software" tab. To remove this file from the story, click on it to trigger the context menu, then click the trash can button (this won't delete it from the "Software" tab).
/*OLED Temprature, Humid and time
Created 19/09/2013
Jed Hodson
*/
#include <SPI.h>
#include <SD.h>
#include <FTOLED.h>
#include <fonts/SystemFont5x7.h>
#include <fonts/Arial14.h>
#include <fonts/Arial_Black_16.h>
#include <fonts/Droid_Sans_36.h>
#include "DHT.h"
#include <Wire.h>
#include "RTClib.h"
#define DHTPIN 4
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
RTC_DS1307 RTC;
const byte pin_cs = 7;
const byte pin_dc = 2;
const byte pin_reset = 3;
OLED oled(pin_cs, pin_dc, pin_reset);
OLED_TextBox temp(oled,20,7,30,17);
OLED_TextBox humid(oled,72,7,30,17);
OLED_TextBox date(oled,35,105,128,15);
OLED_TextBox time(oled,35,52,128,32);
const char *WELCOME = "Temprature,\nHumidity \nand Time\nOn OLED \nDisplay\nJed Hodson \n2013";
const char *ERRORHAP = "An ERROR has\noccured,\nplease check\nwiring and try\nagain later!";
void setup() {
//Start everything up
oled.begin();
dht.begin();
Wire.begin();
RTC.begin();
//Display start up message
oled.selectFont(Arial14);
oled.drawString(10,101,WELCOME,GREEN,BLACK);
delay(5000);
//Check everythings connected
//No RTC!
if (! RTC.isrunning()) {
oled.selectFont(Arial14);
//DISPLAY ERROR MESSAGE
oled.drawString(10,101,ERRORHAP,RED,BLACK);
delay(2500);
// following line sets the RTC to the date & time this sketch was compiled
RTC.adjust(DateTime(__DATE__, __TIME__));
}
//And DHT22
float h = dht.readHumidity();
float t = dht.readTemperature();
// check if returns are valid, if they are NaN (not a number) then something went wrong!
if (isnan(t) || isnan(h)) {
oled.drawString(10,101,ERRORHAP,RED,BLACK);
delay(2500);
}
//debug
Serial.begin(9600);
}
void loop() {
while(1){
oled.begin();
Serial.println("loop success");
float h = dht.readHumidity();
float t = dht.readTemperature();
DateTime now = RTC.now();
//Time to make some Strings
String dateString = "";
dateString += String(now.day());
dateString += "/";
dateString += String(now.month());
dateString += "/";
dateString += String(now.year());
int tempS = t;
String tempString = "";
tempString += String(tempS);
tempString += "*C";
int humidS = h;
String humidString = "";
humidString += String(humidS);
humidString += "%RH";
String timeString = "";
timeString += String(now.hour());
timeString += ":";
timeString += String(now.minute());
//Print Text
//Set colours
temp.setForegroundColour(RED);
humid.setForegroundColour(ROYALBLUE);
time.setForegroundColour(GREEN);
date.setForegroundColour(WHITE);
oled.selectFont(Arial_Black_16);
temp.print(tempString);
oled.selectFont(SystemFont5x7);
date.print(dateString);
oled.selectFont(Droid_Sans_36);
time.print(timeString);
oled.selectFont(Arial_Black_16);
humid.print(humidString);
temp.print(" ");
temp.reset();
time.print(" ");
time.reset();
date.print(" ");
date.reset();
humid.print(" ");
humid.reset();
delay(100);
}
}
Version 2
Version 2
Warning: Embedding code files within the project story has been deprecated. To edit this file or add more files, go to the "Software" tab. To remove this file from the story, click on it to trigger the context menu, then click the trash can button (this won't delete it from the "Software" tab).
/*OLED Temprature, Humid and time
Created 19/09/2013
Jed Hodson
*/
#include <SPI.h>
#include <SD.h>
#include <FTOLED.h>
#include <fonts/SystemFont5x7.h>
#include <fonts/Arial14.h>
#include <fonts/Arial_Black_16.h>
#include <fonts/Droid_Sans_36.h>
#include "DHT.h"
#include <Wire.h>
#include "RTClib.h"
#define DHTPIN 9
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
RTC_DS1307 RTC;
const byte pin_cs = 7;
const byte pin_dc = 2;
const byte pin_reset = 3;
OLED oled(pin_cs, pin_dc, pin_reset);
OLED_TextBox temp(oled,20,7,30,17);
OLED_TextBox humid(oled,72,7,30,17);
OLED_TextBox date(oled,35,105,128,15);
OLED_TextBox time(oled,35,52,128,32);
const char *WELCOME = "Temprature,\nHumidity \nand Time\nOn OLED \nDisplay\nJed Hodson \n2013";
const char *ERRORHAP = "An ERROR has\noccured,\nplease check\nwiring and try\nagain later!";
void setup() {
//Start everything up
oled.begin();
dht.begin();
Wire.begin();
RTC.begin();
//Display start up message
oled.selectFont(Arial14);
oled.drawString(10,101,WELCOME,GREEN,BLACK);
delay(5000);
//Check everythings connected
//No RTC!
if (! RTC.isrunning()) {
oled.selectFont(Arial14);
//DISPLAY ERROR MESSAGE
oled.drawString(10,101,ERRORHAP,RED,BLACK);
delay(2500);
// following line sets the RTC to the date & time this sketch was compiled
RTC.adjust(DateTime(__DATE__, __TIME__));
}
//And DHT22
float h = dht.readHumidity();
float t = dht.readTemperature();
// check if returns are valid, if they are NaN (not a number) then something went wrong!
if (isnan(t) || isnan(h)) {
oled.drawString(10,101,ERRORHAP,RED,BLACK);
delay(2500);
}
oled.clearScreen();
}
void loop() {
while(1){
float h = dht.readHumidity();
float t = dht.readTemperature();
DateTime now = RTC.now();
//Time to make some Strings
String dateString = "";
dateString += String(now.day());
dateString += "/";
dateString += String(now.month());
dateString += "/";
dateString += String(now.year());
int tempS = t;
String tempString = "";
tempString += String(tempS);
tempString += "*C";
int humidS = h;
String humidString = "";
humidString += String(humidS);
humidString += "RH";
String timeString = "";
timeString += String(now.hour());
timeString += ":";
timeString += String(now.minute());
//Print Text
//Set colours
temp.setForegroundColour(RED);
humid.setForegroundColour(ROYALBLUE);
time.setForegroundColour(GREEN);
date.setForegroundColour(WHITE);
oled.selectFont(Arial_Black_16);
temp.print(tempString);
oled.selectFont(SystemFont5x7);
date.print(dateString);
oled.selectFont(Droid_Sans_36);
time.print(timeString);
oled.selectFont(Arial_Black_16);
humid.print(humidString);
temp.reset();
time.reset();
date.reset();
humid.reset();
delay(100);
}
}
Version 3 Latest
Version 3 Latest
Warning: Embedding code files within the project story has been deprecated. To edit this file or add more files, go to the "Software" tab. To remove this file from the story, click on it to trigger the context menu, then click the trash can button (this won't delete it from the "Software" tab).
/*OLED Temprature, Humid and time
Created 14/10/2013
Jed Hodson
*/
#include <SPI.h>
#include <SD.h>
#include <FTOLED.h>
#include <fonts/SystemFont5x7.h>
#include <fonts/Arial14.h>
#include <fonts/Arial_Black_16.h>
#include <fonts/Droid_Sans_36.h>
#include "DHT.h"
#include <Wire.h>
#include "RTClib.h"
#define DHTPIN 9
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
RTC_DS1307 RTC;
const byte pin_cs = 7;
const byte pin_dc = 2;
const byte pin_reset = 3;
#define Green_LED 5
#define Blue1_LED 6
#define Blue2_LED 8
OLED oled(pin_cs, pin_dc, pin_reset);
OLED_TextBox temp(oled,20,7,30,17);
OLED_TextBox humid(oled,65,7,50,17);
OLED_TextBox date(oled,35,105,128,15);
OLED_TextBox time(oled,35,52,128,32);
#define WELCOME F("Temprature,\nHumidity \nand Time\nOn OLED \nDisplay\nJed Hodson \n2013")
#define ERRORI2C F("An ERROR has\noccured,\nplease I2C\nwiring and try\nagain later!")
#define ERRORDHT F("An ERROR has\noccured,\nplease DHT\nwiring and try\nagain later!")
void setup() {
//Start everything up
oled.begin();
dht.begin();
Wire.begin();
RTC.begin();
pinMode(Green_LED, OUTPUT);
pinMode(Blue1_LED, OUTPUT);
pinMode(Blue2_LED, OUTPUT);
//Preform Blink of the LEDs
Blink_Green();
Blink_Blue1();
Blink_Blue2();
//Display start up message
oled.selectFont(Arial14);
oled.drawString(10,101,WELCOME,GREEN,BLACK);
Blink_Green();
oled.clearScreen();
}
void loop() {
DateTime now = RTC.now();
//Always Check the DHT22 for unplug
byte h = dht.readHumidity();
byte t = dht.readTemperature();
// check if returns are valid, if they are NaN (not a number) then something went wrong!
if (isnan(t) || isnan(h)) {
oled.drawString(10,101,ERRORDHT,RED,BLACK);
delay(2500);
oled.drawString(10,101,"",RED,BLACK);
Blink_Blue1();
}
//And the RTC just in case
if (! RTC.isrunning()) {
oled.selectFont(Arial14);
//DISPLAY ERROR MESSAGE
oled.drawString(10,101,ERRORI2C,RED,BLACK);
delay(2500);
oled.drawString(10,101,"",RED,BLACK);
Blink_Blue2();
}
String writeString;
time.setForegroundColour(GREEN);
writeString = "";
writeString += String(now.hour());
writeString += ":";
writeString += String(now.minute());
oled.selectFont(Droid_Sans_36);
time.print(writeString);
time.reset();
writeString = "";
writeString += String(now.day());
writeString += "/";
writeString += String(now.month());
writeString += "/";
writeString += String(now.year());
date.setForegroundColour(WHITE);
oled.selectFont(SystemFont5x7);
date.print(writeString);
date.reset();
temp.setForegroundColour(RED);
int tempS = t;
writeString = "";
writeString += String(tempS);
writeString += "*C";
oled.selectFont(Arial_Black_16);
temp.print(writeString);
temp.reset();
humid.setForegroundColour(ROYALBLUE);
byte humidS = h;
writeString = "";
writeString += ("RH ");
writeString += String(humidS);
oled.selectFont(Arial_Black_16);
humid.print(writeString);
humid.reset();
delay(500);
}
void Blink_Green() {
digitalWrite(Green_LED, HIGH);
delay(500);
digitalWrite(Green_LED, LOW);
delay(500);
digitalWrite(Green_LED, HIGH);
delay(500);
digitalWrite(Green_LED, LOW);
delay(500);
}
void Blink_Blue1() {
digitalWrite(Blue1_LED, HIGH);
delay(500);
digitalWrite(Blue1_LED, LOW);
delay(500);
digitalWrite(Blue1_LED, HIGH);
delay(500);
digitalWrite(Blue1_LED, LOW);
delay(500);
}
void Blink_Blue2() {
digitalWrite(Blue2_LED, HIGH);
delay(500);
digitalWrite(Blue2_LED, LOW);
delay(500);
digitalWrite(Blue2_LED, HIGH);
delay(500);
digitalWrite(Blue2_LED, LOW);
delay(500);
}
Version 3.1 (Missing text box update)
Version 3.1 (Missing text box update)
Warning: Embedding code files within the project story has been deprecated. To edit this file or add more files, go to the "Software" tab. To remove this file from the story, click on it to trigger the context menu, then click the trash can button (this won't delete it from the "Software" tab).
/*OLED Temprature, Humid and time
Created 1/1/2014
Jed Hodson
*/
#include <SPI.h>
#include <SD.h>
#include <FTOLED.h>
#include <fonts/SystemFont5x7.h>
#include <fonts/Arial14.h>
#include <fonts/Arial_Black_16.h>
#include <fonts/Droid_Sans_36.h>
#include "DHT.h"
#include <Wire.h>
#include "RTClib.h"
#define DHTPIN 9
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
RTC_DS1307 RTC;
const byte pin_cs = 7;
const byte pin_dc = 2;
const byte pin_reset = 3;
#define Green_LED 5
#define Blue1_LED 6
#define Blue2_LED 8
OLED oled(pin_cs, pin_dc, pin_reset);
OLED_TextBox temp(oled,15,7,40,17);
OLED_TextBox humid(oled,64,7,70,17);
OLED_TextBox date(oled,35,105,128,15);
OLED_TextBox time(oled,35,52,128,32);
#define WELCOME F("Temprature,\nHumidity \nand Time\nOn OLED \nDisplay\nJed Hodson \n2013")
#define ERRORI2C F("An ERROR has\noccured,\nplease I2C\nwiring and try\nagain later!")
#define ERRORDHT F("An ERROR has\noccured,\nplease DHT\nwiring and try\nagain later!")
void setup() {
//Start everything up
oled.begin();
dht.begin();
Wire.begin();
RTC.begin();
pinMode(Green_LED, OUTPUT);
pinMode(Blue1_LED, OUTPUT);
pinMode(Blue2_LED, OUTPUT);
//Preform Blink of the LEDs
Blink_Green();
Blink_Blue1();
Blink_Blue2();
//Display start up message
oled.selectFont(Arial14);
oled.drawString(10,101,WELCOME,GREEN,BLACK);
Blink_Green();
oled.clearScreen();
}
void loop() {
DateTime now = RTC.now();
//Always Check the DHT22 for unplug
byte h = dht.readHumidity();
byte t = dht.readTemperature();
// check if returns are valid, if they are NaN (not a number) then something went wrong!
if (isnan(t) || isnan(h)) {
oled.drawString(10,101,ERRORDHT,RED,BLACK);
delay(2500);
oled.drawString(10,101,"",RED,BLACK);
Blink_Blue1();
}
//And the RTC just in case
if (! RTC.isrunning()) {
oled.selectFont(Arial14);
//DISPLAY ERROR MESSAGE
oled.drawString(10,101,ERRORI2C,RED,BLACK);
delay(2500);
oled.drawString(10,101,"",RED,BLACK);
Blink_Blue2();
}
String writeString;
time.setForegroundColour(GREEN);
writeString = "";
writeString += String(now.hour());
writeString += ":";
writeString += String(now.minute());
oled.selectFont(Droid_Sans_36);
time.print(writeString);
time.reset();
writeString = "";
writeString += String(now.day());
writeString += "/";
writeString += String(now.month());
writeString += "/";
writeString += String(now.year());
date.setForegroundColour(WHITE);
oled.selectFont(SystemFont5x7);
date.print(writeString);
date.reset();
temp.setForegroundColour(RED);
byte tempS = t;
writeString = "";
writeString += String(tempS);
writeString += "*C";
oled.selectFont(Arial_Black_16);
temp.print(writeString);
temp.reset();
humid.setForegroundColour(ROYALBLUE);
byte humidS = h;
writeString = "";
writeString += ("RH ");
writeString += String(humidS);
writeString += ("%");
oled.selectFont(Arial_Black_16);
humid.print(writeString);
humid.reset();
delay(500);
}
void Blink_Green() {
digitalWrite(Green_LED, HIGH);
delay(500);
digitalWrite(Green_LED, LOW);
delay(500);
digitalWrite(Green_LED, HIGH);
delay(500);
digitalWrite(Green_LED, LOW);
delay(500);
}
void Blink_Blue1() {
digitalWrite(Blue1_LED, HIGH);
delay(500);
digitalWrite(Blue1_LED, LOW);
delay(500);
digitalWrite(Blue1_LED, HIGH);
delay(500);
digitalWrite(Blue1_LED, LOW);
delay(500);
}
void Blink_Blue2() {
digitalWrite(Blue2_LED, HIGH);
delay(500);
digitalWrite(Blue2_LED, LOW);
delay(500);
digitalWrite(Blue2_LED, HIGH);
delay(500);
digitalWrite(Blue2_LED, LOW);
delay(500);
}
Photos
Pin Compatability
The RTC uses the I2C line while the LEDs run on lines 5,6 and 8 and DHT22 on pin 9. The OLED uses 2,3,4,7,11,12 and 13.
Note: Do not connect anything to D10. The OLED may fail to operate properly.
Beware Burn-in
If you expect the OLED128 to be left on for a long time (a day or longer), beware of burn-in.
The phosphours in the display will wear out unevenly, and you can be left with a pale “ghost” of the long-term image caused by burn-in.
Program Downloads
/*OLED Temprature, Humid and time
Created 19/09/2013
Jed Hodson
*/
#include <SPI.h>
#include <SD.h>
#include <FTOLED.h>
#include <fonts/SystemFont5x7.h>
#include <fonts/Arial14.h>
#include <fonts/Arial_Black_16.h>
#include <fonts/Droid_Sans_36.h>
#include "DHT.h"
#include <Wire.h>
#include "RTClib.h"
#define DHTPIN 4
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
RTC_DS1307 RTC;
const byte pin_cs = 7;
const byte pin_dc = 2;
const byte pin_reset = 3;
OLED oled(pin_cs, pin_dc, pin_reset);
OLED_TextBox temp(oled,20,7,30,17);
OLED_TextBox humid(oled,72,7,30,17);
OLED_TextBox date(oled,35,105,128,15);
OLED_TextBox time(oled,35,52,128,32);
const char *WELCOME = "Temprature,\nHumidity \nand Time\nOn OLED \nDisplay\nJed Hodson \n2013";
const char *ERRORHAP = "An ERROR has\noccured,\nplease check\nwiring and try\nagain later!";
void setup() {
//Start everything up
oled.begin();
dht.begin();
Wire.begin();
RTC.begin();
//Display start up message
oled.selectFont(Arial14);
oled.drawString(10,101,WELCOME,GREEN,BLACK);
delay(5000);
//Check everythings connected
//No RTC!
if (! RTC.isrunning()) {
oled.selectFont(Arial14);
//DISPLAY ERROR MESSAGE
oled.drawString(10,101,ERRORHAP,RED,BLACK);
delay(2500);
// following line sets the RTC to the date & time this sketch was compiled
RTC.adjust(DateTime(__DATE__, __TIME__));
}
//And DHT22
float h = dht.readHumidity();
float t = dht.readTemperature();
// check if returns are valid, if they are NaN (not a number) then something went wrong!
if (isnan(t) || isnan(h)) {
oled.drawString(10,101,ERRORHAP,RED,BLACK);
delay(2500);
}
//debug
Serial.begin(9600);
}
void loop() {
while(1){
oled.begin();
Serial.println("loop success");
float h = dht.readHumidity();
float t = dht.readTemperature();
DateTime now = RTC.now();
//Time to make some Strings
String dateString = "";
dateString += String(now.day());
dateString += "/";
dateString += String(now.month());
dateString += "/";
dateString += String(now.year());
int tempS = t;
String tempString = "";
tempString += String(tempS);
tempString += "*C";
int humidS = h;
String humidString = "";
humidString += String(humidS);
humidString += "%RH";
String timeString = "";
timeString += String(now.hour());
timeString += ":";
timeString += String(now.minute());
//Print Text
//Set colours
temp.setForegroundColour(RED);
humid.setForegroundColour(ROYALBLUE);
time.setForegroundColour(GREEN);
date.setForegroundColour(WHITE);
oled.selectFont(Arial_Black_16);
temp.print(tempString);
oled.selectFont(SystemFont5x7);
date.print(dateString);
oled.selectFont(Droid_Sans_36);
time.print(timeString);
oled.selectFont(Arial_Black_16);
humid.print(humidString);
temp.print(" ");
temp.reset();
time.print(" ");
time.reset();
date.print(" ");
date.reset();
humid.print(" ");
humid.reset();
delay(100);
}
}
/*OLED Temprature, Humid and time
Created 19/09/2013
Jed Hodson
*/
#include <SPI.h>
#include <SD.h>
#include <FTOLED.h>
#include <fonts/SystemFont5x7.h>
#include <fonts/Arial14.h>
#include <fonts/Arial_Black_16.h>
#include <fonts/Droid_Sans_36.h>
#include "DHT.h"
#include <Wire.h>
#include "RTClib.h"
#define DHTPIN 9
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
RTC_DS1307 RTC;
const byte pin_cs = 7;
const byte pin_dc = 2;
const byte pin_reset = 3;
OLED oled(pin_cs, pin_dc, pin_reset);
OLED_TextBox temp(oled,20,7,30,17);
OLED_TextBox humid(oled,72,7,30,17);
OLED_TextBox date(oled,35,105,128,15);
OLED_TextBox time(oled,35,52,128,32);
const char *WELCOME = "Temprature,\nHumidity \nand Time\nOn OLED \nDisplay\nJed Hodson \n2013";
const char *ERRORHAP = "An ERROR has\noccured,\nplease check\nwiring and try\nagain later!";
void setup() {
//Start everything up
oled.begin();
dht.begin();
Wire.begin();
RTC.begin();
//Display start up message
oled.selectFont(Arial14);
oled.drawString(10,101,WELCOME,GREEN,BLACK);
delay(5000);
//Check everythings connected
//No RTC!
if (! RTC.isrunning()) {
oled.selectFont(Arial14);
//DISPLAY ERROR MESSAGE
oled.drawString(10,101,ERRORHAP,RED,BLACK);
delay(2500);
// following line sets the RTC to the date & time this sketch was compiled
RTC.adjust(DateTime(__DATE__, __TIME__));
}
//And DHT22
float h = dht.readHumidity();
float t = dht.readTemperature();
// check if returns are valid, if they are NaN (not a number) then something went wrong!
if (isnan(t) || isnan(h)) {
oled.drawString(10,101,ERRORHAP,RED,BLACK);
delay(2500);
}
oled.clearScreen();
}
void loop() {
while(1){
float h = dht.readHumidity();
float t = dht.readTemperature();
DateTime now = RTC.now();
//Time to make some Strings
String dateString = "";
dateString += String(now.day());
dateString += "/";
dateString += String(now.month());
dateString += "/";
dateString += String(now.year());
int tempS = t;
String tempString = "";
tempString += String(tempS);
tempString += "*C";
int humidS = h;
String humidString = "";
humidString += String(humidS);
humidString += "RH";
String timeString = "";
timeString += String(now.hour());
timeString += ":";
timeString += String(now.minute());
//Print Text
//Set colours
temp.setForegroundColour(RED);
humid.setForegroundColour(ROYALBLUE);
time.setForegroundColour(GREEN);
date.setForegroundColour(WHITE);
oled.selectFont(Arial_Black_16);
temp.print(tempString);
oled.selectFont(SystemFont5x7);
date.print(dateString);
oled.selectFont(Droid_Sans_36);
time.print(timeString);
oled.selectFont(Arial_Black_16);
humid.print(humidString);
temp.reset();
time.reset();
date.reset();
humid.reset();
delay(100);
}
}
/*OLED Temprature, Humid and time
Created 14/10/2013
Jed Hodson
*/
#include <SPI.h>
#include <SD.h>
#include <FTOLED.h>
#include <fonts/SystemFont5x7.h>
#include <fonts/Arial14.h>
#include <fonts/Arial_Black_16.h>
#include <fonts/Droid_Sans_36.h>
#include "DHT.h"
#include <Wire.h>
#include "RTClib.h"
#define DHTPIN 9
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
RTC_DS1307 RTC;
const byte pin_cs = 7;
const byte pin_dc = 2;
const byte pin_reset = 3;
#define Green_LED 5
#define Blue1_LED 6
#define Blue2_LED 8
OLED oled(pin_cs, pin_dc, pin_reset);
OLED_TextBox temp(oled,20,7,30,17);
OLED_TextBox humid(oled,65,7,50,17);
OLED_TextBox date(oled,35,105,128,15);
OLED_TextBox time(oled,35,52,128,32);
#define WELCOME F("Temprature,\nHumidity \nand Time\nOn OLED \nDisplay\nJed Hodson \n2013")
#define ERRORI2C F("An ERROR has\noccured,\nplease I2C\nwiring and try\nagain later!")
#define ERRORDHT F("An ERROR has\noccured,\nplease DHT\nwiring and try\nagain later!")
void setup() {
//Start everything up
oled.begin();
dht.begin();
Wire.begin();
RTC.begin();
pinMode(Green_LED, OUTPUT);
pinMode(Blue1_LED, OUTPUT);
pinMode(Blue2_LED, OUTPUT);
//Preform Blink of the LEDs
Blink_Green();
Blink_Blue1();
Blink_Blue2();
//Display start up message
oled.selectFont(Arial14);
oled.drawString(10,101,WELCOME,GREEN,BLACK);
Blink_Green();
oled.clearScreen();
}
void loop() {
DateTime now = RTC.now();
//Always Check the DHT22 for unplug
byte h = dht.readHumidity();
byte t = dht.readTemperature();
// check if returns are valid, if they are NaN (not a number) then something went wrong!
if (isnan(t) || isnan(h)) {
oled.drawString(10,101,ERRORDHT,RED,BLACK);
delay(2500);
oled.drawString(10,101,"",RED,BLACK);
Blink_Blue1();
}
//And the RTC just in case
if (! RTC.isrunning()) {
oled.selectFont(Arial14);
//DISPLAY ERROR MESSAGE
oled.drawString(10,101,ERRORI2C,RED,BLACK);
delay(2500);
oled.drawString(10,101,"",RED,BLACK);
Blink_Blue2();
}
String writeString;
time.setForegroundColour(GREEN);
writeString = "";
writeString += String(now.hour());
writeString += ":";
writeString += String(now.minute());
oled.selectFont(Droid_Sans_36);
time.print(writeString);
time.reset();
writeString = "";
writeString += String(now.day());
writeString += "/";
writeString += String(now.month());
writeString += "/";
writeString += String(now.year());
date.setForegroundColour(WHITE);
oled.selectFont(SystemFont5x7);
date.print(writeString);
date.reset();
temp.setForegroundColour(RED);
int tempS = t;
writeString = "";
writeString += String(tempS);
writeString += "*C";
oled.selectFont(Arial_Black_16);
temp.print(writeString);
temp.reset();
humid.setForegroundColour(ROYALBLUE);
byte humidS = h;
writeString = "";
writeString += ("RH ");
writeString += String(humidS);
oled.selectFont(Arial_Black_16);
humid.print(writeString);
humid.reset();
delay(500);
}
void Blink_Green() {
digitalWrite(Green_LED, HIGH);
delay(500);
digitalWrite(Green_LED, LOW);
delay(500);
digitalWrite(Green_LED, HIGH);
delay(500);
digitalWrite(Green_LED, LOW);
delay(500);
}
void Blink_Blue1() {
digitalWrite(Blue1_LED, HIGH);
delay(500);
digitalWrite(Blue1_LED, LOW);
delay(500);
digitalWrite(Blue1_LED, HIGH);
delay(500);
digitalWrite(Blue1_LED, LOW);
delay(500);
}
void Blink_Blue2() {
digitalWrite(Blue2_LED, HIGH);
delay(500);
digitalWrite(Blue2_LED, LOW);
delay(500);
digitalWrite(Blue2_LED, HIGH);
delay(500);
digitalWrite(Blue2_LED, LOW);
delay(500);
}
/*OLED Temprature, Humid and time
Created 1/1/2014
Jed Hodson
*/
#include <SPI.h>
#include <SD.h>
#include <FTOLED.h>
#include <fonts/SystemFont5x7.h>
#include <fonts/Arial14.h>
#include <fonts/Arial_Black_16.h>
#include <fonts/Droid_Sans_36.h>
#include "DHT.h"
#include <Wire.h>
#include "RTClib.h"
#define DHTPIN 9
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
RTC_DS1307 RTC;
const byte pin_cs = 7;
const byte pin_dc = 2;
const byte pin_reset = 3;
#define Green_LED 5
#define Blue1_LED 6
#define Blue2_LED 8
OLED oled(pin_cs, pin_dc, pin_reset);
OLED_TextBox temp(oled,15,7,40,17);
OLED_TextBox humid(oled,64,7,70,17);
OLED_TextBox date(oled,35,105,128,15);
OLED_TextBox time(oled,35,52,128,32);
#define WELCOME F("Temprature,\nHumidity \nand Time\nOn OLED \nDisplay\nJed Hodson \n2013")
#define ERRORI2C F("An ERROR has\noccured,\nplease I2C\nwiring and try\nagain later!")
#define ERRORDHT F("An ERROR has\noccured,\nplease DHT\nwiring and try\nagain later!")
void setup() {
//Start everything up
oled.begin();
dht.begin();
Wire.begin();
RTC.begin();
pinMode(Green_LED, OUTPUT);
pinMode(Blue1_LED, OUTPUT);
pinMode(Blue2_LED, OUTPUT);
//Preform Blink of the LEDs
Blink_Green();
Blink_Blue1();
Blink_Blue2();
//Display start up message
oled.selectFont(Arial14);
oled.drawString(10,101,WELCOME,GREEN,BLACK);
Blink_Green();
oled.clearScreen();
}
void loop() {
DateTime now = RTC.now();
//Always Check the DHT22 for unplug
byte h = dht.readHumidity();
byte t = dht.readTemperature();
// check if returns are valid, if they are NaN (not a number) then something went wrong!
if (isnan(t) || isnan(h)) {
oled.drawString(10,101,ERRORDHT,RED,BLACK);
delay(2500);
oled.drawString(10,101,"",RED,BLACK);
Blink_Blue1();
}
//And the RTC just in case
if (! RTC.isrunning()) {
oled.selectFont(Arial14);
//DISPLAY ERROR MESSAGE
oled.drawString(10,101,ERRORI2C,RED,BLACK);
delay(2500);
oled.drawString(10,101,"",RED,BLACK);
Blink_Blue2();
}
String writeString;
time.setForegroundColour(GREEN);
writeString = "";
writeString += String(now.hour());
writeString += ":";
writeString += String(now.minute());
oled.selectFont(Droid_Sans_36);
time.print(writeString);
time.reset();
writeString = "";
writeString += String(now.day());
writeString += "/";
writeString += String(now.month());
writeString += "/";
writeString += String(now.year());
date.setForegroundColour(WHITE);
oled.selectFont(SystemFont5x7);
date.print(writeString);
date.reset();
temp.setForegroundColour(RED);
byte tempS = t;
writeString = "";
writeString += String(tempS);
writeString += "*C";
oled.selectFont(Arial_Black_16);
temp.print(writeString);
temp.reset();
humid.setForegroundColour(ROYALBLUE);
byte humidS = h;
writeString = "";
writeString += ("RH ");
writeString += String(humidS);
writeString += ("%");
oled.selectFont(Arial_Black_16);
humid.print(writeString);
humid.reset();
delay(500);
}
void Blink_Green() {
digitalWrite(Green_LED, HIGH);
delay(500);
digitalWrite(Green_LED, LOW);
delay(500);
digitalWrite(Green_LED, HIGH);
delay(500);
digitalWrite(Green_LED, LOW);
delay(500);
}
void Blink_Blue1() {
digitalWrite(Blue1_LED, HIGH);
delay(500);
digitalWrite(Blue1_LED, LOW);
delay(500);
digitalWrite(Blue1_LED, HIGH);
delay(500);
digitalWrite(Blue1_LED, LOW);
delay(500);
}
void Blink_Blue2() {
digitalWrite(Blue2_LED, HIGH);
delay(500);
digitalWrite(Blue2_LED, LOW);
delay(500);
digitalWrite(Blue2_LED, HIGH);
delay(500);
digitalWrite(Blue2_LED, LOW);
delay(500);
}
Comments
Please log in or sign up to comment.