Skip to content

Commit

Permalink
Prepare for derived SHT31_SW (#37)
Browse files Browse the repository at this point in the history
- prepare for derived class SHT31_SW
- update readme.md
- update GitHub actions
- update license 2023
- minor edits
  • Loading branch information
RobTillaart committed Mar 22, 2023
1 parent 0208447 commit ac8fdd4
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 29 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).


## [0.3.8] - 2023-03-23
- prepare for derived class SHT31_SW
- update readme.md
- update GitHub actions
- update license 2023
- minor edits


## [0.3.7] - 2022-11-24
- Add RP2040 support to build-CI.
- Add CHANGELOG.md
- update readme.md


## [0.3.6] - 2022-01-18
- sync with SHT85 lib

Expand Down
3 changes: 2 additions & 1 deletion SHT31.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// FILE: SHT31.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.3.7
// VERSION: 0.3.8
// DATE: 2019-02-08
// PURPOSE: Arduino library for the SHT31 temperature and humidity sensor
// https://www.adafruit.com/product/2857
Expand All @@ -28,6 +28,7 @@

SHT31::SHT31()
{
_wire = NULL;
_address = 0;
_lastRead = 0;
_rawTemperature = 0;
Expand Down
54 changes: 29 additions & 25 deletions SHT31.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@
//
// FILE: SHT31.h
// AUTHOR: Rob Tillaart
// VERSION: 0.3.7
// VERSION: 0.3.8
// DATE: 2019-02-08
// PURPOSE: Arduino library for the SHT31 temperature and humidity sensor
// https://www.adafruit.com/product/2857
// URL: https://github.com/RobTillaart/SHT31


#include "Arduino.h"
#include "Wire.h"
#include "Wire.h"


#define SHT31_LIB_VERSION (F("0.3.7"))
#define SHT31_LIB_VERSION (F("0.3.8"))

#ifndef SHT_DEFAULT_ADDRESS
#define SHT_DEFAULT_ADDRESS 0x44
#endif

// fields readStatus
// fields readStatus
#define SHT31_STATUS_ALERT_PENDING (1 << 15)
#define SHT31_STATUS_HEATER_ON (1 << 13)
#define SHT31_STATUS_HUM_TRACK_ALERT (1 << 11)
Expand All @@ -28,7 +28,7 @@
#define SHT31_STATUS_COMMAND_STATUS (1 << 1)
#define SHT31_STATUS_WRITE_CRC_STATUS (1 << 0)

// error codes
// error codes
#define SHT31_OK 0x00
#define SHT31_ERR_WRITECMD 0x81
#define SHT31_ERR_READBYTES 0x82
Expand All @@ -48,30 +48,30 @@ class SHT31

#if defined(ESP8266) || defined(ESP32)
bool begin(const uint8_t address, uint8_t dataPin, uint8_t clockPin);
// use SHT_DEFAULT_ADDRESS
// use SHT_DEFAULT_ADDRESS
bool begin(const uint8_t dataPin, const uint8_t clockPin);
#endif
bool begin(const uint8_t address, TwoWire *wire = &Wire);
// use SHT_DEFAULT_ADDRESS
// use SHT_DEFAULT_ADDRESS
bool begin(TwoWire *wire = &Wire);

// blocks 15 milliseconds + actual read + math
// blocks 15 milliseconds + actual read + math
bool read(bool fast = true);

// check sensor is reachable over I2C
bool isConnected();
// check sensor is reachable over I2C
virtual bool isConnected();

// details see datasheet; summary in SHT31.cpp file
// details see datasheet; summary in SHT31.cpp file
uint16_t readStatus();

// lastRead is in milliSeconds since start
// lastRead is in milliSeconds since start
uint32_t lastRead() { return _lastRead; };

bool reset(bool hard = false);

// do not use heater for long periods,
// use it for max 3 minutes to heat up
// and let it cool down at least 3 minutes.
// do not use heater for long periods,
// use it for max 3 minutes to heat up
// and let it cool down at least 3 minutes.
void setHeatTimeout(uint8_t seconds);
uint8_t getHeatTimeout() { return _heatTimeout; };
bool heatOn();
Expand All @@ -91,18 +91,13 @@ class SHT31
bool dataReady();
bool readData(bool fast = true);

int getError(); // clears error flag

private:
uint8_t crc8(const uint8_t *data, uint8_t len);
bool writeCmd(uint16_t cmd);
bool readBytes(uint8_t n, uint8_t *val);
TwoWire* _wire;
int getError(); // clears error flag

protected:
uint8_t _address;
uint8_t _heatTimeout; // seconds
uint8_t _heatTimeout; // seconds
uint32_t _lastRead;
uint32_t _lastRequest; // for async interface
uint32_t _lastRequest; // for async interface
uint32_t _heaterStart;
uint32_t _heaterStop;
bool _heaterOn;
Expand All @@ -111,6 +106,15 @@ class SHT31
uint16_t _rawTemperature;

uint8_t _error;

private:
uint8_t crc8(const uint8_t *data, uint8_t len);
virtual bool writeCmd(uint16_t cmd);
virtual bool readBytes(uint8_t n, uint8_t *val);
TwoWire* _wire;
};

// -- END OF FILE --

// -- END OF FILE --


2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/SHT31"
},
"version": "0.3.7",
"version": "0.3.8",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*",
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=SHT31
version=0.3.7
version=0.3.8
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for the SHT31 temperature and humidity sensor
Expand Down

0 comments on commit ac8fdd4

Please sign in to comment.