diff --git a/lib/HM330x/HM330x.cpp b/lib/HM330x/HM330x.cpp index ad83f9d..3cff2d8 100644 --- a/lib/HM330x/HM330x.cpp +++ b/lib/HM330x/HM330x.cpp @@ -30,13 +30,21 @@ #include "HM330x.h" // Default Constructor -HM330x::HM330x() {}; +HM330x::HM330x(uint8_t sp = 0) { + sleep_pin = sp; +}; // Initialize the Sensor void HM330x::initialize(void) { uint8_t retryCount = 0; DEBUG_PRINTLN("HM330x::initialize"); + // Enable Sleep Mode if Pin is Configured + if (sleep_pin > 0) { + pinMode(sleep_pin, OUTPUT); + digitalWrite(sleep_pin, HIGH); + } + // Wait for Sensor to get Ready DEBUG_PRINTLN("HM330x::initialize Waiting for Sensor Startup"); delay(30000); @@ -60,6 +68,12 @@ uint8_t HM330x::getSensorData(char *payload, uint8_t startbyte) { uint16_t value = 0; DEBUG_PRINTLN("HM330x::getSensorData"); + + // Enable Sensor and Wait for it to Settle + if (sleep_pin > 0) { + digitalWrite(sleep_pin, HIGH); + delay(30000); + } // Initialize Payload with 0s for (uint8_t i=startbyte; i < startbyte+6; i++) @@ -82,12 +96,18 @@ uint8_t HM330x::getSensorData(char *payload, uint8_t startbyte) { uint16ToPayload(value, payload, startbyte); startbyte += 2; } + if (sleep_pin > 0) { + digitalWrite(sleep_pin, LOW); + } return startbyte; } else { for (uint8_t i=startbyte; i < startbyte+6; i++) payload[i] = 0xEE; } } + if (sleep_pin > 0) { + digitalWrite(sleep_pin, LOW); + } return startbyte+6; } diff --git a/lib/HM330x/HM330x.h b/lib/HM330x/HM330x.h index 28b89d1..d0d26b1 100644 --- a/lib/HM330x/HM330x.h +++ b/lib/HM330x/HM330x.h @@ -38,13 +38,13 @@ class HM330x : public AttSensor { private: + uint8_t sleep_pin = 0; bool sendCmd(uint8_t cmd); uint8_t calcSum(uint8_t bytes[]); uint16_t bytesToUint16(uint8_t bytes[], uint8_t pos); public: - HM330x(); - HM330x(uint8_t interval, bool selfcalib); + HM330x(uint8_t sp = 0); void initialize(void); void calibrate(void) {}; uint8_t numBytes(void) {return 6;}; diff --git a/src/config.h.example b/src/config.h.example index 4a27ea2..eba7578 100644 --- a/src/config.h.example +++ b/src/config.h.example @@ -66,11 +66,17 @@ * Sensor Configuration * Change according to your Needs *************************************************************************************************************************/ + // Pin for the OneWire Bus #define DS18B20_PIN PIN_PC3 // A/D Resolution of the DS18B20 (9-12 Bit) #define DS18B20_RES 12 +// Connect a free pin on the ATTNode to the SET-Pin on the HM3301-Board +// Set HM330x_SLLEP_PIN to the choosen pin to enable the Sleep-Mode of the HM3301. +// Setting it to 0 disables Sleep Mode +#define HM330x_SLEEP_PIN 0 + /************************************************************************************************************************** * How many minutes to sleep between Measuring/Sending * Since this is a 2-byte value internally, intervals between 1 and 65536 are possible diff --git a/src/main.cpp b/src/main.cpp index d7687e5..32f4b95 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -366,7 +366,7 @@ void setup() i++; #endif #ifdef HAS_HM330x - sensors[i] = new HM330x(); + sensors[i] = new HM330x(HM330x_SLEEP_PIN); i++; #endif #ifdef HAS_DS18B20