read

wayland/dht20/read

Measure relative humidity and temperature.
read
@/read
Measure relative humidity and temperature.
DEV@/dht20-device
A dht20-device.
UPDpulse
Update. Triggers new read. Interval between pulses must be greater than 1 second.
read
DEV
UPD
RH
Temp
Error
Done
Donepulse
Pulse on read.
Errorbyte
Error code: 00h=OK, 0Ah=ERROR_CHECKSUM, 0Bh=ERROR_CONNECT, 0Ch=MISSING_BYTES, 0Dh=ERROR_BYTES_ALL_ZERO, 0Eh=ERROR_READ_TIMEOUT, 0Fh=ERROR_LASTREAD.
Tempnumber
Temperature (°C).
RHnumber
Relative Humidity (%)
To use the node in your project you should have the wayland/dht20 library installed. Use the “File → Add Library” menu item in XOD IDE if you don’t have it yet. See Using libraries for more info.

C++ implementation

#pragma XOD evaluate_on_pin disable
#pragma XOD evaluate_on_pin enable input_UPD

node {
    void evaluate(Context ctx) {
        // The node responds only if there is an input pulse
        if (!isInputDirty<input_UPD>(ctx))
            return;

        auto sensor = getValue<input_DEV>(ctx);
        int errorCode = sensor->read();
        emitValue<output_Error>(ctx, abs(errorCode));
        if (errorCode!=0) {
            raiseError<output_RH>(ctx);
            raiseError<output_Temp>(ctx);
            raiseError<output_Done>(ctx);
        } else {
            emitValue<output_RH>(ctx, sensor->getHumidity());
            emitValue<output_Temp>(ctx, sensor->getTemperature());
            emitValue<output_Done>(ctx, 1);
        }
    }
}