FRDM-K64F example featuring the Seeed Grove Temperature and Humidity sensor

Dependencies:   DHT mbed

Fork of FRDM-K64F_Seeed-Grove_Temp-Humidity_Example by Freescale

Simply Import this Program into your mbed compiler
Select Compile to generate the binary file
Open an Hyperterminal window and connect to the mbed Serial Port (COMxx) peripheral using speed 9600bps
Plug the Grove Shield v2 on the top of your FRDM-K64F
Connect on end of the 4-pin Grove cable to the Temperature and Humidity module and the other end to the port A1 of the Grove Adapter.

Drag n drop the FRDM-K64F_Seeed-Grove_Temp-Humidity_Example.bin into the mbed drive from your file explorer
Wait for download to complete
Press the Reset/SW1 button of your FRDM-K64F board to launch the program

Your hyperterminal window should now display Temperature and Humidity measurements (see picture below)!!

main.cpp

Committer:
sam_grove
Date:
2014-08-15
Revision:
0:c12c28a0f9e7
Child:
2:39e8fc849cb1

File content as of revision 0:c12c28a0f9e7:


#include "mbed.h"
#include "DHT.h"

DHT sensor(D4, DHT11);

int main()
{
    int error = 0;
    float h = 0.0f, c = 0.0f, f = 0.0f, k = 0.0f, dp = 0.0f, dpf = 0.0f;

    while(1) {
        wait(2.0f);
        error = sensor.readData();
        if (0 == error) {
            c   = sensor.ReadTemperature(CELCIUS);
            f   = sensor.ReadTemperature(FARENHEIT);
            k   = sensor.ReadTemperature(KELVIN);
            h   = sensor.ReadHumidity();
            dp  = sensor.CalcdewPoint(c, h);
            dpf = sensor.CalcdewPointFast(c, h);
            printf("Temperature in Kelvin: %4.2f, Celcius: %4.2f, Farenheit %4.2f\n", k, c, f);
            printf("Humidity is %4.2f, Dewpoint: %4.2f, Dewpoint fast: %4.2f\n", h, dp, dpf);
        } else {
            printf("Error: %d\n", error);
        }
    }
}