update library.json, license, minor edits

This commit is contained in:
rob tillaart 2021-12-17 11:26:25 +01:00
parent 883fcaada3
commit ecd315e3e7
12 changed files with 94 additions and 90 deletions

View File

@ -1,7 +1,7 @@
//
// FILE: DS18B20_INT.cpp
// AUTHOR: Rob.Tillaart@gmail.com
// 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
@ -9,82 +9,83 @@
// 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 --

View File

@ -2,7 +2,7 @@
//
// FILE: DS18B20_INT.h
// AUTHOR: Rob.Tillaart@gmail.com
// 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,15 +20,13 @@
//
#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];
@ -36,7 +34,7 @@ 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 @@ public:
private:
DeviceAddress _deviceAddress;
OneWire* _wire;
bool _addresFound;
OneWire* _oneWire;
bool _addressFound;
};
// -- END OF FILE --

View File

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2017-2021 Rob Tillaart
Copyright (c) 2017-2022 Rob Tillaart
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@ -31,14 +31,14 @@ This DS18B20_INT library supports only the DS18B20, only one sensor per pin, no
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:
- **DS18B20_INT(onewire)** constructor needs a reference to OneWire object.
- **DS18B20_INT(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
- **void requestTemperatures()** trigger temperature conversion.
- **bool isConversionComplete()** check if conversion is complete.
- **int16_t getTempC()** returns temperature in whole degrees only. -55..125
-127 = DEVICE_DISCONNECTED
- **bool getAddress()** returns true if the sensor is configured (available)
- **bool getAddress()** returns true if the sensor is configured (available).
## Operation
@ -71,14 +71,14 @@ Note: thicker wires require smaller resistors (typically 1 step in E12 series)
| Length | - 5.0 Volt | - 3.3 Volt |
|--------------:|------------:|----------:|
| 10cm (4") | 10K0 | 6K8 |
| 20cm (8") | 8K2 | 4K7 |
| 50cm (20") | 4K7 | 3K3 |
| 100cm (3'4") | 3K3 | 2K2 |
| 200cm (6'8") | 2K2 | 1K0 |
| 500cm (16'8") | 1K0 | \* |
| longer | * | \* |
|--------------:|------------:|-----------:|
| 10cm (4") | 10K0 | 6K8 |
| 20cm (8") | 8K2 | 4K7 |
| 50cm (20") | 4K7 | 3K3 |
| 100cm (3'4") | 3K3 | 2K2 |
| 200cm (6'8") | 2K2 | 1K0 |
| 500cm (16'8") | 1K0 | \* |
| longer | * | \* |
\* = no info, smaller
@ -88,3 +88,9 @@ Note: thicker wires require smaller resistors (typically 1 step in E12 series)
Miles Burton who originally developed the Arduino Temperature Control Library.
and all people who contributed to that lib.
## Future
- add examples
- a multi sensor == multiple pins, no bus

View File

@ -7,7 +7,7 @@
#include "DS18B20_INT.h"
#define ONE_WIRE_BUS 2
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DS18B20_INT sensor(&oneWire);
@ -41,4 +41,6 @@ void loop()
delay(1000);
}
// -- END OF FILE --

View File

@ -1,18 +1,14 @@
//
// 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
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DS18B20_INT sensor(&oneWire);
@ -29,7 +25,7 @@ void setup()
Serial.print("\ngetAddress: ");
Serial.println(sensor.getAddress(da));
sensor.begin();
Serial.print("\ngetAddress: ");
@ -53,8 +49,8 @@ void setup()
void loop()
{
}
// -- END OF FILE --

View File

@ -1,22 +1,18 @@
//
// 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
// and therefore 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
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DS18B20_INT sensor(&oneWire);
@ -37,4 +33,6 @@ void loop(void)
Serial.println(sensor.getTempC());
}
// -- END OF FILE --

View File

@ -1,18 +1,14 @@
//
// 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
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DS18B20_INT sensor(&oneWire);
@ -32,11 +28,13 @@ void setup(void)
void loop(void)
{
sensor.requestTemperatures();
while (!sensor.isConversionComplete()); // wait until sensor is ready
while (!sensor.isConversionComplete()); // (BLOCKING!!) wait until sensor is ready
Serial.print("Temp: ");
Serial.println(sensor.getTempC());
}
// -- END OF FILE --

View File

@ -1,6 +1,6 @@
# Syntax Coloring Map For DS18B20_INT
# Syntax Colouring Map For DS18B20_INT
# Datatypes (KEYWORD1)
# Data types (KEYWORD1)
DS18B20_INT KEYWORD1

View File

@ -23,8 +23,9 @@
"version": "^2.3.5"
}
],
"version": "0.1.6",
"version": "0.1.7",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*"
"platforms": "*",
"headers": "DS18B20_INT.h"
}

View File

@ -1,5 +1,5 @@
name=DS18B20_int
version=0.1.6
version=0.1.7
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Library for DS18B20 restricted to a single sensor per pin.

View File

@ -31,8 +31,10 @@
unittest_setup()
{
fprintf(stderr, "DS18B20_INT_LIB_VERSION: %s\n", (char *) DS18B20_INT_LIB_VERSION);
}
unittest_teardown()
{
}
@ -40,8 +42,6 @@ unittest_teardown()
unittest(test_constructor)
{
fprintf(stderr, "DS18B20_INT_LIB_VERSION: %s\n", DS18B20_INT_LIB_VERSION);
OneWire oneWire(4);
DS18B20_INT sensor(&oneWire);
@ -54,6 +54,7 @@ unittest(test_constructor)
assertEqual(0, sensor.getTempC());
}
unittest_main()
// --------