-
-
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.
0.1.5 add retries to begin() + refactor (#7)
* 0.1.5 add retries to begin() + refactor
- Loading branch information
1 parent
1827d29
commit 954fb8a
Showing
12 changed files
with
236 additions
and
34 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 |
---|---|---|
|
@@ -11,4 +11,3 @@ jobs: | |
- uses: actions/checkout@v2 | ||
- uses: Arduino-CI/action@master | ||
# Arduino-CI/[email protected] | ||
|
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,17 +1,18 @@ | ||
// | ||
// FILE: DS18B20_INT.cpp | ||
// AUTHOR: [email protected] | ||
// VERSION: 0.1.3 | ||
// VERSION: 0.1.5 | ||
// 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() | ||
// 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() | ||
|
||
|
||
#include "DS18B20_INT.h" | ||
|
@@ -21,6 +22,7 @@ | |
#define READSCRATCH 0xBE | ||
#define WRITESCRATCH 0x4E | ||
|
||
|
||
// Device resolution | ||
#define TEMP_9_BIT 0x1F // 9 bit | ||
|
||
|
@@ -32,10 +34,10 @@ DS18B20_INT::DS18B20_INT(OneWire* _oneWire) | |
} | ||
|
||
|
||
bool DS18B20_INT::begin(void) | ||
bool DS18B20_INT::begin(uint8_t retries) | ||
{ | ||
_addresFound = false; | ||
for (uint8_t retries = 3; (retries > 0) && (_addresFound == false); retries--) | ||
for (uint8_t rtr = retries; (rtr > 0) && (_addresFound == false); rtr--) | ||
{ | ||
_wire->reset(); | ||
_wire->reset_search(); | ||
|
@@ -83,10 +85,22 @@ int16_t DS18B20_INT::getTempC(void) | |
rawTemperature |= _wire->read(); | ||
_wire->reset(); | ||
rawTemperature >>= 4; | ||
|
||
if (rawTemperature < -55) return DEVICE_DISCONNECTED; | ||
return rawTemperature; | ||
} | ||
|
||
|
||
bool DS18B20_INT::getAddress(uint8_t* buf) | ||
{ | ||
if (_addresFound) | ||
{ | ||
for (uint8_t i = 0; i < 8; i++) | ||
{ | ||
buf[i] = _deviceAddress[i]; | ||
} | ||
} | ||
return _addresFound; | ||
} | ||
|
||
|
||
// -- 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.4 | ||
// VERSION: 0.1.5 | ||
// DATE: 2017-07-25 | ||
// PUPROSE: Minimalistic library for DS18B20 temperature sensor | ||
// uses only integer math (no float to minimize footprint) | ||
|
@@ -19,9 +19,14 @@ | |
// \---+ | ||
// | ||
|
||
|
||
#define DS18B20_INT_LIB_VERSION (F("0.1.5")) | ||
|
||
|
||
#include "Arduino.h" | ||
#include "OneWire.h" | ||
|
||
|
||
// Error Code | ||
#define DEVICE_DISCONNECTED -127 | ||
|
||
|
@@ -31,16 +36,17 @@ typedef uint8_t DeviceAddress[8]; | |
class DS18B20_INT | ||
{ | ||
public: | ||
explicit DS18B20_INT(OneWire *); | ||
bool begin(void); | ||
void requestTemperatures(void); | ||
bool isConversionComplete(void); | ||
int16_t getTempC(void); | ||
explicit DS18B20_INT(OneWire *); | ||
bool begin(uint8_t retries = 3); | ||
void requestTemperatures(void); | ||
int16_t getTempC(void); | ||
bool isConversionComplete(void); | ||
bool getAddress(uint8_t* buf); | ||
|
||
private: | ||
uint8_t _deviceAddress[8]; | ||
OneWire* _wire; | ||
bool _addresFound; | ||
DeviceAddress _deviceAddress; | ||
OneWire* _wire; | ||
bool _addresFound; | ||
}; | ||
|
||
// -- 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// | ||
// FILE: DS18B20_getAddress.ino | ||
// AUTHOR: Rob Tillaart | ||
// VERSION: 0.0.1 | ||
// PURPOSE: DS18B20 lib getAddress demo | ||
// | ||
// HISTORY: | ||
// 0.0.1 = 2021-06-16 initial version | ||
|
||
|
||
#include <OneWire.h> | ||
#include <DS18B20_INT.h> | ||
|
||
|
||
#define ONE_WIRE_BUS 2 | ||
|
||
OneWire oneWire(ONE_WIRE_BUS); | ||
DS18B20_INT sensor(&oneWire); | ||
|
||
DeviceAddress da; | ||
|
||
|
||
void setup() | ||
{ | ||
Serial.begin(115200); | ||
Serial.println(__FILE__); | ||
Serial.print("DS18B20_INT_LIB_VERSION: "); | ||
Serial.println(DS18B20_INT_LIB_VERSION); | ||
|
||
Serial.print("\ngetAddress: "); | ||
Serial.println(sensor.getAddress(da)); | ||
|
||
sensor.begin(); | ||
|
||
Serial.print("\ngetAddress: "); | ||
Serial.println(sensor.getAddress(da)); | ||
|
||
if (!sensor.getAddress(da)) | ||
{ | ||
Serial.println("No address found!"); | ||
return; | ||
} | ||
|
||
Serial.print("Address: "); | ||
for (uint8_t i = 0; i < 8; i++) | ||
{ | ||
if (da[i] < 0x10) Serial.print('0'); | ||
Serial.print(da[i], HEX); | ||
} | ||
Serial.println(); | ||
} | ||
|
||
|
||
void loop() | ||
{ | ||
|
||
} | ||
|
||
|
||
// -- 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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// | ||
// FILE: DS18B20_minimum.ino | ||
// AUTHOR: Rob Tillaart | ||
// VERSION: 0.0.1 | ||
// PURPOSE: most minimal sketch | ||
// | ||
// WARNING: this sketch does not wait for isConversionComplete() | ||
// and therefor temperature read is probably incorrect | ||
// but it is fast and maybe accurate enough... | ||
// | ||
// HISTORY: | ||
// 0.0.1 = 2021-06-16 initial version | ||
|
||
|
||
#include <OneWire.h> | ||
#include <DS18B20_INT.h> | ||
|
||
|
||
#define ONE_WIRE_BUS 2 | ||
|
||
OneWire oneWire(ONE_WIRE_BUS); | ||
DS18B20_INT sensor(&oneWire); | ||
|
||
|
||
void setup(void) | ||
{ | ||
Serial.begin(115200); | ||
Serial.println(__FILE__); | ||
|
||
sensor.begin(); | ||
} | ||
|
||
|
||
void loop(void) | ||
{ | ||
sensor.requestTemperatures(); | ||
Serial.println(sensor.getTempC()); | ||
} | ||
|
||
// -- 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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// | ||
// FILE: DS18B20_simple.ino | ||
// AUTHOR: Rob Tillaart | ||
// VERSION: 0.0.1 | ||
// PURPOSE: equivalent of DallasTemperature library Simple | ||
// | ||
// HISTORY: | ||
// 0.0.1 = 2021-06-16 initial version | ||
|
||
|
||
#include <OneWire.h> | ||
#include <DS18B20_INT.h> | ||
|
||
|
||
#define ONE_WIRE_BUS 2 | ||
|
||
OneWire oneWire(ONE_WIRE_BUS); | ||
DS18B20_INT sensor(&oneWire); | ||
|
||
|
||
void setup(void) | ||
{ | ||
Serial.begin(115200); | ||
Serial.println(__FILE__); | ||
Serial.print("DS18B20_INT_LIB_VERSION: "); | ||
Serial.println(DS18B20_INT_LIB_VERSION); | ||
|
||
sensor.begin(); | ||
} | ||
|
||
|
||
void loop(void) | ||
{ | ||
sensor.requestTemperatures(); | ||
|
||
while (!sensor.isConversionComplete()); // wait until sensor is ready | ||
|
||
Serial.print("Temp: "); | ||
Serial.println(sensor.getTempC()); | ||
} | ||
|
||
// -- 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
Oops, something went wrong.