ESP32 / ESP8266 & BME280 / SHT2x sensor with InfluxDB support
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

SHT2x.h 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. SHT2x - Humidity Library for Arduino.
  3. Get humidity and temperature from the HTU21D/SHT2x sensors.
  4. Hardware Setup:
  5. Attach the SDA pin to A4, SCL to A5.
  6. Software:
  7. Call SHT2x.Begin() in setup.
  8. SHT2x.ReadHumidity() will return a float containing the humidity. Ex: 54.7
  9. SHT2x.ReadTemperature() will return a float containing the temperature in Celsius. Ex: 24.1
  10. SHT2x.SetResolution(byte: 0b.76543210) sets the resolution of the readings.
  11. Copyright (C) 2015 Nuno Chaveiro nchaveiro[at]gmail.com Lisbon, Portugal
  12. Copyright (C) 2020 Thomas Buck <thomas@xythobuz.de>
  13. */
  14. #if defined(ARDUINO) && ARDUINO >= 100
  15. #include "Arduino.h"
  16. #else
  17. #include "WProgram.h"
  18. #endif
  19. #include <Wire.h>
  20. #ifndef SHT2X_H
  21. #define SHT2X_H
  22. // Unshifted 7-bit I2C address for the sensor
  23. #define HTDU21D_ADDRESS 0x40
  24. #define TRIGGER_TEMP_MEASURE_HOLD 0xE3
  25. #define TRIGGER_HUMD_MEASURE_HOLD 0xE5
  26. #define TRIGGER_TEMP_MEASURE_NOHOLD 0xF3
  27. #define TRIGGER_HUMD_MEASURE_NOHOLD 0xF5
  28. #define WRITE_USER_REG 0xE6
  29. #define READ_USER_REG 0xE7
  30. #define SOFT_RESET 0xFE
  31. #define ERROR_CRC 998
  32. #define ERROR_TIMEOUT 999
  33. class SHT2x {
  34. public:
  35. SHT2x(uint8_t _addr = HTDU21D_ADDRESS, TwoWire* _wire = &Wire);
  36. void begin();
  37. bool GetAlive(void);
  38. float GetHumidity(void);
  39. float GetTemperature(void);
  40. void setResolution(uint8_t resBits);
  41. uint8_t read_user_register(void);
  42. uint16_t readSensor(uint8_t command);
  43. private:
  44. uint8_t check_crc(uint16_t message_from_sensor, uint8_t check_value_from_sensor);
  45. uint8_t addr;
  46. TwoWire* wire;
  47. };
  48. #endif