Make HM3301 Sleep Mode Usable

This commit is contained in:
seiichiro 2021-05-30 08:52:10 +02:00
parent 6b86aa707b
commit e974463add
4 changed files with 30 additions and 4 deletions

View file

@ -30,13 +30,21 @@
#include "HM330x.h" #include "HM330x.h"
// Default Constructor // Default Constructor
HM330x::HM330x() {}; HM330x::HM330x(uint8_t sp = 0) {
sleep_pin = sp;
};
// Initialize the Sensor // Initialize the Sensor
void HM330x::initialize(void) { void HM330x::initialize(void) {
uint8_t retryCount = 0; uint8_t retryCount = 0;
DEBUG_PRINTLN("HM330x::initialize"); 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 // Wait for Sensor to get Ready
DEBUG_PRINTLN("HM330x::initialize Waiting for Sensor Startup"); DEBUG_PRINTLN("HM330x::initialize Waiting for Sensor Startup");
delay(30000); delay(30000);
@ -61,6 +69,12 @@ uint8_t HM330x::getSensorData(char *payload, uint8_t startbyte) {
DEBUG_PRINTLN("HM330x::getSensorData"); 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 // Initialize Payload with 0s
for (uint8_t i=startbyte; i < startbyte+6; i++) for (uint8_t i=startbyte; i < startbyte+6; i++)
payload[i] = 0xFF; payload[i] = 0xFF;
@ -82,12 +96,18 @@ uint8_t HM330x::getSensorData(char *payload, uint8_t startbyte) {
uint16ToPayload(value, payload, startbyte); uint16ToPayload(value, payload, startbyte);
startbyte += 2; startbyte += 2;
} }
if (sleep_pin > 0) {
digitalWrite(sleep_pin, LOW);
}
return startbyte; return startbyte;
} else { } else {
for (uint8_t i=startbyte; i < startbyte+6; i++) for (uint8_t i=startbyte; i < startbyte+6; i++)
payload[i] = 0xEE; payload[i] = 0xEE;
} }
} }
if (sleep_pin > 0) {
digitalWrite(sleep_pin, LOW);
}
return startbyte+6; return startbyte+6;
} }

View file

@ -38,13 +38,13 @@
class HM330x : public AttSensor { class HM330x : public AttSensor {
private: private:
uint8_t sleep_pin = 0;
bool sendCmd(uint8_t cmd); bool sendCmd(uint8_t cmd);
uint8_t calcSum(uint8_t bytes[]); uint8_t calcSum(uint8_t bytes[]);
uint16_t bytesToUint16(uint8_t bytes[], uint8_t pos); uint16_t bytesToUint16(uint8_t bytes[], uint8_t pos);
public: public:
HM330x(); HM330x(uint8_t sp = 0);
HM330x(uint8_t interval, bool selfcalib);
void initialize(void); void initialize(void);
void calibrate(void) {}; void calibrate(void) {};
uint8_t numBytes(void) {return 6;}; uint8_t numBytes(void) {return 6;};

View file

@ -66,11 +66,17 @@
* Sensor Configuration * Sensor Configuration
* Change according to your Needs * Change according to your Needs
*************************************************************************************************************************/ *************************************************************************************************************************/
// Pin for the OneWire Bus // Pin for the OneWire Bus
#define DS18B20_PIN PIN_PC3 #define DS18B20_PIN PIN_PC3
// A/D Resolution of the DS18B20 (9-12 Bit) // A/D Resolution of the DS18B20 (9-12 Bit)
#define DS18B20_RES 12 #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 * How many minutes to sleep between Measuring/Sending
* Since this is a 2-byte value internally, intervals between 1 and 65536 are possible * Since this is a 2-byte value internally, intervals between 1 and 65536 are possible

View file

@ -366,7 +366,7 @@ void setup()
i++; i++;
#endif #endif
#ifdef HAS_HM330x #ifdef HAS_HM330x
sensors[i] = new HM330x(); sensors[i] = new HM330x(HM330x_SLEEP_PIN);
i++; i++;
#endif #endif
#ifdef HAS_DS18B20 #ifdef HAS_DS18B20