root / Ports / examples / indoor / indoor.pde
History | View | Annotate | Download (2.5 KB)
| 1 | //>>> The latest version of this code can be found at https://github.com/jcw/ !! |
|---|---|
| 2 | |
| 3 | // Example indoor temp + humidty + barometer, mounted on a Graphics Board |
| 4 | // 2010-11-17 <jcw@equi4.com> http://opensource.org/licenses/mit-license.php |
| 5 | // $Id: indoor.pde 7763 2011-12-11 01:28:16Z jcw $ |
| 6 | |
| 7 | #include "ST7565.h" |
| 8 | #include <Ports.h> |
| 9 | #include <PortsBMP085.h> |
| 10 | #include <PortsSHT11.h> |
| 11 | #include <RF12.h> // needed to avoid a linker error :( |
| 12 | |
| 13 | ST7565 glcd(14, 4, 17, 7); |
| 14 | SHT11 th_sensor (3); // port 3 |
| 15 | PortI2C two (2); // port 2 |
| 16 | BMP085 p_sensor (two, 3); // ultra high resolution |
| 17 | MilliTimer timer; |
| 18 | char outBuf [25]; |
| 19 | |
| 20 | // this has to be added since we're using the watchdog for low-power waiting |
| 21 | ISR(WDT_vect) { Sleepy::watchdogEvent(); }
|
| 22 | |
| 23 | // spend a little time in power down mode while the SHT11 does a measurement |
| 24 | static void shtDelay () {
|
| 25 | Sleepy::loseSomeTime(32); // must wait at least 20 ms |
| 26 | } |
| 27 | |
| 28 | void setup () {
|
| 29 | rf12_initialize(1, RF12_868MHZ); |
| 30 | rf12_sleep(RF12_SLEEP); // power down |
| 31 | |
| 32 | p_sensor.getCalibData(); |
| 33 | |
| 34 | glcd.st7565_init(); |
| 35 | glcd.st7565_command(CMD_DISPLAY_ON); |
| 36 | glcd.st7565_command(CMD_SET_ALLPTS_NORMAL); |
| 37 | glcd.st7565_set_brightness(0x15); |
| 38 | } |
| 39 | |
| 40 | void loop () {
|
| 41 | glcd.clear(); |
| 42 | |
| 43 | float h, t, d; |
| 44 | th_sensor.measure(SHT11::HUMI, shtDelay); |
| 45 | th_sensor.measure(SHT11::TEMP, shtDelay); |
| 46 | th_sensor.calculate(h, t); |
| 47 | d = th_sensor.dewpoint(h, t); |
| 48 | // convert back to ints |
| 49 | int temp = t * 10 + 0.5; |
| 50 | int humi = h + 0.5; |
| 51 | int dewp = d * 10 + 0.5; |
| 52 | |
| 53 | // sensor readout takes some time, so go into power down while waiting |
| 54 | int temp2; |
| 55 | long pres; |
| 56 | p_sensor.startMeas(BMP085::TEMP); |
| 57 | Sleepy::loseSomeTime(16); |
| 58 | p_sensor.getResult(BMP085::TEMP); |
| 59 | p_sensor.startMeas(BMP085::PRES); |
| 60 | Sleepy::loseSomeTime(32); |
| 61 | p_sensor.getResult(BMP085::PRES); |
| 62 | p_sensor.calculate(temp2, pres); |
| 63 | |
| 64 | glcd.drawstring(0, 0, "SHT11:"); |
| 65 | sprintf(outBuf, " Temp %4d.%d C", temp/10, temp%10); |
| 66 | glcd.drawstring(0, 1, outBuf); |
| 67 | sprintf(outBuf, " Dewpoint %4d.%d C", dewp/10, dewp%10); |
| 68 | glcd.drawstring(0, 2, outBuf); |
| 69 | sprintf(outBuf, " Humidity %4d %%", humi); |
| 70 | glcd.drawstring(0, 3, outBuf); |
| 71 | |
| 72 | glcd.drawstring(0, 5, "BMP085:"); |
| 73 | sprintf(outBuf, " Temp %4d.%d C", temp2/10, temp2%10); |
| 74 | glcd.drawstring(0, 6, outBuf); |
| 75 | sprintf(outBuf, " Pressure %4d.%d mb", (int) (pres/100), |
| 76 | (int) (pres%100) / 10); |
| 77 | glcd.drawstring(0, 7, outBuf); |
| 78 | |
| 79 | glcd.display(); |
| 80 | Sleepy::loseSomeTime(1000); |
| 81 | } |