Seeeduino Arch + Grove - OLED 128x64 + Grove - Temperature & Humidity Sensor Pro to sense the environment
Dependencies: DHT SSD1308_128x64_I2C USBDevice mbed
Revision 0:4a9b07ff844f, committed 2013-07-24
- Comitter:
- yihui
- Date:
- Wed Jul 24 07:03:48 2013 +0000
- Commit message:
- Sense the environment
Changed in this revision
diff -r 000000000000 -r 4a9b07ff844f DHT.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DHT.lib Wed Jul 24 07:03:48 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/yihui/code/DHT/#25c96950b6ed
diff -r 000000000000 -r 4a9b07ff844f SSD1308_128x64_I2C.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SSD1308_128x64_I2C.lib Wed Jul 24 07:03:48 2013 +0000 @@ -0,0 +1,1 @@ +https://mbed.org/users/wim/code/SSD1308_128x64_I2C/#fa18169dd7e6
diff -r 000000000000 -r 4a9b07ff844f USBDevice.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/USBDevice.lib Wed Jul 24 07:03:48 2013 +0000 @@ -0,0 +1,1 @@ +https://mbed.org/users/mbed_official/code/USBDevice/#1e3d126a322b
diff -r 000000000000 -r 4a9b07ff844f main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Jul 24 07:03:48 2013 +0000 @@ -0,0 +1,63 @@ +#include "mbed.h" +#include "USBSerial.h" +#include "DHT.h" +#include "SSD1308.h" + +#define LOG(...) serial.printf(__VA_ARGS__) + +BusOut leds(LED1, LED2, LED3, LED4); +USBSerial serial; // USB serial to output debug message + +// Grove - Temperature & Humidity Pro is connected with UART Grove of Seeeduino Arch, uses P1_14 +DHT sensor(P1_14, DHT22); + +// Grove - OLED 128x64 is connected with I2C Grove +I2C i2c(P0_5, P0_4); // SDA, SCL +SSD1308 oled = SSD1308(i2c, SSD1308_SA0); + +int main() { + uint8_t count = 0; + char display_buf[8]; + int err; + float humidity; + float last_humidity = 0; + float temperature; + float last_temperature = 0; + + + LOG("------- Sense -------\n"); + oled.writeString(0, 0, "---- Sense ----"); + oled.writeString(2, 0, "Temperature:"); + oled.writeString(5, 0, "Humidity:"); + while(1) { + count++; + leds = count; + + err = sensor.readData(); + if (err == 0) { + temperature = sensor.ReadTemperature(CELCIUS); + if (temperature != last_temperature) { // update temperature if changed + snprintf(display_buf, sizeof(display_buf), "%4.2f C", temperature); + oled.writeString(3, 0, display_buf); + last_temperature = temperature; + } + + humidity = sensor.ReadHumidity(); + if (humidity != last_humidity) { + snprintf(display_buf, sizeof(display_buf), "%4.2f %%", humidity); + oled.writeString(6, 0, display_buf); + last_humidity = humidity; + } + + LOG("Temperature is %4.2f C \r\n",sensor.ReadTemperature(CELCIUS)); + LOG("Temperature is %4.2f F \r\n",sensor.ReadTemperature(FARENHEIT)); + LOG("Temperature is %4.2f K \r\n",sensor.ReadTemperature(KELVIN)); + LOG("Humidity is %4.2f \r\n",sensor.ReadHumidity()); + LOG("Dew point is %4.2f \r\n",sensor.CalcdewPoint(sensor.ReadTemperature(CELCIUS), sensor.ReadHumidity())); + LOG("Dew point (fast) is %4.2f \r\n",sensor.CalcdewPointFast(sensor.ReadTemperature(CELCIUS), sensor.ReadHumidity())); + } else + LOG("\r\nErr %i \n",err); + + wait(2); + } +}
diff -r 000000000000 -r 4a9b07ff844f mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Jul 24 07:03:48 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/b3110cd2dd17 \ No newline at end of file