Skip to content

Commit

Permalink
Added DHT22 and general improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
fornellas committed Nov 25, 2012
1 parent aa4fcab commit d150813
Show file tree
Hide file tree
Showing 15 changed files with 224 additions and 169 deletions.
5 changes: 1 addition & 4 deletions notAnotherClockProject/BigClock.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
#include "BigClock.h"

#include <U8glib.h>
#include <DS1307.h>
#include "tz.h"
#include "facilities.h"

#define BUFF_DATE 3

extern U8GLIB_ST7920_128X64 *lcd;

BigClock::BigClock():
Mode(PSTR("Big Clock")){
}
Expand Down
113 changes: 58 additions & 55 deletions notAnotherClockProject/Clock.cpp
Original file line number Diff line number Diff line change
@@ -1,107 +1,110 @@
#include "Clock.h"
#include "pins.h"

#include <SFRGBLEDMatrix.h>
#include <U8glib.h>
#include <DS1307.h>
#include <HIH4030.h>
#include <DS18S20.h>
#include <BMP085.h>
#include <EEPROM.h>
#include <avr/pgmspace.h>
#include "Light.h"
#include "Button.h"
#include "EEPROM_addr.h"
#include "tz.h"
#include "facilities.h"

#define BUFF_LCD_MSG 8

extern SFRGBLEDMatrix *ledMatrix;
extern U8GLIB_ST7920_128X64 *lcd;
extern Light *light;
extern DS18S20 *temperatureOutside;
extern BMP085 *pressure;
#define BUFF_LCD_MSG 18

// LCD

