diff --git a/src/libDevCom/HIH4000.cpp b/src/libDevCom/HIH4000.cpp index d62d1324ccd613cd6df01ac5500dfd4fa60e682c..0838e7e3c09eb675511ccd0fc9a7ea1f081d79ed 100644 --- a/src/libDevCom/HIH4000.cpp +++ b/src/libDevCom/HIH4000.cpp @@ -4,8 +4,13 @@ #include <cmath> -HIH4000::HIH4000(uint8_t chan, std::shared_ptr<ADCDevice> dev, std::shared_ptr<ClimateSensor> tempSens) - : m_adcdev(dev), m_tempSens(tempSens), m_chan(chan) + +HIH4000::HIH4000(uint8_t chan, std::shared_ptr<ADCDevice> dev, std::shared_ptr<ClimateSensor> tempSens, float Vsup) + : m_adcdev(dev), m_tempSens(tempSens), m_chan(chan), m_Vsup(Vsup), m_calib(false) +{ } + +HIH4000::HIH4000(uint8_t chan, std::shared_ptr<ADCDevice> dev, std::shared_ptr<ClimateSensor> tempSens, float offset, float slope) + : m_adcdev(dev), m_tempSens(tempSens), m_chan(chan), m_offset(offset), m_slope(slope), m_calib(true) { } HIH4000::~HIH4000() @@ -23,11 +28,15 @@ void HIH4000::read() m_temperature=m_tempSens->temperature(); m_humidity = 0.; const uint navg = 5; + // output voltage for(uint i=0;i<navg;i++) m_humidity += (float)m_adcdev->read(m_chan); m_humidity/=(float)navg; - // temperature correction - m_humidity=(m_humidity-0.16)/0.0062/(1.0546-0.00216*m_temperature); + // sensor humidity + if (m_calib) m_humidity = (m_humidity - m_offset)/m_slope; + else m_humidity = (m_humidity/m_Vsup-0.16)/0.0062; + // temperature correction + m_humidity=m_humidity/(1.0546-0.00216*m_temperature); } float HIH4000::temperature() const diff --git a/src/libDevCom/HIH4000.h b/src/libDevCom/HIH4000.h index 21ea4d7c701839bf47f0e5567d88ead194a37a1d..ce82bbd38988235e77bfff0911a3d3563354c60b 100644 --- a/src/libDevCom/HIH4000.h +++ b/src/libDevCom/HIH4000.h @@ -7,9 +7,12 @@ //! \brief An implementation of 'ClimateSensor' for reading an HIH4000 sensor /** - * Measures humidity using a HIH4000 sensor connected to one of the analog pins - * on an Arduino via an ADC intereface. - * humiditry requires temperature connection: according sensor has to be provided + * Measures humidity using a HIH4000 sensor connected to a channel on an ADC device. + * Humidity requires temperature connection: according sensor has to be provided. + * A better measurement accuracy down to 3.5% RH can be achieved with the pre-calibrated + * models HIH4000-003 and -004 with a datasheet providing offset and slope of Vout vs. RH + * calibrated with a supply voltage of 5V. The same supply voltage has to be used for the + * connected HIH4000. * HIH4000 specs: https://sensing.honeywell.com/HIH-4000-001-humidity-sensors */ @@ -20,8 +23,20 @@ public: * \param chan The channel number of the analog channel connected to the Pt * \param dev The ADCDevice for interfacing with the Adruino or similar - should be calibrated * to return measured voltage as 0...100% of the operational voltage + * \param tempSens The Temperature sensor used for the temperature compensation + * \param Vsup The supply voltage */ - HIH4000(uint8_t chan, std::shared_ptr<ADCDevice> dev, std::shared_ptr<ClimateSensor> tempSens); + HIH4000(uint8_t chan, std::shared_ptr<ADCDevice> dev, std::shared_ptr<ClimateSensor> tempSens, float Vsup = 5.0); + + /** + * \param chan The channel number of the analog channel connected to the Pt + * \param dev The ADCDevice for interfacing with the Adruino or similar - should be calibrated + * to return measured voltage as 0...100% of the operational voltage + * \param tempSens The Temperature sensor used for the temperature compensation + * \param offset The zero offset of Vout vs RH of calibrated sensors at 5V + * \param slope The Vout vs RH slope of calibrated sensors at 5V + */ + HIH4000(uint8_t chan, std::shared_ptr<ADCDevice> dev, std::shared_ptr<ClimateSensor> tempSens, float offset, float slope); virtual ~HIH4000(); virtual void init(); @@ -41,6 +56,14 @@ private: float m_temperature = -273.15; //! The humidity recorded in the last reading (defaults to 0) float m_humidity = 0.; + //! Supply voltage + float m_Vsup = 5.; + //! Whether the calibration data of a sensor is used + bool m_calib = false; + //! Zero offset for calibrated sensor + float m_offset = 0.85; + //! Slope for calibrated sensor + float m_slope = 0.03; //! ref. to the temperature sensor from which temp. correction is derived std::shared_ptr<ClimateSensor> m_tempSens; }; diff --git a/src/libDevCom/python.cpp b/src/libDevCom/python.cpp index 6a112fe254d51cecd2bf70100ee4030a3217e2e7..62528f06e72a56db454d512f64b6ae86ca262bab 100644 --- a/src/libDevCom/python.cpp +++ b/src/libDevCom/python.cpp @@ -6,6 +6,7 @@ #include "HTS221.h" #include "Si7021.h" #include "SHT85.h" +#include "HIH4000.h" #include "HIH6130.h" #include "DeviceCom.h" @@ -661,6 +662,11 @@ void register_devcom(py::module& m) { .def(py::init<std::shared_ptr<I2CCom>>()) .def("status", &SHT85::status); + py::class_<HIH4000, PySensor<HIH4000>, ClimateSensor, std::shared_ptr<HIH4000>>(m, "HIH4000") + .def(py::init<uint8_t, std::shared_ptr<ADCDevice>, std::shared_ptr<ClimateSensor>>()) + .def(py::init<uint8_t, std::shared_ptr<ADCDevice>, std::shared_ptr<ClimateSensor>, float>()) + .def(py::init<uint8_t, std::shared_ptr<ADCDevice>, std::shared_ptr<ClimateSensor>, float, float>()); + py::class_<HIH6130, PySensor_w_status<HIH6130>, ClimateSensor, std::shared_ptr<HIH6130>>(m, "HIH6130") .def(py::init<std::shared_ptr<I2CCom>>()) .def("status", &HIH6130::status);