-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update library.json, license, minor edits (#9)
- Loading branch information
1 parent
c4b33bd
commit 8e329c3
Showing
12 changed files
with
92 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,90 +1,91 @@ | ||
// | ||
// FILE: DS18B20_INT.cpp | ||
// AUTHOR: [email protected] | ||
// VERSION: 0.1.6 | ||
// VERSION: 0.1.7 | ||
// DATE: 2017-07-25 | ||
// PUPROSE: library for DS18B20 temperature sensor - integer only. | ||
// URL: https://github.com/RobTillaart/DS18B20_INT | ||
// | ||
// HISTORY: | ||
// 0.1.0 2017-07-25 initial version | ||
// 0.1.1 2019- | ||
// 0.1.2 2020-08-05 refactor / sync with DS18B20 | ||
// 0.1.3 2020-12-20 add arduino-ci + unit test | ||
// 0.1.4 2021-05-26 add onewire.reset() to begin() | ||
// 0.1.5 2021-06-16 add retries param to begin() | ||
// 0.1.2 2020-08-05 refactor / sync with DS18B20 | ||
// 0.1.3 2020-12-20 add Arduino-CI + unit test | ||
// 0.1.4 2021-05-26 add OneWire.reset() to begin() | ||
// 0.1.5 2021-06-16 add retries parameter to begin() | ||
// 0.1.6 2021-10-03 add dependency + fix build-CI | ||
// 0.1.7 2021-12-17 update library.json, license, minor edits | ||
|
||
|
||
#include "DS18B20_INT.h" | ||
|
||
// OneWire commands | ||
#define STARTCONVO 0x44 | ||
#define READSCRATCH 0xBE | ||
#define WRITESCRATCH 0x4E | ||
#define STARTCONVO 0x44 | ||
#define READSCRATCH 0xBE | ||
#define WRITESCRATCH 0x4E | ||
|
||
|
||
// Device resolution | ||
#define TEMP_9_BIT 0x1F // 9 bit | ||
#define TEMP_9_BIT 0x1F // 9 bit | ||
|
||
|
||
DS18B20_INT::DS18B20_INT(OneWire* _oneWire) | ||
DS18B20_INT::DS18B20_INT(OneWire* ow) | ||
{ | ||
_wire = _oneWire; | ||
_addresFound = false; | ||
_oneWire = ow; | ||
_addressFound = false; | ||
} | ||
|
||
|
||
bool DS18B20_INT::begin(uint8_t retries) | ||
{ | ||
_addresFound = false; | ||
for (uint8_t rtr = retries; (rtr > 0) && (_addresFound == false); rtr--) | ||
_addressFound = false; | ||
for (uint8_t rtr = retries; (rtr > 0) && (_addressFound == false); rtr--) | ||
{ | ||
_wire->reset(); | ||
_wire->reset_search(); | ||
_oneWire->reset(); | ||
_oneWire->reset_search(); | ||
_deviceAddress[0] = 0x00; | ||
_wire->search(_deviceAddress); | ||
_addresFound = _deviceAddress[0] != 0x00 && | ||
_wire->crc8(_deviceAddress, 7) == _deviceAddress[7]; | ||
_oneWire->search(_deviceAddress); | ||
_addressFound = _deviceAddress[0] != 0x00 && | ||
_oneWire->crc8(_deviceAddress, 7) == _deviceAddress[7]; | ||
} | ||
|
||
if (_addresFound) | ||
if (_addressFound) | ||
{ | ||
_wire->reset(); | ||
_wire->select(_deviceAddress); | ||
_wire->write(WRITESCRATCH); | ||
_oneWire->reset(); | ||
_oneWire->select(_deviceAddress); | ||
_oneWire->write(WRITESCRATCH); | ||
// two dummy values for LOW & HIGH ALARM | ||
_wire->write(0); | ||
_wire->write(100); | ||
_wire->write(TEMP_9_BIT); // lowest as we do only integer math. | ||
_wire->reset(); | ||
_oneWire->write(0); | ||
_oneWire->write(100); | ||
_oneWire->write(TEMP_9_BIT); // lowest as we do only integer math. | ||
_oneWire->reset(); | ||
} | ||
return _addresFound; | ||
return _addressFound; | ||
} | ||
|
||
|
||
void DS18B20_INT::requestTemperatures(void) | ||
{ | ||
_wire->reset(); | ||
_wire->skip(); | ||
_wire->write(STARTCONVO, 0); | ||
_oneWire->reset(); | ||
_oneWire->skip(); | ||
_oneWire->write(STARTCONVO, 0); | ||
} | ||
|
||
|
||
bool DS18B20_INT::isConversionComplete(void) | ||
{ | ||
return (_wire->read_bit() == 1); | ||
return (_oneWire->read_bit() == 1); | ||
} | ||
|
||
|
||
int16_t DS18B20_INT::getTempC(void) | ||
{ | ||
_wire->reset(); | ||
_wire->select(_deviceAddress); | ||
_wire->write(READSCRATCH); | ||
int16_t rawTemperature = ((int16_t)_wire->read()) << 8; | ||
rawTemperature |= _wire->read(); | ||
_wire->reset(); | ||
_oneWire->reset(); | ||
_oneWire->select(_deviceAddress); | ||
_oneWire->write(READSCRATCH); | ||
int16_t rawTemperature = ((int16_t)_oneWire->read()) << 8; | ||
rawTemperature |= _oneWire->read(); | ||
_oneWire->reset(); | ||
rawTemperature >>= 4; | ||
if (rawTemperature < -55) return DEVICE_DISCONNECTED; | ||
return rawTemperature; | ||
|
@@ -93,15 +94,16 @@ int16_t DS18B20_INT::getTempC(void) | |
|
||
bool DS18B20_INT::getAddress(uint8_t* buf) | ||
{ | ||
if (_addresFound) | ||
if (_addressFound) | ||
{ | ||
for (uint8_t i = 0; i < 8; i++) | ||
{ | ||
buf[i] = _deviceAddress[i]; | ||
} | ||
} | ||
return _addresFound; | ||
return _addressFound; | ||
} | ||
|
||
|
||
// -- END OF FILE -- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
// | ||
// FILE: DS18B20_INT.h | ||
// AUTHOR: [email protected] | ||
// VERSION: 0.1.6 | ||
// VERSION: 0.1.7 | ||
// DATE: 2017-07-25 | ||
// PUPROSE: Minimalistic library for DS18B20 temperature sensor | ||
// uses only integer math (no float to minimize footprint) | ||
|
@@ -20,23 +20,21 @@ | |
// | ||
|
||
|
||
#define DS18B20_INT_LIB_VERSION (F("0.1.6")) | ||
|
||
#define DS18B20_INT_LIB_VERSION (F("0.1.7")) | ||
|
||
#include "Arduino.h" | ||
#include "OneWire.h" | ||
|
||
|
||
// Error Code | ||
#define DEVICE_DISCONNECTED -127 | ||
#define DEVICE_DISCONNECTED -127 | ||
|
||
typedef uint8_t DeviceAddress[8]; | ||
|
||
|
||
class DS18B20_INT | ||
{ | ||
public: | ||
explicit DS18B20_INT(OneWire *); | ||
explicit DS18B20_INT(OneWire * ow); | ||
bool begin(uint8_t retries = 3); | ||
void requestTemperatures(void); | ||
int16_t getTempC(void); | ||
|
@@ -45,8 +43,10 @@ class DS18B20_INT | |
|
||
private: | ||
DeviceAddress _deviceAddress; | ||
OneWire* _wire; | ||
bool _addresFound; | ||
OneWire* _oneWire; | ||
bool _addressFound; | ||
}; | ||
|
||
|
||
// -- END OF FILE -- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.