void
Clock::lcdInfo(){
float tOut;
long Pa;
char buff[BUFF_LCD_MSG];
float tIn;
byte humidity;
byte t;

// read values
tOut=temperatureOutside->readC();
Pa=pressure->readHPa();
tIn=pressure->readC();
humidity=HIH4030::read(PIN_HUMIDITY, tIn);
dht22->loadFromSensor();
switch(dht22->error()){
case DHT_ERROR_NONE:
case DHT_ERROR_TOOQUICK:
break;
default:
// FIXME better error reporting
ledMatrix->fill(RED);
ledMatrix->show();
while(1);
break;
}
bmp085->loadFromSensor();
humidityInside.loadFromSensor();
// LCD
lcd->firstPage();
do {
byte x;
byte y;
// Temperature names
x=0;
y=0;
y=-1;
lcd->setFont(u8g_font_5x7);
lcd->setFontPosTop();
lcd->drawStrP(x, y, U8G_PSTR("Indoor"));
x=lcd->getWidth()-lcd->getStrWidthP(U8G_PSTR("Outdoor"));
lcd->drawStrP(x, y, U8G_PSTR("Outdoor"));
// Temperature indoor
x=lcd->getWidth()/4-lcd->getStrWidthP(U8G_PSTR("Inside"))/2;
lcd->drawStrP(x, y, U8G_PSTR("Inside"));
x=lcd->getWidth()-lcd->getStrWidthP(U8G_PSTR("Outside"));
x=lcd->getWidth()*3/4-lcd->getStrWidthP(U8G_PSTR("Outside"))/2;
lcd->drawStrP(x, y, U8G_PSTR("Outside"));
// Temperature inside
x=0;
y=lcd->getFontAscent()+1;
y=lcd->getFontAscent();
lcd->setFont(u8g_font_fub14);
lcd->setFontPosTop();
lcd->drawStr(x, y, dtostrf(tIn, -2, 1, buff));
x+=lcd->getStrWidth(dtostrf(tIn, -2, 1, buff));
lcd->drawStr(x, y, dtostrf(temperatureInside.getC(), -2, 1, buff));
x+=lcd->getStrWidth(dtostrf(temperatureInside.getC(), -2, 1, buff));
buff[0]=176;
buff[1]='C';
buff[2]='\0';
lcd->drawStr(x, y, buff);
// Temperature outdoor
dtostrf(tOut, -2, 1, buff);
// Temperature outside
dtostrf(temperatureOutside.getC(), -2, 1, buff);
t=strlen(buff);
buff[t++]=176;
buff[t++]='C';
buff[t]='\0';
x=lcd->getWidth()-lcd->getStrWidth(buff);
lcd->drawStr(x, y, buff);
// Humidity
x=0;
y+=lcd->getFontAscent()+3;
lcd->drawStr(x, y, itoa(humidity, buff, 10));
x+=lcd->getStrWidth(itoa(humidity, buff, 10));
lcd->drawStrP(x, y, U8G_PSTR("%"));
// Humidity inside
y+=lcd->getFontAscent()+1;
ltoa(humidityInside.getRH(), buff, 10);
t=strlen(buff);
buff[t++]='%';
buff[t]='\0';
x=lcd->getWidth()/4-lcd->getStrWidth(buff)/2;
lcd->drawStr(x, y, buff);
// Humidity outside
ltoa(humidityOutside.getRH(), buff, 10);
t=strlen(buff);
buff[t++]='%';
buff[t]='\0';
x=lcd->getWidth()*3/4-lcd->getStrWidth(buff)/2;
lcd->drawStr(x, y, buff);
// Pressure
ltoa(Pa, buff, 10);
ltoa(pressure.readHPa(), buff, 10);
t=strlen(buff);
buff[t++]='h';
buff[t++]='P';
buff[t++]='a';
buff[t]='\0';
x=lcd->getWidth()-lcd->getStrWidth(buff);
y+=lcd->getFontAscent()+1;
lcd->setFont(u8g_font_7x13B);
lcd->setFontPosTop();
x=lcd->getWidth()/2-lcd->getStrWidth(buff)/2;
lcd->drawStr(x, y, buff);
// Week day
y+=lcd->getFontAscent()+1;
lcd->setFont(u8g_font_7x14);
y+=lcd->getFontAscent();
lcd->setFont(u8g_font_6x12);
lcd->setFontPosTop();
x=lcd->getWidth()/2-lcd->getStrWidthP((u8g_pgm_uint8_t *)time->getWeekDayName())/2;
lcd->drawStrP(x, y, (const u8g_pgm_uint8_t*)time->getWeekDayName());
// Date
strcpy_P(buff, time->getMonthName());
t=strlen(buff);
buff[t++]=' ';
itoa(date.mday, buff+t, 10);
t=strlen(buff);
buff[t++]=' ';
itoa(date.year, buff+t, 10);
y+=lcd->getFontAscent()+2;
x=0;
lcd->drawStrP(x, y, (const u8g_pgm_uint8_t*)time->getMonthName());
t=lcd->getStrWidthP((u8g_pgm_uint8_t *)time->getMonthName());
itoa(date.year, buff, 10);
x=lcd->getWidth()-lcd->getStrWidth(buff);
lcd->drawStr(x, y, buff);
x=t+(lcd->getWidth()-t-lcd->getStrWidth(buff))/2;
itoa(date.mday, buff, 10);
x=x-lcd->getStrWidth(buff)/2;
x=lcd->getWidth()/2-lcd->getStrWidth(buff)/2;
lcd->drawStr(x, y, buff);
}
while( lcd->nextPage() );
Expand Down
6 changes: 1 addition & 5 deletions notAnotherClockProject/ECA.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
#include "ECA.h"

#include "Button.h"
#include <U8glib.h>
#include "facilities.h"

#define CHANGE_MS 5000
#define BUFF_RULE 4

extern U8GLIB_ST7920_128X64 *lcd;
extern SFRGBLEDMatrix *ledMatrix;

void ECA::newAutomata(){
byte x;
byte y;
Expand Down
5 changes: 1 addition & 4 deletions notAnotherClockProject/Equalizer.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
#include "Equalizer.h"

#include "pins.h"
#include <SFRGBLEDMatrix.h>
#include "Button.h"

extern SFRGBLEDMatrix *ledMatrix;
#include "facilities.h"

#define BANDS 7

Expand Down
5 changes: 1 addition & 4 deletions notAnotherClockProject/Fire.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#include "Fire.h"

#include <SFRGBLEDMatrix.h>
#include "Button.h"

extern SFRGBLEDMatrix *ledMatrix;
#include "facilities.h"

#define PIXMAP(x,y) *(pixmap+(ledMatrix->width+2)*(y)+(x))

Expand Down
5 changes: 1 addition & 4 deletions notAnotherClockProject/HTTPServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@
#include <SD.h>
#include <MemoryFree.h>
#include <DS1307.h>
#include "Net.h"
#include "facilities.h"

#define BUFF_READ 64
#define BUFF_TAIL 37
#define BUFF_MIME 26

#define HTTP_PORT 80

extern time_t bootTime;
extern Net *net;

WebServer *HTTPServer::webserver=NULL;

void HTTPServer::footer(WebServer &server){
Expand Down
5 changes: 1 addition & 4 deletions notAnotherClockProject/Lamp.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#include "Lamp.h"

#include <SFRGBLEDMatrix.h>
#include <avr/pgmspace.h>

extern SFRGBLEDMatrix *ledMatrix;
#include "facilities.h"

Lamp::Lamp():
Mode(PSTR("Lamp")){
Expand Down
45 changes: 25 additions & 20 deletions notAnotherClockProject/Logger.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
#include "Logger.h"

#include "Light.h"
#include <Arduino.h>
#include <DS1307.h>
#include <avr/pgmspace.h>
#include <SD.h>
#include <BMP085.h>
#include "pins.h"
#include <DS18S20.h>
#include <HIH4030.h>

extern Light *light;
extern DS18S20 *temperatureOutside;
extern BMP085 *pressure;
#include <DS1307.h>
#include "facilities.h"

#define BUFF_PATH 32
#define BUFF_FILE 19
Expand Down Expand Up @@ -59,16 +51,29 @@ void Logger::update(){
if(!SD.mkdir(path)){
while(true)Serial.println("Error creating dir."); // FIXME better error reporting
}
// Indoor Temperature
float temperatureInside;
byte addr[]={40, 200, 10, 228, 3, 0, 0, 62};
save(PSTR("TEMPINDO.TXT"), path, &time, pressure->readC());
// Outdoor Temperature
save(PSTR("TEMPOUTD.TXT"), path, &time, temperatureOutside->readC());
// Humidity
save(PSTR("HUMIDITY.TXT"), path, &time, HIH4030::read(PIN_HUMIDITY, temperatureInside));
save(PSTR("PRESSURE.TXT"), path, &time, (long int)pressure->readPa());

// Inside
bmp085->loadFromSensor();
save(PSTR("TEMPINDO.TXT"), path, &time, temperatureInside.getC());
save(PSTR("PRESSURE.TXT"), path, &time, (long int)pressure.readPa());
humidityInside.loadFromSensor();
save(PSTR("HUMIDIIN.TXT"), path, &time, humidityInside.getRH());
// Out
dht22->loadFromSensor();
switch(dht22->error()){
case DHT_ERROR_NONE:
case DHT_ERROR_TOOQUICK:
break;
default:
// FIXME better error reporting
ledMatrix->fill(RED);
ledMatrix->show();
while(1);
break;
}
save(PSTR("TEMPEOUT.TXT"), path, &time, temperatureOutside.getC());
save(PSTR("HUMIDOUT.TXT"), path, &time, humidityOutside.getRH());
temperatureOutside2.loadFromSensor();
save(PSTR("TEMPEOU2.TXT"), path, &time, temperatureOutside2.getC());
digitalWrite(PIN_R, LOW);
}
}
Expand Down
4 changes: 3 additions & 1 deletion notAnotherClockProject/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ ARDUINO_LIBS=\
SD/utility \
Webduino \
Temperature \
Pressure
Pressure \
DHT22 \
Humidity
ARDUINO_DIR=/home/fornellas/local/arduino-1.0.1
ARDMK_DIR=/home/fornellas/src/Arduino-Makefile
AVR_TOOLS_DIR=/usr
Expand Down
8 changes: 1 addition & 7 deletions notAnotherClockProject/Mode.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
#include "Mode.h"
#include "Light.h"

#include <SFRGBLEDMatrix.h>
#include <U8glib.h>

extern SFRGBLEDMatrix *ledMatrix;
extern U8GLIB_ST7920_128X64 *lcd;
extern Light *light;
#include "facilities.h"

Mode::Mode(PROGMEM char *name) {
byte x;
Expand Down
4 changes: 1 addition & 3 deletions notAnotherClockProject/Net.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#include "Net.h"
#include "pins.h"
#include "Light.h"

#include <stdlib.h>

#include <Ethernet.h>
#include <EthernetInterrupt.h>

extern Light *light;
#include "facilities.h"

Net::Net(){
// Initialize Ethernet
Expand Down
4 changes: 1 addition & 3 deletions notAnotherClockProject/Plasma.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#include "Plasma.h"
#include "EEPROM_addr.h"
#include "Button.h"
#include <EEPROM.h>

extern SFRGBLEDMatrix *ledMatrix;
#include "facilities.h"

#define PIXMAP_WIDTH ((ledMatrix->width>>3)+3)
#define PIXMAP_HEIGHT ((ledMatrix->height>>3)+3)
Expand Down
Loading

0 comments on commit d150813

Please sign in to comment.