Skip to content
Snippets Groups Projects
Commit b4b27769 authored by Elisabetta Pianori's avatar Elisabetta Pianori
Browse files

Merge branch 'lm_HIH4000' into 'devel'

Improve HIH4000

See merge request berkeleylab/labRemote!181
parents 6d5e8fd0 3f962f48
No related branches found
No related tags found
No related merge requests found
...@@ -4,8 +4,13 @@ ...@@ -4,8 +4,13 @@
#include <cmath> #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() HIH4000::~HIH4000()
...@@ -23,11 +28,15 @@ void HIH4000::read() ...@@ -23,11 +28,15 @@ void HIH4000::read()
m_temperature=m_tempSens->temperature(); m_temperature=m_tempSens->temperature();
m_humidity = 0.; m_humidity = 0.;
const uint navg = 5; const uint navg = 5;
// output voltage
for(uint i=0;i<navg;i++) for(uint i=0;i<navg;i++)
m_humidity += (float)m_adcdev->read(m_chan); m_humidity += (float)m_adcdev->read(m_chan);
m_humidity/=(float)navg; m_humidity/=(float)navg;
// temperature correction // sensor humidity
m_humidity=(m_humidity-0.16)/0.0062/(1.0546-0.00216*m_temperature); 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 float HIH4000::temperature() const
......
...@@ -7,9 +7,12 @@ ...@@ -7,9 +7,12 @@
//! \brief An implementation of 'ClimateSensor' for reading an HIH4000 sensor //! \brief An implementation of 'ClimateSensor' for reading an HIH4000 sensor
/** /**
* Measures humidity using a HIH4000 sensor connected to one of the analog pins * Measures humidity using a HIH4000 sensor connected to a channel on an ADC device.
* on an Arduino via an ADC intereface. * Humidity requires temperature connection: according sensor has to be provided.
* humiditry 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 * HIH4000 specs: https://sensing.honeywell.com/HIH-4000-001-humidity-sensors
*/ */
...@@ -20,8 +23,20 @@ public: ...@@ -20,8 +23,20 @@ public:
* \param chan The channel number of the analog channel connected to the Pt * \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 * \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 * 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 ~HIH4000();
virtual void init(); virtual void init();
...@@ -41,6 +56,14 @@ private: ...@@ -41,6 +56,14 @@ private:
float m_temperature = -273.15; float m_temperature = -273.15;
//! The humidity recorded in the last reading (defaults to 0) //! The humidity recorded in the last reading (defaults to 0)
float m_humidity = 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 //! ref. to the temperature sensor from which temp. correction is derived
std::shared_ptr<ClimateSensor> m_tempSens; std::shared_ptr<ClimateSensor> m_tempSens;
}; };
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "HTS221.h" #include "HTS221.h"
#include "Si7021.h" #include "Si7021.h"
#include "SHT85.h" #include "SHT85.h"
#include "HIH4000.h"
#include "HIH6130.h" #include "HIH6130.h"
#include "DeviceCom.h" #include "DeviceCom.h"
...@@ -661,6 +662,11 @@ void register_devcom(py::module& m) { ...@@ -661,6 +662,11 @@ void register_devcom(py::module& m) {
.def(py::init<std::shared_ptr<I2CCom>>()) .def(py::init<std::shared_ptr<I2CCom>>())
.def("status", &SHT85::status); .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") py::class_<HIH6130, PySensor_w_status<HIH6130>, ClimateSensor, std::shared_ptr<HIH6130>>(m, "HIH6130")
.def(py::init<std::shared_ptr<I2CCom>>()) .def(py::init<std::shared_ptr<I2CCom>>())
.def("status", &HIH6130::status); .def("status", &HIH6130::status);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment