mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.1.10 DS18B20_RT
This commit is contained in:
parent
580626494a
commit
2c4ed138a1
@ -1,7 +1,7 @@
|
||||
//
|
||||
// FILE: DS18B20.cpp
|
||||
// AUTHOR: Rob.Tillaart@gmail.com
|
||||
// VERSION: 0.1.9
|
||||
// VERSION: 0.1.10
|
||||
// DATE: 2017-07-25
|
||||
// PUPROSE: library for DS18B20 temperature sensor with minimal footprint
|
||||
//
|
||||
@ -16,6 +16,7 @@
|
||||
// 0.1.7 2020-12-20 add arduino CI + unit test
|
||||
// 0.1.8 2021-04-08 clear scratchpad before read + update readme.md
|
||||
// 0.1.9 2021-05-26 add oneWire.reset() in begin()
|
||||
// 0.1.10 2021-06-14 add retries param to begin()
|
||||
|
||||
|
||||
#include "DS18B20.h"
|
||||
@ -54,11 +55,11 @@ DS18B20::DS18B20(OneWire* _oneWire)
|
||||
}
|
||||
|
||||
|
||||
bool DS18B20::begin(void)
|
||||
bool DS18B20::begin(uint8_t retries)
|
||||
{
|
||||
_config = DS18B20_CLEAR;
|
||||
_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();
|
||||
@ -158,12 +159,13 @@ bool DS18B20::getAddress(uint8_t* buf)
|
||||
{
|
||||
if (_addresFound)
|
||||
{
|
||||
for (uint8_t i = 0; i < 8; i++)
|
||||
{
|
||||
buf[i] = _deviceAddress[i];
|
||||
}
|
||||
for (uint8_t i = 0; i < 8; i++)
|
||||
{
|
||||
buf[i] = _deviceAddress[i];
|
||||
}
|
||||
}
|
||||
return _addresFound;
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
@ -2,7 +2,7 @@
|
||||
//
|
||||
// FILE: DS18B20.h
|
||||
// AUTHOR: Rob.Tillaart@gmail.com
|
||||
// VERSION: 0.1.9
|
||||
// VERSION: 0.1.10
|
||||
// DATE: 2017-07-25
|
||||
// PUPROSE: library for DS18B20 temperature sensor with minimal footprint
|
||||
//
|
||||
@ -18,7 +18,7 @@
|
||||
// \---+
|
||||
//
|
||||
|
||||
#define DS18B20_LIB_VERSION (F("0.1.8"))
|
||||
#define DS18B20_LIB_VERSION (F("0.1.10"))
|
||||
|
||||
#include <OneWire.h>
|
||||
|
||||
@ -39,12 +39,12 @@ class DS18B20
|
||||
{
|
||||
public:
|
||||
explicit DS18B20(OneWire *);
|
||||
bool begin(void);
|
||||
void setResolution(uint8_t);
|
||||
bool begin(uint8_t retries = 3);
|
||||
void setResolution(uint8_t newResolution = 9);
|
||||
void requestTemperatures(void);
|
||||
float getTempC(void);
|
||||
bool isConversionComplete(void);
|
||||
bool getAddress(uint8_t*);
|
||||
bool getAddress(uint8_t* buf);
|
||||
|
||||
void setConfig(uint8_t config) { _config = config; };
|
||||
uint8_t getConfig() { return _config; };
|
||||
|
@ -16,24 +16,25 @@ This library supports only one DS18B20 per Arduino/ MCU pin.
|
||||
If you need more functions or control over the DS18B20 family I refer to the library
|
||||
of Miles Burton - https://github.com/milesburton/Arduino-Temperature-Control-Library
|
||||
|
||||
|
||||
## Description
|
||||
|
||||
I'm a great fan of the above library however some time ago I needed to strip it down
|
||||
to save a few dozen bytes. I reworked that minimalistic version into a library and I
|
||||
added a number of Arduino examples to help you get started.
|
||||
added a number of Arduino examples to help you get started.
|
||||
|
||||
|
||||
## Interface
|
||||
|
||||
The DS18B20 library supports only the DS18B20, only one sensor per pin, no parasite
|
||||
mode, no Fahrenheit and no alarm functions. The only feature the class supports is
|
||||
the asynchronous reading of the temperature by means of three core functions:
|
||||
|
||||
- **void requestTemperatures()**
|
||||
- **bool isConversionComplete()**
|
||||
- **float readTempC()**
|
||||
|
||||
The other main functions are
|
||||
- **bool begin()** returns true if the sensor is configured (available)
|
||||
- **void setResolution(res)** res = 9..12
|
||||
- **DS18B20(onewire)** constructor needs a reference to OneWire object.
|
||||
- **bool begin(uint8_t retries = 3)** resets oneWire and set resolution to 9 bit.
|
||||
returns true if all is OK. there will be a number of retries to connect, default 3.
|
||||
- **void requestTemperatures()** trigger temperature comversion
|
||||
- **bool isConversionComplete()** check if conversion is complete
|
||||
- **float getTempC()** returns temperature
|
||||
-127 = DEVICE_DISCONNECTED
|
||||
- **void setResolution(uint8_t res = 9)** res = 9..12 (9 is default)
|
||||
- **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
|
||||
@ -50,21 +51,24 @@ boards or IC's with small memory footprint.
|
||||
|
||||
## Operation
|
||||
|
||||
```
|
||||
// BOTTOM VIEW
|
||||
//
|
||||
// PIN MEANING
|
||||
// /---+
|
||||
// / o | 1 GND
|
||||
// | o | 2 DATA
|
||||
// \ o | 3 VCC
|
||||
// \---+
|
||||
```
|
||||
|
||||
This library supports only one DS18B20 per Arduino/ MCU pin.
|
||||
|
||||
Connect a pull-up resistor 4.7 KOhm between pin3 and pin2. When the wires are longer
|
||||
this resistor needs to be smaller.
|
||||
```
|
||||
// BOTTOM VIEW
|
||||
//
|
||||
// PIN MEANING
|
||||
// /---+
|
||||
// / o | 1 GND
|
||||
// | o | 2 DATA
|
||||
// \ o | 3 VCC
|
||||
// \---+
|
||||
|
||||
```
|
||||
|
||||
Connect a pull-up resistor 4.7 KOhm between pin3 and pin2.
|
||||
When the wires are longer this resistor needs to be smaller.
|
||||
|
||||
Check examples.
|
||||
|
||||
|
||||
### Pull up resistor
|
||||
|
@ -15,7 +15,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/DS18B20"
|
||||
},
|
||||
"version": "0.1.9",
|
||||
"version": "0.1.10",
|
||||
"license": "MIT",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*"
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=DS18B20_RT
|
||||
version=0.1.9
|
||||
version=0.1.10
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino library for the DS18B20 temperature sensor.
|
||||
|
Loading…
x
Reference in New Issue
Block a user