mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-09-19 16:46:11 -04:00
0.1.15 DS18B20_RT
This commit is contained in:
parent
972f7c622f
commit
098f07159f
@ -6,6 +6,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
|
||||
## [0.1.15] - 2023-02-22
|
||||
- fix #20 improve disconnect detection
|
||||
- add **bool isConnected(uint8_t retries)**
|
||||
- update keywords.txt
|
||||
- update readme.md
|
||||
- minor edits
|
||||
|
||||
|
||||
## [0.1.14] - 2023-02-03
|
||||
- update readme.md
|
||||
- add **getResolution()**
|
||||
@ -15,7 +23,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
- update GitHub actions
|
||||
- update license 2023
|
||||
|
||||
|
||||
## [0.1.13] - 2022-11-02
|
||||
- add changelog.md
|
||||
- add rp2040 to build-CI
|
||||
|
@ -1,10 +1,11 @@
|
||||
//
|
||||
// FILE: DS18B20.cpp
|
||||
// AUTHOR: Rob.Tillaart@gmail.com
|
||||
// VERSION: 0.1.14
|
||||
// VERSION: 0.1.15
|
||||
// DATE: 2017-07-25
|
||||
// PUPROSE: library for DS18B20 temperature sensor with minimal footprint
|
||||
// URL: https://github.com/RobTillaart/DS18B20_RT
|
||||
// https://github.com/RobTillaart/DS18B20_INT
|
||||
|
||||
|
||||
#include "DS18B20.h"
|
||||
@ -47,6 +48,17 @@ DS18B20::DS18B20(OneWire* ow)
|
||||
bool DS18B20::begin(uint8_t retries)
|
||||
{
|
||||
_config = DS18B20_CLEAR;
|
||||
isConnected(retries);
|
||||
if (_addressFound)
|
||||
{
|
||||
setResolution();
|
||||
}
|
||||
return _addressFound;
|
||||
}
|
||||
|
||||
|
||||
bool DS18B20::isConnected(uint8_t retries)
|
||||
{
|
||||
_addressFound = false;
|
||||
for (uint8_t rtr = retries; (rtr > 0) && (_addressFound == false); rtr--)
|
||||
{
|
||||
@ -57,19 +69,6 @@ bool DS18B20::begin(uint8_t retries)
|
||||
_addressFound = _deviceAddress[0] != 0x00 &&
|
||||
_oneWire->crc8(_deviceAddress, 7) == _deviceAddress[7];
|
||||
}
|
||||
|
||||
if (_addressFound)
|
||||
{
|
||||
_oneWire->reset();
|
||||
_oneWire->select(_deviceAddress);
|
||||
_oneWire->write(WRITESCRATCH);
|
||||
// two dummy values for LOW & HIGH ALARM
|
||||
_oneWire->write(0);
|
||||
_oneWire->write(100);
|
||||
// lowest as default as we do only integer math.
|
||||
_oneWire->write(_resolution);
|
||||
_oneWire->reset();
|
||||
}
|
||||
return _addressFound;
|
||||
}
|
||||
|
||||
@ -91,6 +90,10 @@ bool DS18B20::isConversionComplete(void)
|
||||
float DS18B20::getTempC(void)
|
||||
{
|
||||
ScratchPad scratchPad;
|
||||
if (isConnected(3) == false)
|
||||
{
|
||||
return DEVICE_DISCONNECTED;
|
||||
}
|
||||
|
||||
if (_config & DS18B20_CRC)
|
||||
{
|
||||
|
@ -2,7 +2,7 @@
|
||||
//
|
||||
// FILE: DS18B20.h
|
||||
// AUTHOR: Rob.Tillaart@gmail.com
|
||||
// VERSION: 0.1.14
|
||||
// VERSION: 0.1.15
|
||||
// DATE: 2017-07-25
|
||||
// PUPROSE: library for DS18B20 temperature sensor with minimal footprint
|
||||
// URL: https://github.com/RobTillaart/DS18B20_RT
|
||||
@ -19,7 +19,7 @@
|
||||
//
|
||||
|
||||
|
||||
#define DS18B20_LIB_VERSION (F("0.1.14"))
|
||||
#define DS18B20_LIB_VERSION (F("0.1.15"))
|
||||
|
||||
#include <OneWire.h>
|
||||
|
||||
@ -27,7 +27,7 @@
|
||||
#define DEVICE_DISCONNECTED -127
|
||||
#define DEVICE_CRC_ERROR -128
|
||||
|
||||
// config codes
|
||||
// configuration codes
|
||||
#define DS18B20_CLEAR 0x00
|
||||
#define DS18B20_CRC 0x01
|
||||
|
||||
@ -41,6 +41,7 @@ class DS18B20
|
||||
public:
|
||||
explicit DS18B20(OneWire * ow);
|
||||
bool begin(uint8_t retries = 3);
|
||||
bool isConnected(uint8_t retries = 3);
|
||||
|
||||
void requestTemperatures(void);
|
||||
bool isConversionComplete(void);
|
||||
|
@ -47,12 +47,15 @@ the asynchronous reading of the temperature by means of three core functions:
|
||||
- **bool begin(uint8_t retries = 3)** resets oneWire and set resolution default to 9 bit.
|
||||
returns true if all is OK.
|
||||
There will be a number of retries to connect, default 3.
|
||||
- **bool isConnected(uint8_t retries = 3)** resets oneWire checks if a device can be found.
|
||||
Returns true if a device is found.
|
||||
- **void requestTemperatures()** trigger temperature conversion.
|
||||
- **bool isConversionComplete()** check if conversion is complete.
|
||||
- **float getTempC()** returns temperature
|
||||
-127 = DEVICE_DISCONNECTED
|
||||
- **void setResolution(uint8_t resolution = 9)** resolution = 9..12 (9 is default)
|
||||
- **bool getAddress()** returns true if the sensor is configured (available)
|
||||
- **uint8_t getResolution()** return resolution set.
|
||||
- **bool getAddress()** returns true if the sensor is configured (available).
|
||||
|
||||
This allowed the class to be both minimal in size and non-blocking. In fact the class
|
||||
has no support for a synchronous read in one call. This choice will teach people
|
||||
@ -65,10 +68,19 @@ few problems when you need more functionality like multiple sensors on one pin.
|
||||
Finally this library will probably make it easier to use a DS18B20 with processing
|
||||
boards or IC's with small memory footprint.
|
||||
|
||||
#### Config
|
||||
|
||||
- **void setConfig(uint8_t config)** set DS18B20_CLEAR or DS18B20_CRC.
|
||||
If DS18B20_CRC flag is set the library will check the CRC, otherwise it won't.
|
||||
Not checking the CRC is faster.
|
||||
- **uint8_t getConfig()** get current configuration
|
||||
- 1 == DS18B20_CRC
|
||||
- 0 == no flag set.
|
||||
|
||||
|
||||
## Operation
|
||||
|
||||
This library supports only one DS18B20 per Arduino/ MCU pin.
|
||||
This library supports only **one** DS18B20 per Arduino/ MCU pin.
|
||||
|
||||
```
|
||||
// BOTTOM VIEW
|
||||
@ -147,14 +159,10 @@ and all people who contributed to that lib.
|
||||
#### Should
|
||||
|
||||
- add examples
|
||||
- a multi sensor == multiple pins, no bus
|
||||
- investigate performance gain of no CRC.
|
||||
|
||||
#### Could
|
||||
|
||||
- add rounding for **getTempC()**.
|
||||
- now it truncates, so it can be 0.5°C off.
|
||||
- add "0.5" to raw and truncate improves only for 10 bits and higher.
|
||||
|
||||
#### Wont
|
||||
|
||||
- unit tests
|
||||
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// FILE: DS18B20_two_sensors.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: demo with two sensors (on two pins)
|
||||
// PURPOSE: demo with two sensors on two different pins
|
||||
// URL: https://github.com/RobTillaart/DS18B20_RT
|
||||
|
||||
|
||||
|
@ -9,6 +9,7 @@ DeviceAddress KEYWORD1
|
||||
|
||||
# Methods and Functions (KEYWORD2)
|
||||
begin KEYWORD2
|
||||
isConnected KEYWORD2
|
||||
|
||||
requestTemperatures KEYWORD2
|
||||
isConversionComplete KEYWORD2
|
||||
|
@ -23,7 +23,7 @@
|
||||
"version": "^2.3.5"
|
||||
}
|
||||
],
|
||||
"version": "0.1.14",
|
||||
"version": "0.1.15",
|
||||
"license": "MIT",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*",
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=DS18B20_RT
|
||||
version=0.1.14
|
||||
version=0.1.15
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino library for the DS18B20 temperature sensor.
|
||||
|
Loading…
Reference in New Issue
Block a user