mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
added getAddress()
This commit is contained in:
parent
77635d6463
commit
00c7809986
@ -1,13 +1,14 @@
|
||||
//
|
||||
// FILE: DS18B20.cpp
|
||||
// AUTHOR: Rob.Tillaart@gmail.com
|
||||
// VERSION: 0.1.0
|
||||
// VERSION: 0.1.1
|
||||
// DATE: 2017-07-25
|
||||
//
|
||||
// PUPROSE: library for DS18B20 temperature sensor with minimal footprint
|
||||
//
|
||||
// HISTORY:
|
||||
// 0.1.0 = 2017-07-25 initial version
|
||||
// 0.1.0 2017-07-25 initial version
|
||||
// 0.1.1 2020-02-18 added getAddress()
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "DS18B20.h"
|
||||
@ -38,13 +39,16 @@
|
||||
DS18B20::DS18B20(OneWire* _oneWire)
|
||||
{
|
||||
_wire = _oneWire;
|
||||
configured = false;
|
||||
}
|
||||
|
||||
bool DS18B20::begin(void)
|
||||
{
|
||||
_wire->reset_search();
|
||||
_wire->search(deviceAddress);
|
||||
return (_wire->crc8(deviceAddress, 7) == deviceAddress[7]);
|
||||
configured = _wire->crc8(deviceAddress, 7) == deviceAddress[7]
|
||||
&& deviceAddress[0] != 0x00;
|
||||
return configured;
|
||||
}
|
||||
|
||||
void DS18B20::readScratchPad(uint8_t *scratchPad, uint8_t fields)
|
||||
@ -111,4 +115,16 @@ void DS18B20::setResolution(uint8_t newResolution)
|
||||
_wire->reset();
|
||||
}
|
||||
|
||||
// END OF FILE
|
||||
bool DS18B20::getAddress(uint8_t* buf)
|
||||
{
|
||||
if (configured)
|
||||
{
|
||||
for (uint8_t i = 0; i< 8; i++)
|
||||
{
|
||||
buf[i] = deviceAddress[i];
|
||||
}
|
||||
}
|
||||
return configured;
|
||||
}
|
||||
|
||||
// END OF FILE
|
||||
|
@ -1,16 +1,26 @@
|
||||
//
|
||||
// FILE: DS18B20.h
|
||||
// AUTHOR: Rob.Tillaart@gmail.com
|
||||
// VERSION: 0.1.0
|
||||
// VERSION: 0.1.1
|
||||
// DATE: 2017-07-25
|
||||
//
|
||||
// PUPROSE: library for DS18B20 temperature sensor with minimal footprint
|
||||
//
|
||||
|
||||
//
|
||||
// BOTTOM VIEW
|
||||
//
|
||||
// /---+
|
||||
// / o | GND
|
||||
// | o | DATA
|
||||
// \ o | VCC
|
||||
// \---+
|
||||
//
|
||||
|
||||
#ifndef DS18B20_H
|
||||
#define DS18B20_H
|
||||
|
||||
#define DS18B20_LIB_VERSION "0.1.0"
|
||||
#define DS18B20_LIB_VERSION "0.1.1"
|
||||
|
||||
#include <OneWire.h>
|
||||
|
||||
@ -29,11 +39,13 @@ public:
|
||||
void requestTemperatures(void);
|
||||
float getTempC(void);
|
||||
bool isConversionComplete(void);
|
||||
bool getAddress(uint8_t*);
|
||||
|
||||
private:
|
||||
void readScratchPad(uint8_t *, uint8_t);
|
||||
DeviceAddress deviceAddress;
|
||||
OneWire* _wire;
|
||||
bool configured;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -0,0 +1,58 @@
|
||||
//
|
||||
// FILE: DS18B20_getAddress.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.0.1
|
||||
// PURPOSE: DS18B20 lib getAddress demo
|
||||
//
|
||||
// HISTORY:
|
||||
// 0.0.1 = 2020-02-18 initial version
|
||||
|
||||
#include <OneWire.h>
|
||||
#include <DS18B20.h>
|
||||
|
||||
#define ONE_WIRE_BUS 2
|
||||
|
||||
OneWire oneWire(ONE_WIRE_BUS);
|
||||
DS18B20 sensor(&oneWire);
|
||||
|
||||
uint32_t start, stop;
|
||||
|
||||
DeviceAddress da;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("DS18B20 Library version: ");
|
||||
Serial.println(DS18B20_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
|
@ -15,7 +15,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/Arduino.git"
|
||||
},
|
||||
"version":"0.1.0",
|
||||
"version":"0.1.1",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*",
|
||||
"export": {
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=DS18B20
|
||||
version=0.1.0
|
||||
version=0.1.1
|
||||
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. Rewritten minimalistic version of Dallas Temperature Control Library of Miles Burton.
|
||||
|
@ -20,6 +20,10 @@ the asynchronous reading of the temperature by means of three core functions:
|
||||
* isConversionComplete()
|
||||
* readTempC()
|
||||
|
||||
Version 0.1.1 added getAddress() as this info is available as private data.
|
||||
* getAddress(uint8_t*)
|
||||
|
||||
|
||||
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
|
||||
how to work in a non-blocking way from the start.
|
||||
|
Loading…
x
Reference in New Issue
Block a user