read

wayland/sht2x-rh-temp/read

Measure relative humidity and temperature.
read
@/read
Measure relative humidity and temperature.
DEV@/sht2x-device
An SHT2x device.
UPDpulse
Update. Triggers new read.
read
DEV
UPD
RH
Temp
Error
Done
Donepulse
Pulse on read.
Errorbyte
Error code: 00h=OK, 81h=WRITECMD, 82h=READBYTES, 83h=HEATER_OFF, 84h=NOT_CONNECT, 85h=CRC_TEMP, 86h=CRC_HUM, 87h=CRC_STATUS, 88h=HEATER_COOLDOWN, 89h=HEATER_ON.
Tempnumber
Temperature (°C).
RHnumber
Relative humidity (%).
To use the node in your project you should have the wayland/sht2x-rh-temp 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);
        sensor->read();
        uint8_t errorCode = sensor->getError();
        emitValue<output_Error>(ctx, 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);
        }
    }
}