@@ -2,6 +2,7 @@ | |||||
#define APP_H | #define APP_H | ||||
#include <Arduino.h> | #include <Arduino.h> | ||||
#include <Spirulerie.h> | |||||
#include "DataTypes.h" | #include "DataTypes.h" | ||||
#include "IODefinitions.h" | #include "IODefinitions.h" | ||||
@@ -41,7 +42,7 @@ | |||||
// Defines | // Defines | ||||
#define MAX_PERCENTAGE_LIGHT 35 // do not go above this value or the LED will fail (burn, melt plastic etc...) | #define MAX_PERCENTAGE_LIGHT 35 // do not go above this value or the LED will fail (burn, melt plastic etc...) | ||||
#define MAX_PERCENTAGE_HEATER 65 // So it doesn't draw too much current | |||||
#define MAX_PERCENTAGE_HEATER 75 // So it doesn't draw too much current | |||||
#define SECONDS_TO_SCREENSAVER 45 // only if screensaver is enabled in settings | #define SECONDS_TO_SCREENSAVER 45 // only if screensaver is enabled in settings | ||||
// Main container class for program | // Main container class for program | ||||
@@ -58,6 +59,7 @@ class Application | |||||
// RTOS Queues | // RTOS Queues | ||||
QueueHandle_t temperatureQueue; | QueueHandle_t temperatureQueue; | ||||
QueueHandle_t TSensorActiveQueue; | |||||
QueueHandle_t PWMActionsQueue; | QueueHandle_t PWMActionsQueue; | ||||
QueueHandle_t inputQueue; | QueueHandle_t inputQueue; | ||||
QueueHandle_t audioQueue; | QueueHandle_t audioQueue; | ||||
@@ -73,7 +75,7 @@ class Application | |||||
bool lightNominal = true; | bool lightNominal = true; | ||||
bool heatNominal = true; | bool heatNominal = true; | ||||
bool pumpNominal = true; | bool pumpNominal = true; | ||||
bool canGoToScreenSaver = true; | |||||
bool isOnMainMenu = true; | |||||
bool modeNeedsRefresh = true; | bool modeNeedsRefresh = true; | ||||
ModeParameters parameters; | ModeParameters parameters; | ||||
@@ -2,12 +2,11 @@ | |||||
#define THERMOMETER_H | #define THERMOMETER_H | ||||
#include <Arduino.h> | #include <Arduino.h> | ||||
#include <OneWire.h> | |||||
#include <DallasTemperature.h> | |||||
#include <Spirulerie.h> | |||||
#include "App.h" | #include "App.h" | ||||
#define READING_DELAY 10000 //30000 | |||||
#define READING_DELAY 3000 //30000 | |||||
// Global Variables | // Global Variables | ||||
class Thermometer | class Thermometer | ||||
@@ -22,12 +21,10 @@ class Thermometer | |||||
Thermometer(); | Thermometer(); | ||||
bool StartDevice(); | bool StartDevice(); | ||||
float GetTemperature(); | float GetTemperature(); | ||||
}; | }; | ||||
// Functions | // Functions | ||||
TaskHandle_t InitThermometer(); // entry point | TaskHandle_t InitThermometer(); // entry point | ||||
void ThermometerTask(void *parameter); // RTOS task loop | |||||
void ThermometerTask(void *parameter); // RTOS task loop | |||||
#endif | #endif |
@@ -1,16 +0,0 @@ | |||||
.idea | |||||
classes | |||||
target | |||||
out | |||||
build | |||||
*.iml | |||||
*.ipr | |||||
*.iws | |||||
*.log | |||||
*.war | |||||
.idea | |||||
.project | |||||
.classpath | |||||
.settings | |||||
.gradle | |||||
.vscode |
@@ -1,69 +0,0 @@ | |||||
{ | |||||
"name": "DallasTemperature", | |||||
"repository": { | |||||
"url": "https://github.com/milesburton/Arduino-Temperature-Control-Library.git", | |||||
"type": "git" | |||||
}, | |||||
"platforms": [ | |||||
"atmelavr", | |||||
"atmelmegaavr", | |||||
"atmelsam", | |||||
"espressif32", | |||||
"espressif8266", | |||||
"gd32v", | |||||
"infineonxmc", | |||||
"intel_arc32", | |||||
"kendryte210", | |||||
"microchippic32", | |||||
"nordicnrf51", | |||||
"nordicnrf52", | |||||
"ststm32", | |||||
"ststm8", | |||||
"teensy", | |||||
"timsp430" | |||||
], | |||||
"frameworks": [ | |||||
"arduino" | |||||
], | |||||
"dependencies": { | |||||
"frameworks": "arduino", | |||||
"name": "OneWire", | |||||
"authors": "Paul Stoffregen" | |||||
}, | |||||
"version": "3.8.1", | |||||
"authors": [ | |||||
{ | |||||
"maintainer": true, | |||||
"name": "Miles Burton", | |||||
"url": "http://www.milesburton.com", | |||||
"email": "miles@mnetcs.com" | |||||
}, | |||||
{ | |||||
"url": null, | |||||
"maintainer": false, | |||||
"email": "nuisance@casualhacker.net", | |||||
"name": "Tim Newsome" | |||||
}, | |||||
{ | |||||
"url": null, | |||||
"maintainer": false, | |||||
"email": "gfbarros@bappos.com", | |||||
"name": "Guil Barros" | |||||
}, | |||||
{ | |||||
"url": null, | |||||
"maintainer": false, | |||||
"email": "rob.tillaart@gmail.com", | |||||
"name": "Rob Tillaart" | |||||
} | |||||
], | |||||
"keywords": [ | |||||
"bus", | |||||
"sensor", | |||||
"1-wire", | |||||
"onewire", | |||||
"temperature" | |||||
], | |||||
"id": 54, | |||||
"description": "Arduino Library for Dallas Temperature ICs (DS18B20, DS18S20, DS1822, DS1820)" | |||||
} |
@@ -1,940 +0,0 @@ | |||||
// This library is free software; you can redistribute it and/or | |||||
// modify it under the terms of the GNU Lesser General Public | |||||
// License as published by the Free Software Foundation; either | |||||
// version 2.1 of the License, or (at your option) any later version. | |||||
#include "DallasTemperature.h" | |||||
#if ARDUINO >= 100 | |||||
#include "Arduino.h" | |||||
#else | |||||
extern "C" { | |||||
#include "WConstants.h" | |||||
} | |||||
#endif | |||||
// OneWire commands | |||||
#define STARTCONVO 0x44 // Tells device to take a temperature reading and put it on the scratchpad | |||||
#define COPYSCRATCH 0x48 // Copy EEPROM | |||||
#define READSCRATCH 0xBE // Read EEPROM | |||||
#define WRITESCRATCH 0x4E // Write to EEPROM | |||||
#define RECALLSCRATCH 0xB8 // Reload from last known | |||||
#define READPOWERSUPPLY 0xB4 // Determine if device needs parasite power | |||||
#define ALARMSEARCH 0xEC // Query bus for devices with an alarm condition | |||||
// Scratchpad locations | |||||
#define TEMP_LSB 0 | |||||
#define TEMP_MSB 1 | |||||
#define HIGH_ALARM_TEMP 2 | |||||
#define LOW_ALARM_TEMP 3 | |||||
#define CONFIGURATION 4 | |||||
#define INTERNAL_BYTE 5 | |||||
#define COUNT_REMAIN 6 | |||||
#define COUNT_PER_C 7 | |||||
#define SCRATCHPAD_CRC 8 | |||||
// Device resolution | |||||
#define TEMP_9_BIT 0x1F // 9 bit | |||||
#define TEMP_10_BIT 0x3F // 10 bit | |||||
#define TEMP_11_BIT 0x5F // 11 bit | |||||
#define TEMP_12_BIT 0x7F // 12 bit | |||||
#define NO_ALARM_HANDLER ((AlarmHandler *)0) | |||||
DallasTemperature::DallasTemperature() | |||||
{ | |||||
#if REQUIRESALARMS | |||||
setAlarmHandler(NO_ALARM_HANDLER); | |||||
#endif | |||||
useExternalPullup = false; | |||||
} | |||||
DallasTemperature::DallasTemperature(OneWire* _oneWire) | |||||
{ | |||||
setOneWire(_oneWire); | |||||
#if REQUIRESALARMS | |||||
setAlarmHandler(NO_ALARM_HANDLER); | |||||
#endif | |||||
useExternalPullup = false; | |||||
} | |||||
bool DallasTemperature::validFamily(const uint8_t* deviceAddress) { | |||||
switch (deviceAddress[0]) { | |||||
case DS18S20MODEL: | |||||
case DS18B20MODEL: | |||||
case DS1822MODEL: | |||||
case DS1825MODEL: | |||||
case DS28EA00MODEL: | |||||
return true; | |||||
default: | |||||
return false; | |||||
} | |||||
} | |||||
/* | |||||
* Constructs DallasTemperature with strong pull-up turned on. Strong pull-up is mandated in DS18B20 datasheet for parasitic | |||||
* power (2 wires) setup. (https://datasheets.maximintegrated.com/en/ds/DS18B20.pdf, p. 7, section 'Powering the DS18B20'). | |||||
*/ | |||||
DallasTemperature::DallasTemperature(OneWire* _oneWire, uint8_t _pullupPin) : DallasTemperature(_oneWire){ | |||||
setPullupPin(_pullupPin); | |||||
} | |||||
void DallasTemperature::setPullupPin(uint8_t _pullupPin) { | |||||
useExternalPullup = true; | |||||
pullupPin = _pullupPin; | |||||
pinMode(pullupPin, OUTPUT); | |||||
deactivateExternalPullup(); | |||||
} | |||||
void DallasTemperature::setOneWire(OneWire* _oneWire) { | |||||
_wire = _oneWire; | |||||
devices = 0; | |||||
ds18Count = 0; | |||||
parasite = false; | |||||
bitResolution = 9; | |||||
waitForConversion = true; | |||||
checkForConversion = true; | |||||
} | |||||
// initialise the bus | |||||
void DallasTemperature::begin(void) { | |||||
DeviceAddress deviceAddress; | |||||
_wire->reset_search(); | |||||
devices = 0; // Reset the number of devices when we enumerate wire devices | |||||
ds18Count = 0; // Reset number of DS18xxx Family devices | |||||
while (_wire->search(deviceAddress)) { | |||||
if (validAddress(deviceAddress)) { | |||||
if (!parasite && readPowerSupply(deviceAddress)) | |||||
parasite = true; | |||||
bitResolution = max(bitResolution, getResolution(deviceAddress)); | |||||
devices++; | |||||
if (validFamily(deviceAddress)) { | |||||
ds18Count++; | |||||
} | |||||
} | |||||
} | |||||
} | |||||
// returns the number of devices found on the bus | |||||
uint8_t DallasTemperature::getDeviceCount(void) { | |||||
return devices; | |||||
} | |||||
uint8_t DallasTemperature::getDS18Count(void) { | |||||
return ds18Count; | |||||
} | |||||
// returns true if address is valid | |||||
bool DallasTemperature::validAddress(const uint8_t* deviceAddress) { | |||||
return (_wire->crc8(deviceAddress, 7) == deviceAddress[7]); | |||||
} | |||||
// finds an address at a given index on the bus | |||||
// returns true if the device was found | |||||
bool DallasTemperature::getAddress(uint8_t* deviceAddress, uint8_t index) { | |||||
uint8_t depth = 0; | |||||
_wire->reset_search(); | |||||
while (depth <= index && _wire->search(deviceAddress)) { | |||||
if (depth == index && validAddress(deviceAddress)) | |||||
return true; | |||||
depth++; | |||||
} | |||||
return false; | |||||
} | |||||
// attempt to determine if the device at the given address is connected to the bus | |||||
bool DallasTemperature::isConnected(const uint8_t* deviceAddress) { | |||||
ScratchPad scratchPad; | |||||
return isConnected(deviceAddress, scratchPad); | |||||
} | |||||
// attempt to determine if the device at the given address is connected to the bus | |||||
// also allows for updating the read scratchpad | |||||
bool DallasTemperature::isConnected(const uint8_t* deviceAddress, | |||||
uint8_t* scratchPad) { | |||||
bool b = readScratchPad(deviceAddress, scratchPad); | |||||
return b && !isAllZeros(scratchPad) && (_wire->crc8(scratchPad, 8) == scratchPad[SCRATCHPAD_CRC]); | |||||
} | |||||
bool DallasTemperature::readScratchPad(const uint8_t* deviceAddress, | |||||
uint8_t* scratchPad) { | |||||
// send the reset command and fail fast | |||||
int b = _wire->reset(); | |||||
if (b == 0) | |||||
return false; | |||||
_wire->select(deviceAddress); | |||||
_wire->write(READSCRATCH); | |||||
// Read all registers in a simple loop | |||||
// byte 0: temperature LSB | |||||
// byte 1: temperature MSB | |||||
// byte 2: high alarm temp | |||||
// byte 3: low alarm temp | |||||
// byte 4: DS18S20: store for crc | |||||
// DS18B20 & DS1822: configuration register | |||||
// byte 5: internal use & crc | |||||
// byte 6: DS18S20: COUNT_REMAIN | |||||
// DS18B20 & DS1822: store for crc | |||||
// byte 7: DS18S20: COUNT_PER_C | |||||
// DS18B20 & DS1822: store for crc | |||||
// byte 8: SCRATCHPAD_CRC | |||||
for (uint8_t i = 0; i < 9; i++) { | |||||
scratchPad[i] = _wire->read(); | |||||
} | |||||
b = _wire->reset(); | |||||
return (b == 1); | |||||
} | |||||
void DallasTemperature::writeScratchPad(const uint8_t* deviceAddress, | |||||
const uint8_t* scratchPad) { | |||||
_wire->reset(); | |||||
_wire->select(deviceAddress); | |||||
_wire->write(WRITESCRATCH); | |||||
_wire->write(scratchPad[HIGH_ALARM_TEMP]); // high alarm temp | |||||
_wire->write(scratchPad[LOW_ALARM_TEMP]); // low alarm temp | |||||
// DS1820 and DS18S20 have no configuration register | |||||
if (deviceAddress[0] != DS18S20MODEL) | |||||
_wire->write(scratchPad[CONFIGURATION]); | |||||
_wire->reset(); | |||||
// save the newly written values to eeprom | |||||
_wire->select(deviceAddress); | |||||
_wire->write(COPYSCRATCH, parasite); | |||||
delay(20); // <--- added 20ms delay to allow 10ms long EEPROM write operation (as specified by datasheet) | |||||
if (parasite) { | |||||
activateExternalPullup(); | |||||
delay(10); // 10ms delay | |||||
deactivateExternalPullup(); | |||||
} | |||||
_wire->reset(); | |||||
} | |||||
// returns true if parasite mode is used (2 wire) | |||||
// returns false if normal mode is used (3 wire) | |||||
// if no address is given (or nullptr) it checks if any device on the bus | |||||
// uses parasite mode. | |||||
// See issue #145 | |||||
bool DallasTemperature::readPowerSupply(const uint8_t* deviceAddress) | |||||
{ | |||||
bool parasiteMode = false; | |||||
_wire->reset(); | |||||
if (deviceAddress == nullptr) | |||||
_wire->skip(); | |||||
else | |||||
_wire->select(deviceAddress); | |||||
_wire->write(READPOWERSUPPLY); | |||||
if (_wire->read_bit() == 0) | |||||
parasiteMode = true; | |||||
_wire->reset(); | |||||
return parasiteMode; | |||||
} | |||||
// set resolution of all devices to 9, 10, 11, or 12 bits | |||||
// if new resolution is out of range, it is constrained. | |||||
void DallasTemperature::setResolution(uint8_t newResolution) { | |||||
bitResolution = constrain(newResolution, 9, 12); | |||||
DeviceAddress deviceAddress; | |||||
for (int i = 0; i < devices; i++) { | |||||
getAddress(deviceAddress, i); | |||||
setResolution(deviceAddress, bitResolution, true); | |||||
} | |||||
} | |||||
// set resolution of a device to 9, 10, 11, or 12 bits | |||||
// if new resolution is out of range, 9 bits is used. | |||||
bool DallasTemperature::setResolution(const uint8_t* deviceAddress, | |||||
uint8_t newResolution, bool skipGlobalBitResolutionCalculation) { | |||||
// ensure same behavior as setResolution(uint8_t newResolution) | |||||
newResolution = constrain(newResolution, 9, 12); | |||||
// return when stored value == new value | |||||
if (getResolution(deviceAddress) == newResolution) | |||||
return true; | |||||
ScratchPad scratchPad; | |||||
if (isConnected(deviceAddress, scratchPad)) { | |||||
// DS1820 and DS18S20 have no resolution configuration register | |||||
if (deviceAddress[0] != DS18S20MODEL) { | |||||
switch (newResolution) { | |||||
case 12: | |||||
scratchPad[CONFIGURATION] = TEMP_12_BIT; | |||||
break; | |||||
case 11: | |||||
scratchPad[CONFIGURATION] = TEMP_11_BIT; | |||||
break; | |||||
case 10: | |||||
scratchPad[CONFIGURATION] = TEMP_10_BIT; | |||||
break; | |||||
case 9: | |||||
default: | |||||
scratchPad[CONFIGURATION] = TEMP_9_BIT; | |||||
break; | |||||
} | |||||
writeScratchPad(deviceAddress, scratchPad); | |||||
// without calculation we can always set it to max | |||||
bitResolution = max(bitResolution, newResolution); | |||||
if (!skipGlobalBitResolutionCalculation | |||||
&& (bitResolution > newResolution)) { | |||||
bitResolution = newResolution; | |||||
DeviceAddress deviceAddr; | |||||
for (int i = 0; i < devices; i++) { | |||||
getAddress(deviceAddr, i); | |||||
bitResolution = max(bitResolution, | |||||
getResolution(deviceAddr)); | |||||
} | |||||
} | |||||
} | |||||
return true; // new value set | |||||
} | |||||
return false; | |||||
} | |||||
// returns the global resolution | |||||
uint8_t DallasTemperature::getResolution() { | |||||
return bitResolution; | |||||
} | |||||
// returns the current resolution of the device, 9-12 | |||||
// returns 0 if device not found | |||||
uint8_t DallasTemperature::getResolution(const uint8_t* deviceAddress) { | |||||
// DS1820 and DS18S20 have no resolution configuration register | |||||
if (deviceAddress[0] == DS18S20MODEL) | |||||
return 12; | |||||
ScratchPad scratchPad; | |||||
if (isConnected(deviceAddress, scratchPad)) { | |||||
switch (scratchPad[CONFIGURATION]) { | |||||
case TEMP_12_BIT: | |||||
return 12; | |||||
case TEMP_11_BIT: | |||||
return 11; | |||||
case TEMP_10_BIT: | |||||
return 10; | |||||
case TEMP_9_BIT: | |||||
return 9; | |||||
} | |||||
} | |||||
return 0; | |||||
} | |||||
// sets the value of the waitForConversion flag | |||||
// TRUE : function requestTemperature() etc returns when conversion is ready | |||||
// FALSE: function requestTemperature() etc returns immediately (USE WITH CARE!!) | |||||
// (1) programmer has to check if the needed delay has passed | |||||
// (2) but the application can do meaningful things in that time | |||||
void DallasTemperature::setWaitForConversion(bool flag) { | |||||
waitForConversion = flag; | |||||
} | |||||
// gets the value of the waitForConversion flag | |||||
bool DallasTemperature::getWaitForConversion() { | |||||
return waitForConversion; | |||||
} | |||||
// sets the value of the checkForConversion flag | |||||
// TRUE : function requestTemperature() etc will 'listen' to an IC to determine whether a conversion is complete | |||||
// FALSE: function requestTemperature() etc will wait a set time (worst case scenario) for a conversion to complete | |||||
void DallasTemperature::setCheckForConversion(bool flag) { | |||||
checkForConversion = flag; | |||||
} | |||||
// gets the value of the waitForConversion flag | |||||
bool DallasTemperature::getCheckForConversion() { | |||||
return checkForConversion; | |||||
} | |||||
bool DallasTemperature::isConversionComplete() { | |||||
uint8_t b = _wire->read_bit(); | |||||
return (b == 1); | |||||
} | |||||
// sends command for all devices on the bus to perform a temperature conversion | |||||
void DallasTemperature::requestTemperatures() { | |||||
_wire->reset(); | |||||
_wire->skip(); | |||||
_wire->write(STARTCONVO, parasite); | |||||
// ASYNC mode? | |||||
if (!waitForConversion) | |||||
return; | |||||
blockTillConversionComplete(bitResolution); | |||||
} | |||||
// sends command for one device to perform a temperature by address | |||||
// returns FALSE if device is disconnected | |||||
// returns TRUE otherwise | |||||
bool DallasTemperature::requestTemperaturesByAddress( | |||||
const uint8_t* deviceAddress) { | |||||
uint8_t bitResolution = getResolution(deviceAddress); | |||||
if (bitResolution == 0) { | |||||
return false; //Device disconnected | |||||
} | |||||
_wire->reset(); // Commented by La Spirulerie | |||||
_wire->select(deviceAddress); | |||||
_wire->write(STARTCONVO, parasite); | |||||
// CODE SPIRULERIE | |||||
return (true); | |||||
// ORIGINAL CODE BELOW | |||||
// ASYNC mode? | |||||
if (!waitForConversion) | |||||
return true; | |||||
blockTillConversionComplete(bitResolution); | |||||
return true; | |||||
} | |||||
// Continue to check if the IC has responded with a temperature | |||||
void DallasTemperature::blockTillConversionComplete(uint8_t bitResolution) { | |||||
unsigned long delms = millisToWaitForConversion(bitResolution); | |||||
if (checkForConversion && !parasite) { | |||||
unsigned long start = millis(); | |||||
while (!isConversionComplete() && (millis() - start < delms)) | |||||
yield(); | |||||
} else { | |||||
activateExternalPullup(); | |||||
delay(delms); | |||||
deactivateExternalPullup(); | |||||
} | |||||
} | |||||
// returns number of milliseconds to wait till conversion is complete (based on IC datasheet) | |||||
int16_t DallasTemperature::millisToWaitForConversion(uint8_t bitResolution) { | |||||
switch (bitResolution) { | |||||
case 9: | |||||
return 94; | |||||
case 10: | |||||
return 188; | |||||
case 11: | |||||
return 375; | |||||
default: | |||||
return 750; | |||||
} | |||||
} | |||||
void DallasTemperature::activateExternalPullup() { | |||||
if(useExternalPullup) | |||||
digitalWrite(pullupPin, LOW); | |||||
} | |||||
void DallasTemperature::deactivateExternalPullup() { | |||||
if(useExternalPullup) | |||||
digitalWrite(pullupPin, HIGH); | |||||
} | |||||
// sends command for one device to perform a temp conversion by index | |||||
bool DallasTemperature::requestTemperaturesByIndex(uint8_t deviceIndex) { | |||||
DeviceAddress deviceAddress; | |||||
getAddress(deviceAddress, deviceIndex); | |||||
return requestTemperaturesByAddress(deviceAddress); | |||||
} | |||||
// Fetch temperature for device index | |||||
float DallasTemperature::getTempCByIndex(uint8_t deviceIndex) { | |||||
DeviceAddress deviceAddress; | |||||
if (!getAddress(deviceAddress, deviceIndex)) { | |||||
return DEVICE_DISCONNECTED_C; | |||||
} | |||||
return getTempC((uint8_t*) deviceAddress); | |||||
} | |||||
// Fetch temperature for device index | |||||
float DallasTemperature::getTempFByIndex(uint8_t deviceIndex) { | |||||
DeviceAddress deviceAddress; | |||||
if (!getAddress(deviceAddress, deviceIndex)) { | |||||
return DEVICE_DISCONNECTED_F; | |||||
} | |||||
return getTempF((uint8_t*) deviceAddress); | |||||
} | |||||
// reads scratchpad and returns fixed-point temperature, scaling factor 2^-7 | |||||
int16_t DallasTemperature::calculateTemperature(const uint8_t* deviceAddress, | |||||
uint8_t* scratchPad) { | |||||
int16_t fpTemperature = (((int16_t) scratchPad[TEMP_MSB]) << 11) | |||||
| (((int16_t) scratchPad[TEMP_LSB]) << 3); | |||||
/* | |||||
DS1820 and DS18S20 have a 9-bit temperature register. | |||||
Resolutions greater than 9-bit can be calculated using the data from | |||||
the temperature, and COUNT REMAIN and COUNT PER °C registers in the | |||||
scratchpad. The resolution of the calculation depends on the model. | |||||
While the COUNT PER °C register is hard-wired to 16 (10h) in a | |||||
DS18S20, it changes with temperature in DS1820. | |||||
After reading the scratchpad, the TEMP_READ value is obtained by | |||||
truncating the 0.5°C bit (bit 0) from the temperature data. The | |||||
extended resolution temperature can then be calculated using the | |||||
following equation: | |||||
COUNT_PER_C - COUNT_REMAIN | |||||
TEMPERATURE = TEMP_READ - 0.25 + -------------------------- | |||||
COUNT_PER_C | |||||
Hagai Shatz simplified this to integer arithmetic for a 12 bits | |||||
value for a DS18S20, and James Cameron added legacy DS1820 support. | |||||
See - http://myarduinotoy.blogspot.co.uk/2013/02/12bit-result-from-ds18s20.html | |||||
*/ | |||||
if ((deviceAddress[0] == DS18S20MODEL) && (scratchPad[COUNT_PER_C] != 0)) { | |||||
fpTemperature = ((fpTemperature & 0xfff0) << 3) - 32 | |||||
+ (((scratchPad[COUNT_PER_C] - scratchPad[COUNT_REMAIN]) << 7) | |||||
/ scratchPad[COUNT_PER_C]); | |||||
} | |||||
return fpTemperature; | |||||
} | |||||
// returns temperature in 1/128 degrees C or DEVICE_DISCONNECTED_RAW if the | |||||
// device's scratch pad cannot be read successfully. | |||||
// the numeric value of DEVICE_DISCONNECTED_RAW is defined in | |||||
// DallasTemperature.h. It is a large negative number outside the | |||||
// operating range of the device | |||||
int16_t DallasTemperature::getTemp(const uint8_t* deviceAddress) { | |||||
ScratchPad scratchPad; | |||||
if (isConnected(deviceAddress, scratchPad)) | |||||
return calculateTemperature(deviceAddress, scratchPad); | |||||
return DEVICE_DISCONNECTED_RAW; | |||||
} | |||||
// returns temperature in degrees C or DEVICE_DISCONNECTED_C if the | |||||
// device's scratch pad cannot be read successfully. | |||||
// the numeric value of DEVICE_DISCONNECTED_C is defined in | |||||
// DallasTemperature.h. It is a large negative number outside the | |||||
// operating range of the device | |||||
float DallasTemperature::getTempC(const uint8_t* deviceAddress) { | |||||
return rawToCelsius(getTemp(deviceAddress)); | |||||
} | |||||
// returns temperature in degrees F or DEVICE_DISCONNECTED_F if the | |||||
// device's scratch pad cannot be read successfully. | |||||
// the numeric value of DEVICE_DISCONNECTED_F is defined in | |||||
// DallasTemperature.h. It is a large negative number outside the | |||||
// operating range of the device | |||||
float DallasTemperature::getTempF(const uint8_t* deviceAddress) { | |||||
return rawToFahrenheit(getTemp(deviceAddress)); | |||||
} | |||||
// returns true if the bus requires parasite power | |||||
bool DallasTemperature::isParasitePowerMode(void) { | |||||
return parasite; | |||||
} | |||||
// IF alarm is not used one can store a 16 bit int of userdata in the alarm | |||||
// registers. E.g. an ID of the sensor. | |||||
// See github issue #29 | |||||
// note if device is not connected it will fail writing the data. | |||||
void DallasTemperature::setUserData(const uint8_t* deviceAddress, | |||||
int16_t data) { | |||||
// return when stored value == new value | |||||
if (getUserData(deviceAddress) == data) | |||||
return; | |||||
ScratchPad scratchPad; | |||||
if (isConnected(deviceAddress, scratchPad)) { | |||||
scratchPad[HIGH_ALARM_TEMP] = data >> 8; | |||||
scratchPad[LOW_ALARM_TEMP] = data & 255; | |||||
writeScratchPad(deviceAddress, scratchPad); | |||||
} | |||||
} | |||||
int16_t DallasTemperature::getUserData(const uint8_t* deviceAddress) { | |||||
int16_t data = 0; | |||||
ScratchPad scratchPad; | |||||
if (isConnected(deviceAddress, scratchPad)) { | |||||
data = scratchPad[HIGH_ALARM_TEMP] << 8; | |||||
data += scratchPad[LOW_ALARM_TEMP]; | |||||
} | |||||
return data; | |||||
} | |||||
// note If address cannot be found no error will be reported. | |||||
int16_t DallasTemperature::getUserDataByIndex(uint8_t deviceIndex) { | |||||
DeviceAddress deviceAddress; | |||||
getAddress(deviceAddress, deviceIndex); | |||||
return getUserData((uint8_t*) deviceAddress); | |||||
} | |||||
void DallasTemperature::setUserDataByIndex(uint8_t deviceIndex, int16_t data) { | |||||
DeviceAddress deviceAddress; | |||||
getAddress(deviceAddress, deviceIndex); | |||||
setUserData((uint8_t*) deviceAddress, data); | |||||
} | |||||
// Convert float Celsius to Fahrenheit | |||||
float DallasTemperature::toFahrenheit(float celsius) { | |||||
return (celsius * 1.8) + 32; | |||||
} | |||||
// Convert float Fahrenheit to Celsius | |||||
float DallasTemperature::toCelsius(float fahrenheit) { | |||||
return (fahrenheit - 32) * 0.555555556; | |||||
} | |||||
// convert from raw to Celsius | |||||
float DallasTemperature::rawToCelsius(int16_t raw) { | |||||
if (raw <= DEVICE_DISCONNECTED_RAW) | |||||
return DEVICE_DISCONNECTED_C; | |||||
// C = RAW/128 | |||||
return (float) raw * 0.0078125; | |||||
} | |||||
// convert from raw to Fahrenheit | |||||
float DallasTemperature::rawToFahrenheit(int16_t raw) { | |||||
if (raw <= DEVICE_DISCONNECTED_RAW) | |||||
return DEVICE_DISCONNECTED_F; | |||||
// C = RAW/128 | |||||
// F = (C*1.8)+32 = (RAW/128*1.8)+32 = (RAW*0.0140625)+32 | |||||
return ((float) raw * 0.0140625) + 32; | |||||
} | |||||
// Returns true if all bytes of scratchPad are '\0' | |||||
bool DallasTemperature::isAllZeros(const uint8_t * const scratchPad, const size_t length) { | |||||
for (size_t i = 0; i < length; i++) { | |||||
if (scratchPad[i] != 0) { | |||||
return false; | |||||
} | |||||
} | |||||
return true; | |||||
} | |||||
#if REQUIRESALARMS | |||||
/* | |||||
ALARMS: | |||||
TH and TL Register Format | |||||
BIT 7 BIT 6 BIT 5 BIT 4 BIT 3 BIT 2 BIT 1 BIT 0 | |||||
S 2^6 2^5 2^4 2^3 2^2 2^1 2^0 | |||||
Only bits 11 through 4 of the temperature register are used | |||||
in the TH and TL comparison since TH and TL are 8-bit | |||||
registers. If the measured temperature is lower than or equal | |||||
to TL or higher than or equal to TH, an alarm condition exists | |||||
and an alarm flag is set inside the DS18B20. This flag is | |||||
updated after every temperature measurement; therefore, if the | |||||
alarm condition goes away, the flag will be turned off after | |||||
the next temperature conversion. | |||||
*/ | |||||
// sets the high alarm temperature for a device in degrees Celsius | |||||
// accepts a float, but the alarm resolution will ignore anything | |||||
// after a decimal point. valid range is -55C - 125C | |||||
void DallasTemperature::setHighAlarmTemp(const uint8_t* deviceAddress, | |||||
int8_t celsius) { | |||||
// return when stored value == new value | |||||
if (getHighAlarmTemp(deviceAddress) == celsius) | |||||
return; | |||||
// make sure the alarm temperature is within the device's range | |||||
if (celsius > 125) | |||||
celsius = 125; | |||||
else if (celsius < -55) | |||||
celsius = -55; | |||||
ScratchPad scratchPad; | |||||
if (isConnected(deviceAddress, scratchPad)) { | |||||
scratchPad[HIGH_ALARM_TEMP] = (uint8_t) celsius; | |||||
writeScratchPad(deviceAddress, scratchPad); | |||||
} | |||||
} | |||||
// sets the low alarm temperature for a device in degrees Celsius | |||||
// accepts a float, but the alarm resolution will ignore anything | |||||
// after a decimal point. valid range is -55C - 125C | |||||
void DallasTemperature::setLowAlarmTemp(const uint8_t* deviceAddress, | |||||
int8_t celsius) { | |||||
// return when stored value == new value | |||||
if (getLowAlarmTemp(deviceAddress) == celsius) | |||||
return; | |||||
// make sure the alarm temperature is within the device's range | |||||
if (celsius > 125) | |||||
celsius = 125; | |||||
else if (celsius < -55) | |||||
celsius = -55; | |||||
ScratchPad scratchPad; | |||||
if (isConnected(deviceAddress, scratchPad)) { | |||||
scratchPad[LOW_ALARM_TEMP] = (uint8_t) celsius; | |||||
writeScratchPad(deviceAddress, scratchPad); | |||||
} | |||||
} | |||||
// returns a int8_t with the current high alarm temperature or | |||||
// DEVICE_DISCONNECTED for an address | |||||
int8_t DallasTemperature::getHighAlarmTemp(const uint8_t* deviceAddress) { | |||||
ScratchPad scratchPad; | |||||
if (isConnected(deviceAddress, scratchPad)) | |||||
return (int8_t) scratchPad[HIGH_ALARM_TEMP]; | |||||
return DEVICE_DISCONNECTED_C; | |||||
} | |||||
// returns a int8_t with the current low alarm temperature or | |||||
// DEVICE_DISCONNECTED for an address | |||||
int8_t DallasTemperature::getLowAlarmTemp(const uint8_t* deviceAddress) { | |||||
ScratchPad scratchPad; | |||||
if (isConnected(deviceAddress, scratchPad)) | |||||
return (int8_t) scratchPad[LOW_ALARM_TEMP]; | |||||
return DEVICE_DISCONNECTED_C; | |||||
} | |||||
// resets internal variables used for the alarm search | |||||
void DallasTemperature::resetAlarmSearch() { | |||||
alarmSearchJunction = -1; | |||||
alarmSearchExhausted = 0; | |||||
for (uint8_t i = 0; i < 7; i++) { | |||||
alarmSearchAddress[i] = 0; | |||||
} | |||||
} | |||||
// This is a modified version of the OneWire::search method. | |||||
// | |||||
// Also added the OneWire search fix documented here: | |||||
// http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1238032295 | |||||
// | |||||
// Perform an alarm search. If this function returns a '1' then it has | |||||
// enumerated the next device and you may retrieve the ROM from the | |||||
// OneWire::address variable. If there are no devices, no further | |||||
// devices, or something horrible happens in the middle of the | |||||
// enumeration then a 0 is returned. If a new device is found then | |||||
// its address is copied to newAddr. Use | |||||
// DallasTemperature::resetAlarmSearch() to start over. | |||||
bool DallasTemperature::alarmSearch(uint8_t* newAddr) { | |||||
uint8_t i; | |||||
int8_t lastJunction = -1; | |||||
uint8_t done = 1; | |||||
if (alarmSearchExhausted) | |||||
return false; | |||||
if (!_wire->reset()) | |||||
return false; | |||||
// send the alarm search command | |||||
_wire->write(0xEC, 0); | |||||
for (i = 0; i < 64; i++) { | |||||
uint8_t a = _wire->read_bit(); | |||||
uint8_t nota = _wire->read_bit(); | |||||
uint8_t ibyte = i / 8; | |||||
uint8_t ibit = 1 << (i & 7); | |||||
// I don't think this should happen, this means nothing responded, but maybe if | |||||
// something vanishes during the search it will come up. | |||||
if (a && nota) | |||||
return false; | |||||
if (!a && !nota) { | |||||
if (i == alarmSearchJunction) { | |||||
// this is our time to decide differently, we went zero last time, go one. | |||||
a = 1; | |||||
alarmSearchJunction = lastJunction; | |||||
} else if (i < alarmSearchJunction) { | |||||
// take whatever we took last time, look in address | |||||
if (alarmSearchAddress[ibyte] & ibit) { | |||||
a = 1; | |||||
} else { | |||||
// Only 0s count as pending junctions, we've already exhausted the 0 side of 1s | |||||
a = 0; | |||||
done = 0; | |||||
lastJunction = i; | |||||
} | |||||
} else { | |||||
// we are blazing new tree, take the 0 | |||||
a = 0; | |||||
alarmSearchJunction = i; | |||||
done = 0; | |||||
} | |||||
// OneWire search fix | |||||
// See: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1238032295 | |||||
} | |||||
if (a) | |||||
alarmSearchAddress[ibyte] |= ibit; | |||||
else | |||||
alarmSearchAddress[ibyte] &= ~ibit; | |||||
_wire->write_bit(a); | |||||
} | |||||
if (done) | |||||
alarmSearchExhausted = 1; | |||||
for (i = 0; i < 8; i++) | |||||
newAddr[i] = alarmSearchAddress[i]; | |||||
return true; | |||||
} | |||||
// returns true if device address might have an alarm condition | |||||
// (only an alarm search can verify this) | |||||
bool DallasTemperature::hasAlarm(const uint8_t* deviceAddress) { | |||||
ScratchPad scratchPad; | |||||
if (isConnected(deviceAddress, scratchPad)) { | |||||
int8_t temp = calculateTemperature(deviceAddress, scratchPad) >> 7; | |||||
// check low alarm | |||||
if (temp <= (int8_t) scratchPad[LOW_ALARM_TEMP]) | |||||
return true; | |||||
// check high alarm | |||||
if (temp >= (int8_t) scratchPad[HIGH_ALARM_TEMP]) | |||||
return true; | |||||
} | |||||
// no alarm | |||||
return false; | |||||
} | |||||
// returns true if any device is reporting an alarm condition on the bus | |||||
bool DallasTemperature::hasAlarm(void) { | |||||
DeviceAddress deviceAddress; | |||||
resetAlarmSearch(); | |||||
return alarmSearch(deviceAddress); | |||||
} | |||||
// runs the alarm handler for all devices returned by alarmSearch() | |||||
// unless there no _AlarmHandler exist. | |||||
void DallasTemperature::processAlarms(void) { | |||||
if (!hasAlarmHandler()) | |||||
{ | |||||
return; | |||||
} | |||||
resetAlarmSearch(); | |||||
DeviceAddress alarmAddr; | |||||
while (alarmSearch(alarmAddr)) { | |||||
if (validAddress(alarmAddr)) { | |||||
_AlarmHandler(alarmAddr); | |||||
} | |||||
} | |||||
} | |||||
// sets the alarm handler | |||||
void DallasTemperature::setAlarmHandler(const AlarmHandler *handler) { | |||||
_AlarmHandler = handler; | |||||
} | |||||
// checks if AlarmHandler has been set. | |||||
bool DallasTemperature::hasAlarmHandler() | |||||
{ | |||||
return _AlarmHandler != NO_ALARM_HANDLER; | |||||
} | |||||
#endif | |||||
#if REQUIRESNEW | |||||
// MnetCS - Allocates memory for DallasTemperature. Allows us to instance a new object | |||||
void* DallasTemperature::operator new(unsigned int size) { // Implicit NSS obj size | |||||
void * p;// void pointer | |||||
p = malloc(size);// Allocate memory | |||||
memset((DallasTemperature*)p,0,size);// Initialise memory | |||||
//!!! CANT EXPLICITLY CALL CONSTRUCTOR - workaround by using an init() methodR - workaround by using an init() method | |||||
return (DallasTemperature*) p;// Cast blank region to NSS pointer | |||||
} | |||||
// MnetCS 2009 - Free the memory used by this instance | |||||
void DallasTemperature::operator delete(void* p) { | |||||
DallasTemperature* pNss = (DallasTemperature*) p; // Cast to NSS pointer | |||||
pNss->~DallasTemperature();// Destruct the object | |||||
free(p);// Free the memory | |||||
} | |||||
#endif |
@@ -1,274 +0,0 @@ | |||||
#ifndef DallasTemperature_h | |||||
#define DallasTemperature_h | |||||
#define DALLASTEMPLIBVERSION "3.8.1" // To be deprecated -> TODO remove in 4.0.0 | |||||
// This library is free software; you can redistribute it and/or | |||||
// modify it under the terms of the GNU Lesser General Public | |||||
// License as published by the Free Software Foundation; either | |||||
// version 2.1 of the License, or (at your option) any later version. | |||||
// set to true to include code for new and delete operators | |||||
#ifndef REQUIRESNEW | |||||
#define REQUIRESNEW false | |||||
#endif | |||||
// set to true to include code implementing alarm search functions | |||||
#ifndef REQUIRESALARMS | |||||
#define REQUIRESALARMS true | |||||
#endif | |||||
#include <inttypes.h> | |||||
#ifdef __STM32F1__ | |||||
#include <OneWireSTM.h> | |||||
#else | |||||
#include <OneWire.h> | |||||
#endif | |||||
// Model IDs | |||||
#define DS18S20MODEL 0x10 // also DS1820 | |||||
#define DS18B20MODEL 0x28 | |||||
#define DS1822MODEL 0x22 | |||||
#define DS1825MODEL 0x3B | |||||
#define DS28EA00MODEL 0x42 | |||||
// Error Codes | |||||
#define DEVICE_DISCONNECTED_C -127 | |||||
#define DEVICE_DISCONNECTED_F -196.6 | |||||
#define DEVICE_DISCONNECTED_RAW -7040 | |||||
// For readPowerSupply on oneWire bus | |||||
#ifndef nullptr | |||||
#define nullptr NULL | |||||
#endif | |||||
typedef uint8_t DeviceAddress[8]; | |||||
class DallasTemperature { | |||||
public: | |||||
DallasTemperature(); | |||||
DallasTemperature(OneWire*); | |||||
DallasTemperature(OneWire*, uint8_t); | |||||
void setOneWire(OneWire*); | |||||
void setPullupPin(uint8_t); | |||||
// initialise bus | |||||
void begin(void); | |||||
// returns the number of devices found on the bus | |||||
uint8_t getDeviceCount(void); | |||||
// returns the number of DS18xxx Family devices on bus | |||||
uint8_t getDS18Count(void); | |||||
// returns true if address is valid | |||||
bool validAddress(const uint8_t*); | |||||
// returns true if address is of the family of sensors the lib supports. | |||||
bool validFamily(const uint8_t* deviceAddress); | |||||
// finds an address at a given index on the bus | |||||
bool getAddress(uint8_t*, uint8_t); | |||||
// attempt to determine if the device at the given address is connected to the bus | |||||
bool isConnected(const uint8_t*); | |||||
// attempt to determine if the device at the given address is connected to the bus | |||||
// also allows for updating the read scratchpad | |||||
bool isConnected(const uint8_t*, uint8_t*); | |||||
// read device's scratchpad | |||||
bool readScratchPad(const uint8_t*, uint8_t*); | |||||
// write device's scratchpad | |||||
void writeScratchPad(const uint8_t*, const uint8_t*); | |||||
// read device's power requirements | |||||
bool readPowerSupply(const uint8_t* deviceAddress = nullptr); | |||||
// get global resolution | |||||
uint8_t getResolution(); | |||||
// set global resolution to 9, 10, 11, or 12 bits | |||||
void setResolution(uint8_t); | |||||
// returns the device resolution: 9, 10, 11, or 12 bits | |||||
uint8_t getResolution(const uint8_t*); | |||||
// set resolution of a device to 9, 10, 11, or 12 bits | |||||
bool setResolution(const uint8_t*, uint8_t, | |||||
bool skipGlobalBitResolutionCalculation = false); | |||||
// sets/gets the waitForConversion flag | |||||
void setWaitForConversion(bool); | |||||
bool getWaitForConversion(void); | |||||
// sets/gets the checkForConversion flag | |||||
void setCheckForConversion(bool); | |||||
bool getCheckForConversion(void); | |||||
// sends command for all devices on the bus to perform a temperature conversion | |||||
void requestTemperatures(void); | |||||
// sends command for one device to perform a temperature conversion by address | |||||
bool requestTemperaturesByAddress(const uint8_t*); | |||||
// sends command for one device to perform a temperature conversion by index | |||||
bool requestTemperaturesByIndex(uint8_t); | |||||
// returns temperature raw value (12 bit integer of 1/128 degrees C) | |||||
int16_t getTemp(const uint8_t*); | |||||
// returns temperature in degrees C | |||||
float getTempC(const uint8_t*); | |||||
// returns temperature in degrees F | |||||
float getTempF(const uint8_t*); | |||||
// Get temperature for device index (slow) | |||||
float getTempCByIndex(uint8_t); | |||||
// Get temperature for device index (slow) | |||||
float getTempFByIndex(uint8_t); | |||||
// returns true if the bus requires parasite power | |||||
bool isParasitePowerMode(void); | |||||
// Is a conversion complete on the wire? Only applies to the first sensor on the wire. | |||||
bool isConversionComplete(void); | |||||
int16_t millisToWaitForConversion(uint8_t); | |||||
#if REQUIRESALARMS | |||||
typedef void AlarmHandler(const uint8_t*); | |||||
// sets the high alarm temperature for a device | |||||
// accepts a int8_t. valid range is -55C - 125C | |||||
void setHighAlarmTemp(const uint8_t*, int8_t); | |||||
// sets the low alarm temperature for a device | |||||
// accepts a int8_t. valid range is -55C - 125C | |||||
void setLowAlarmTemp(const uint8_t*, int8_t); | |||||
// returns a int8_t with the current high alarm temperature for a device | |||||
// in the range -55C - 125C | |||||
int8_t getHighAlarmTemp(const uint8_t*); | |||||
// returns a int8_t with the current low alarm temperature for a device | |||||
// in the range -55C - 125C | |||||
int8_t getLowAlarmTemp(const uint8_t*); | |||||
// resets internal variables used for the alarm search | |||||
void resetAlarmSearch(void); | |||||
// search the wire for devices with active alarms | |||||
bool alarmSearch(uint8_t*); | |||||
// returns true if ia specific device has an alarm | |||||
bool hasAlarm(const uint8_t*); | |||||
// returns true if any device is reporting an alarm on the bus | |||||
bool hasAlarm(void); | |||||
// runs the alarm handler for all devices returned by alarmSearch() | |||||
void processAlarms(void); | |||||
// sets the alarm handler | |||||
void setAlarmHandler(const AlarmHandler *); | |||||
// returns true if an AlarmHandler has been set | |||||
bool hasAlarmHandler(); | |||||
#endif | |||||
// if no alarm handler is used the two bytes can be used as user data | |||||
// example of such usage is an ID. | |||||
// note if device is not connected it will fail writing the data. | |||||
// note if address cannot be found no error will be reported. | |||||
// in short use carefully | |||||
void setUserData(const uint8_t*, int16_t); | |||||
void setUserDataByIndex(uint8_t, int16_t); | |||||
int16_t getUserData(const uint8_t*); | |||||
int16_t getUserDataByIndex(uint8_t); | |||||
// convert from Celsius to Fahrenheit | |||||
static float toFahrenheit(float); | |||||
// convert from Fahrenheit to Celsius | |||||
static float toCelsius(float); | |||||
// convert from raw to Celsius | |||||
static float rawToCelsius(int16_t); | |||||
// convert from raw to Fahrenheit | |||||
static float rawToFahrenheit(int16_t); | |||||
#if REQUIRESNEW | |||||
// initialize memory area | |||||
void* operator new (unsigned int); | |||||
// delete memory reference | |||||
void operator delete(void*); | |||||
#endif | |||||
private: | |||||
typedef uint8_t ScratchPad[9]; | |||||
// parasite power on or off | |||||
bool parasite; | |||||
// external pullup | |||||
bool useExternalPullup; | |||||
uint8_t pullupPin; | |||||
// used to determine the delay amount needed to allow for the | |||||
// temperature conversion to take place | |||||
uint8_t bitResolution; | |||||
// used to requestTemperature with or without delay | |||||
bool waitForConversion; | |||||
// used to requestTemperature to dynamically check if a conversion is complete | |||||
bool checkForConversion; | |||||
// count of devices on the bus | |||||
uint8_t devices; | |||||
// count of DS18xxx Family devices on bus | |||||
uint8_t ds18Count; | |||||
// Take a pointer to one wire instance | |||||
OneWire* _wire; | |||||
// reads scratchpad and returns the raw temperature | |||||
int16_t calculateTemperature(const uint8_t*, uint8_t*); | |||||
void blockTillConversionComplete(uint8_t); | |||||
// Returns true if all bytes of scratchPad are '\0' | |||||
bool isAllZeros(const uint8_t* const scratchPad, const size_t length = 9); | |||||
// External pullup control | |||||
void activateExternalPullup(void); | |||||
void deactivateExternalPullup(void); | |||||
#if REQUIRESALARMS | |||||
// required for alarmSearch | |||||
uint8_t alarmSearchAddress[8]; | |||||
int8_t alarmSearchJunction; | |||||
uint8_t alarmSearchExhausted; | |||||
// the alarm handler function pointer | |||||
AlarmHandler *_AlarmHandler; | |||||
#endif | |||||
}; | |||||
#endif |
@@ -1,72 +0,0 @@ | |||||
# Arduino Library for Maxim Temperature Integrated Circuits | |||||
## Usage | |||||
This library supports the following devices : | |||||
* DS18B20 | |||||
* DS18S20 - Please note there appears to be an issue with this series. | |||||
* DS1822 | |||||
* DS1820 | |||||
* MAX31820 | |||||
You will need a pull-up resistor of about 5 KOhm between the 1-Wire data line | |||||
and your 5V power. If you are using the DS18B20, ground pins 1 and 3. The | |||||
centre pin is the data line '1-wire'. | |||||
In case of temperature conversion problems (result is `-85`), strong pull-up setup may be necessary. See section | |||||
_Powering the DS18B20_ in | |||||
[DS18B20 datasheet](https://datasheets.maximintegrated.com/en/ds/DS18B20.pdf) (page 7) | |||||
and use `DallasTemperature(OneWire*, uint8_t)` constructor. | |||||
We have included a "REQUIRESNEW" and "REQUIRESALARMS" definition. If you | |||||
want to slim down the code feel free to use either of these by including | |||||
#define REQUIRESNEW | |||||
or | |||||
#define REQUIRESALARMS | |||||
at the top of DallasTemperature.h | |||||
Finally, please include OneWire from Paul Stoffregen in the library manager before you begin. | |||||
## Credits | |||||
The OneWire code has been derived from | |||||
http://www.arduino.cc/playground/Learning/OneWire. | |||||
Miles Burton <miles@mnetcs.com> originally developed this library. | |||||
Tim Newsome <nuisance@casualhacker.net> added support for multiple sensors on | |||||
the same bus. | |||||
Guil Barros [gfbarros@bappos.com] added getTempByAddress (v3.5) | |||||
Note: these are implemented as getTempC(address) and getTempF(address) | |||||
Rob Tillaart [rob.tillaart@gmail.com] added async modus (v3.7.0) | |||||
## Website | |||||
You can find the latest version of the library at | |||||
https://www.milesburton.com/Dallas_Temperature_Control_Library | |||||
# License | |||||
This library is free software; you can redistribute it and/or | |||||
modify it under the terms of the GNU Lesser General Public | |||||
License as published by the Free Software Foundation; either | |||||
version 2.1 of the License, or (at your option) any later version. | |||||
This library is distributed in the hope that it will be useful, | |||||
but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||||
Lesser General Public License for more details. | |||||
You should have received a copy of the GNU Lesser General Public | |||||
License along with this library; if not, write to the Free Software | |||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
@@ -1,162 +0,0 @@ | |||||
#include <OneWire.h> | |||||
#include <DallasTemperature.h> | |||||
// Data wire is plugged into port 2 on the Arduino | |||||
#define ONE_WIRE_BUS 2 | |||||
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) | |||||
OneWire oneWire(ONE_WIRE_BUS); | |||||
// Pass our oneWire reference to Dallas Temperature. | |||||
DallasTemperature sensors(&oneWire); | |||||
// arrays to hold device addresses | |||||
DeviceAddress insideThermometer, outsideThermometer; | |||||
void setup(void) | |||||
{ | |||||
// start serial port | |||||
Serial.begin(9600); | |||||
Serial.println("Dallas Temperature IC Control Library Demo"); | |||||
// Start up the library | |||||
sensors.begin(); | |||||
// locate devices on the bus | |||||
Serial.print("Found "); | |||||
Serial.print(sensors.getDeviceCount(), DEC); | |||||
Serial.println(" devices."); | |||||
// search for devices on the bus and assign based on an index. | |||||
if (!sensors.getAddress(insideThermometer, 0)) Serial.println("Unable to find address for Device 0"); | |||||
if (!sensors.getAddress(outsideThermometer, 1)) Serial.println("Unable to find address for Device 1"); | |||||
// show the addresses we found on the bus | |||||
Serial.print("Device 0 Address: "); | |||||
printAddress(insideThermometer); | |||||
Serial.println(); | |||||
Serial.print("Device 0 Alarms: "); | |||||
printAlarms(insideThermometer); | |||||
Serial.println(); | |||||
Serial.print("Device 1 Address: "); | |||||
printAddress(outsideThermometer); | |||||
Serial.println(); | |||||
Serial.print("Device 1 Alarms: "); | |||||
printAlarms(outsideThermometer); | |||||
Serial.println(); | |||||
Serial.println("Setting alarm temps..."); | |||||
// alarm when temp is higher than 30C | |||||
sensors.setHighAlarmTemp(insideThermometer, 30); | |||||
// alarm when temp is lower than -10C | |||||
sensors.setLowAlarmTemp(insideThermometer, -10); | |||||
// alarm when temp is higher than 31C | |||||
sensors.setHighAlarmTemp(outsideThermometer, 31); | |||||
// alarn when temp is lower than 27C | |||||
sensors.setLowAlarmTemp(outsideThermometer, 27); | |||||
Serial.print("New Device 0 Alarms: "); | |||||
printAlarms(insideThermometer); | |||||
Serial.println(); | |||||
Serial.print("New Device 1 Alarms: "); | |||||
printAlarms(outsideThermometer); | |||||
Serial.println(); | |||||
} | |||||
// function to print a device address | |||||
void printAddress(DeviceAddress deviceAddress) | |||||
{ | |||||
for (uint8_t i = 0; i < 8; i++) | |||||
{ | |||||
if (deviceAddress[i] < 16) Serial.print("0"); | |||||
Serial.print(deviceAddress[i], HEX); | |||||
} | |||||
} | |||||
// function to print the temperature for a device | |||||
void printTemperature(DeviceAddress deviceAddress) | |||||
{ | |||||
float tempC = sensors.getTempC(deviceAddress); | |||||
Serial.print("Temp C: "); | |||||
Serial.print(tempC); | |||||
Serial.print(" Temp F: "); | |||||
Serial.print(DallasTemperature::toFahrenheit(tempC)); | |||||
} | |||||
void printAlarms(uint8_t deviceAddress[]) | |||||
{ | |||||
char temp; | |||||
temp = sensors.getHighAlarmTemp(deviceAddress); | |||||
Serial.print("High Alarm: "); | |||||
Serial.print(temp, DEC); | |||||
Serial.print("C/"); | |||||
Serial.print(DallasTemperature::toFahrenheit(temp)); | |||||
Serial.print("F | Low Alarm: "); | |||||
temp = sensors.getLowAlarmTemp(deviceAddress); | |||||
Serial.print(temp, DEC); | |||||
Serial.print("C/"); | |||||
Serial.print(DallasTemperature::toFahrenheit(temp)); | |||||
Serial.print("F"); | |||||
} | |||||
// main function to print information about a device | |||||
void printData(DeviceAddress deviceAddress) | |||||
{ | |||||
Serial.print("Device Address: "); | |||||
printAddress(deviceAddress); | |||||
Serial.print(" "); | |||||
printTemperature(deviceAddress); | |||||
Serial.println(); | |||||
} | |||||
void checkAlarm(DeviceAddress deviceAddress) | |||||
{ | |||||
if (sensors.hasAlarm(deviceAddress)) | |||||
{ | |||||
Serial.print("ALARM: "); | |||||
printData(deviceAddress); | |||||
} | |||||
} | |||||
void loop(void) | |||||
{ | |||||
// call sensors.requestTemperatures() to issue a global temperature | |||||
// request to all devices on the bus | |||||
Serial.print("Requesting temperatures..."); | |||||
sensors.requestTemperatures(); | |||||
Serial.println("DONE"); | |||||
// Method 1: | |||||
// check each address individually for an alarm condition | |||||
checkAlarm(insideThermometer); | |||||
checkAlarm(outsideThermometer); | |||||
/* | |||||
// Alternate method: | |||||
// Search the bus and iterate through addresses of devices with alarms | |||||
// space for the alarm device's address | |||||
DeviceAddress alarmAddr; | |||||
Serial.println("Searching for alarms..."); | |||||
// resetAlarmSearch() must be called before calling alarmSearch() | |||||
sensors.resetAlarmSearch(); | |||||
// alarmSearch() returns 0 when there are no devices with alarms | |||||
while (sensors.alarmSearch(alarmAddr)) | |||||
{ | |||||
Serial.print("ALARM: "); | |||||
printData(alarmAddr); | |||||
} | |||||
*/ | |||||
} | |||||
@@ -1,144 +0,0 @@ | |||||
#include <OneWire.h> | |||||
#include <DallasTemperature.h> | |||||
// Data wire is plugged into port 2 on the Arduino | |||||
#define ONE_WIRE_BUS 2 | |||||
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) | |||||
OneWire oneWire(ONE_WIRE_BUS); | |||||
// Pass our oneWire reference to Dallas Temperature. | |||||
DallasTemperature sensors(&oneWire); | |||||
// arrays to hold device addresses | |||||
DeviceAddress insideThermometer, outsideThermometer; | |||||
// function that will be called when an alarm condition exists during DallasTemperatures::processAlarms(); | |||||
void newAlarmHandler(uint8_t* deviceAddress) | |||||
{ | |||||
Serial.println("Alarm Handler Start"); | |||||
printAlarmInfo(deviceAddress); | |||||
printTemp(deviceAddress); | |||||
Serial.println(); | |||||
Serial.println("Alarm Handler Finish"); | |||||
} | |||||
void printCurrentTemp(DeviceAddress deviceAddress) | |||||
{ | |||||
printAddress(deviceAddress); | |||||
printTemp(deviceAddress); | |||||
Serial.println(); | |||||
} | |||||
void printAddress(DeviceAddress deviceAddress) | |||||
{ | |||||
Serial.print("Address: "); | |||||
for (uint8_t i = 0; i < 8; i++) | |||||
{ | |||||
if (deviceAddress[i] < 16) Serial.print("0"); | |||||
Serial.print(deviceAddress[i], HEX); | |||||
} | |||||
Serial.print(" "); | |||||
} | |||||
void printTemp(DeviceAddress deviceAddress) | |||||
{ | |||||
float tempC = sensors.getTempC(deviceAddress); | |||||
if (tempC != DEVICE_DISCONNECTED_C) | |||||
{ | |||||
Serial.print("Current Temp C: "); | |||||
Serial.print(tempC); | |||||
} | |||||
else Serial.print("DEVICE DISCONNECTED"); | |||||
Serial.print(" "); | |||||
} | |||||
void printAlarmInfo(DeviceAddress deviceAddress) | |||||
{ | |||||
char temp; | |||||
printAddress(deviceAddress); | |||||
temp = sensors.getHighAlarmTemp(deviceAddress); | |||||
Serial.print("High Alarm: "); | |||||
Serial.print(temp, DEC); | |||||
Serial.print("C"); | |||||
Serial.print(" Low Alarm: "); | |||||
temp = sensors.getLowAlarmTemp(deviceAddress); | |||||
Serial.print(temp, DEC); | |||||
Serial.print("C"); | |||||
Serial.print(" "); | |||||
} | |||||
void setup(void) | |||||
{ | |||||
// start serial port | |||||
Serial.begin(9600); | |||||
Serial.println("Dallas Temperature IC Control Library Demo"); | |||||
// Start up the library | |||||
sensors.begin(); | |||||
// locate devices on the bus | |||||
Serial.print("Found "); | |||||
Serial.print(sensors.getDeviceCount(), DEC); | |||||
Serial.println(" devices."); | |||||
// search for devices on the bus and assign based on an index | |||||
if (!sensors.getAddress(insideThermometer, 0)) Serial.println("Unable to find address for Device 0"); | |||||
if (!sensors.getAddress(outsideThermometer, 1)) Serial.println("Unable to find address for Device 1"); | |||||
Serial.print("Device insideThermometer "); | |||||
printAlarmInfo(insideThermometer); | |||||
Serial.println(); | |||||
Serial.print("Device outsideThermometer "); | |||||
printAlarmInfo(outsideThermometer); | |||||
Serial.println(); | |||||
// set alarm ranges | |||||
Serial.println("Setting alarm temps..."); | |||||
sensors.setHighAlarmTemp(insideThermometer, 26); | |||||
sensors.setLowAlarmTemp(insideThermometer, 22); | |||||
sensors.setHighAlarmTemp(outsideThermometer, 25); | |||||
sensors.setLowAlarmTemp(outsideThermometer, 21); | |||||
Serial.print("New insideThermometer "); | |||||
printAlarmInfo(insideThermometer); | |||||
Serial.println(); | |||||
Serial.print("New outsideThermometer "); | |||||
printAlarmInfo(outsideThermometer); | |||||
Serial.println(); | |||||
// attach alarm handler | |||||
sensors.setAlarmHandler(&newAlarmHandler); | |||||
} | |||||
void loop(void) | |||||
{ | |||||
// ask the devices to measure the temperature | |||||
sensors.requestTemperatures(); | |||||
// if an alarm condition exists as a result of the most recent | |||||
// requestTemperatures() request, it exists until the next time | |||||
// requestTemperatures() is called AND there isn't an alarm condition | |||||
// on the device | |||||
if (sensors.hasAlarm()) | |||||
{ | |||||
Serial.println("Oh noes! There is at least one alarm on the bus."); | |||||
} | |||||
// call alarm handler function defined by sensors.setAlarmHandler | |||||
// for each device reporting an alarm | |||||
sensors.processAlarms(); | |||||
if (!sensors.hasAlarm()) | |||||
{ | |||||
// just print out the current temperature | |||||
printCurrentTemp(insideThermometer); | |||||
printCurrentTemp(outsideThermometer); | |||||
} | |||||
delay(1000); | |||||
} | |||||
@@ -1,35 +0,0 @@ | |||||
#include <OneWire.h> | |||||
#include <DallasTemperature.h> | |||||
// Data wire is plugged into port 2 on the Arduino, while external pullup P-MOSFET gate into port 3 | |||||
#define ONE_WIRE_BUS 2 | |||||
#define ONE_WIRE_PULLUP 3 | |||||
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) | |||||
OneWire oneWire(ONE_WIRE_BUS); | |||||
// Pass our oneWire reference to Dallas Temperature. | |||||
DallasTemperature sensors(&oneWire, ONE_WIRE_PULLUP); | |||||
void setup(void) | |||||
{ | |||||
// start serial port | |||||
Serial.begin(9600); | |||||
Serial.println("Dallas Temperature IC Control Library Demo"); | |||||
// Start up the library | |||||
sensors.begin(); | |||||
} | |||||
void loop(void) | |||||
{ | |||||
// call sensors.requestTemperatures() to issue a global temperature | |||||
// request to all devices on the bus | |||||
Serial.print("Requesting temperatures..."); | |||||
sensors.requestTemperatures(); // Send the command to get temperatures | |||||
Serial.println("DONE"); | |||||
for(int i=0;i<sensors.getDeviceCount();i++) { | |||||
Serial.println("Temperature for Device "+String(i)+" is: " + String(sensors.getTempCByIndex(i))); | |||||
} | |||||
} |
@@ -1,43 +0,0 @@ | |||||
#include <OneWire.h> | |||||
#include <DallasTemperature.h> | |||||
OneWire ds18x20[] = { 3, 7 }; | |||||
const int oneWireCount = sizeof(ds18x20)/sizeof(OneWire); | |||||
DallasTemperature sensor[oneWireCount]; | |||||
void setup(void) { | |||||
// start serial port | |||||
Serial.begin(9600); | |||||
Serial.println("Dallas Temperature Multiple Bus Control Library Simple Demo"); | |||||
Serial.print("============Ready with "); | |||||
Serial.print(oneWireCount); | |||||
Serial.println(" Sensors================"); | |||||
// Start up the library on all defined bus-wires | |||||
DeviceAddress deviceAddress; | |||||
for (int i = 0; i < oneWireCount; i++) {; | |||||
sensor[i].setOneWire(&ds18x20[i]); | |||||
sensor[i].begin(); | |||||
if (sensor[i].getAddress(deviceAddress, 0)) sensor[i].setResolution(deviceAddress, 12); | |||||
} | |||||
} | |||||
void loop(void) { | |||||
// call sensors.requestTemperatures() to issue a global temperature | |||||
// request to all devices on the bus | |||||
Serial.print("Requesting temperatures..."); | |||||
for (int i = 0; i < oneWireCount; i++) { | |||||
sensor[i].requestTemperatures(); | |||||
} | |||||
Serial.println("DONE"); | |||||
delay(1000); | |||||
for (int i = 0; i < oneWireCount; i++) { | |||||
float temperature = sensor[i].getTempCByIndex(0); | |||||
Serial.print("Temperature for the sensor "); | |||||
Serial.print(i); | |||||
Serial.print(" is "); | |||||
Serial.println(temperature); | |||||
} | |||||
Serial.println(); | |||||
} |
@@ -1,148 +0,0 @@ | |||||
// Include the libraries we need | |||||
#include <OneWire.h> | |||||
#include <DallasTemperature.h> | |||||
// Data wire is plugged into port 2 on the Arduino | |||||
#define ONE_WIRE_BUS 2 | |||||
#define TEMPERATURE_PRECISION 9 | |||||
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) | |||||
OneWire oneWire(ONE_WIRE_BUS); | |||||
// Pass our oneWire reference to Dallas Temperature. | |||||
DallasTemperature sensors(&oneWire); | |||||
// arrays to hold device addresses | |||||
DeviceAddress insideThermometer, outsideThermometer; | |||||
// Assign address manually. The addresses below will beed to be changed | |||||
// to valid device addresses on your bus. Device address can be retrieved | |||||
// by using either oneWire.search(deviceAddress) or individually via | |||||
// sensors.getAddress(deviceAddress, index) | |||||
// DeviceAddress insideThermometer = { 0x28, 0x1D, 0x39, 0x31, 0x2, 0x0, 0x0, 0xF0 }; | |||||
// DeviceAddress outsideThermometer = { 0x28, 0x3F, 0x1C, 0x31, 0x2, 0x0, 0x0, 0x2 }; | |||||
void setup(void) | |||||
{ | |||||
// start serial port | |||||
Serial.begin(9600); | |||||
Serial.println("Dallas Temperature IC Control Library Demo"); | |||||
// Start up the library | |||||
sensors.begin(); | |||||
// locate devices on the bus | |||||
Serial.print("Locating devices..."); | |||||
Serial.print("Found "); | |||||
Serial.print(sensors.getDeviceCount(), DEC); | |||||
Serial.println(" devices."); | |||||
// report parasite power requirements | |||||
Serial.print("Parasite power is: "); | |||||
if (sensors.isParasitePowerMode()) Serial.println("ON"); | |||||
else Serial.println("OFF"); | |||||
// Search for devices on the bus and assign based on an index. Ideally, | |||||
// you would do this to initially discover addresses on the bus and then | |||||
// use those addresses and manually assign them (see above) once you know | |||||
// the devices on your bus (and assuming they don't change). | |||||
// | |||||
// method 1: by index | |||||
if (!sensors.getAddress(insideThermometer, 0)) Serial.println("Unable to find address for Device 0"); | |||||
if (!sensors.getAddress(outsideThermometer, 1)) Serial.println("Unable to find address for Device 1"); | |||||
// method 2: search() | |||||
// search() looks for the next device. Returns 1 if a new address has been | |||||
// returned. A zero might mean that the bus is shorted, there are no devices, | |||||
// or you have already retrieved all of them. It might be a good idea to | |||||
// check the CRC to make sure you didn't get garbage. The order is | |||||
// deterministic. You will always get the same devices in the same order | |||||
// | |||||
// Must be called before search() | |||||
//oneWire.reset_search(); | |||||
// assigns the first address found to insideThermometer | |||||
//if (!oneWire.search(insideThermometer)) Serial.println("Unable to find address for insideThermometer"); | |||||
// assigns the seconds address found to outsideThermometer | |||||
//if (!oneWire.search(outsideThermometer)) Serial.println("Unable to find address for outsideThermometer"); | |||||
// show the addresses we found on the bus | |||||
Serial.print("Device 0 Address: "); | |||||
printAddress(insideThermometer); | |||||
Serial.println(); | |||||
Serial.print("Device 1 Address: "); | |||||
printAddress(outsideThermometer); | |||||
Serial.println(); | |||||
// set the resolution to 9 bit per device | |||||
sensors.setResolution(insideThermometer, TEMPERATURE_PRECISION); | |||||
sensors.setResolution(outsideThermometer, TEMPERATURE_PRECISION); | |||||
Serial.print("Device 0 Resolution: "); | |||||
Serial.print(sensors.getResolution(insideThermometer), DEC); | |||||
Serial.println(); | |||||
Serial.print("Device 1 Resolution: "); | |||||
Serial.print(sensors.getResolution(outsideThermometer), DEC); | |||||
Serial.println(); | |||||
} | |||||
// function to print a device address | |||||
void printAddress(DeviceAddress deviceAddress) | |||||
{ | |||||
for (uint8_t i = 0; i < 8; i++) | |||||
{ | |||||
// zero pad the address if necessary | |||||
if (deviceAddress[i] < 16) Serial.print("0"); | |||||
Serial.print(deviceAddress[i], HEX); | |||||
} | |||||
} | |||||
// function to print the temperature for a device | |||||
void printTemperature(DeviceAddress deviceAddress) | |||||
{ | |||||
float tempC = sensors.getTempC(deviceAddress); | |||||
if(tempC == DEVICE_DISCONNECTED_C) | |||||
{ | |||||
Serial.println("Error: Could not read temperature data"); | |||||
return; | |||||
} | |||||
Serial.print("Temp C: "); | |||||
Serial.print(tempC); | |||||
Serial.print(" Temp F: "); | |||||
Serial.print(DallasTemperature::toFahrenheit(tempC)); | |||||
} | |||||
// function to print a device's resolution | |||||
void printResolution(DeviceAddress deviceAddress) | |||||
{ | |||||
Serial.print("Resolution: "); | |||||
Serial.print(sensors.getResolution(deviceAddress)); | |||||
Serial.println(); | |||||
} | |||||
// main function to print information about a device | |||||
void printData(DeviceAddress deviceAddress) | |||||
{ | |||||
Serial.print("Device Address: "); | |||||
printAddress(deviceAddress); | |||||
Serial.print(" "); | |||||
printTemperature(deviceAddress); | |||||
Serial.println(); | |||||
} | |||||
/* | |||||
Main function, calls the temperatures in a loop. | |||||
*/ | |||||
void loop(void) | |||||
{ | |||||
// call sensors.requestTemperatures() to issue a global temperature | |||||
// request to all devices on the bus | |||||
Serial.print("Requesting temperatures..."); | |||||
sensors.requestTemperatures(); | |||||
Serial.println("DONE"); | |||||
// print the device information | |||||
printData(insideThermometer); | |||||
printData(outsideThermometer); | |||||
} |
@@ -1,47 +0,0 @@ | |||||
// | |||||
// This sketch does not use the ALARM registers and uses those 2 bytes as a counter | |||||
// these 2 bytes can be used for other purposes as well e.g. last temperature or | |||||
// a specific ID. | |||||
// | |||||
#include <OneWire.h> | |||||
#include <DallasTemperature.h> | |||||
// Data wire is plugged into port 2 on the Arduino | |||||
#define ONE_WIRE_BUS 2 | |||||
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) | |||||
OneWire oneWire(ONE_WIRE_BUS); | |||||
// Pass our oneWire reference to Dallas Temperature. | |||||
DallasTemperature sensors(&oneWire); | |||||
int count = 0; | |||||
void setup(void) | |||||
{ | |||||
// start serial port | |||||
Serial.begin(9600); | |||||
Serial.println("Dallas Temperature IC Control Library Demo"); | |||||
// Start up the library | |||||
sensors.begin(); | |||||
} | |||||
void loop(void) | |||||
{ | |||||
// call sensors.requestTemperatures() to issue a global temperature | |||||
// request to all devices on the bus | |||||
Serial.print("Requesting temperatures..."); | |||||
sensors.requestTemperatures(); // Send the command to get temperatures | |||||
Serial.println("DONE"); | |||||
Serial.print("Temperature for the device 1 (index 0) is: "); | |||||
Serial.println(sensors.getTempCByIndex(0)); | |||||
count++; | |||||
sensors.setUserDataByIndex(0, count); | |||||
int x = sensors.getUserDataByIndex(0); | |||||
Serial.println(count); | |||||
} |
@@ -1,51 +0,0 @@ | |||||
// Include the libraries we need | |||||
#include <OneWire.h> | |||||
#include <DallasTemperature.h> | |||||
// Data wire is plugged into port 2 on the Arduino | |||||
#define ONE_WIRE_BUS 2 | |||||
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) | |||||
OneWire oneWire(ONE_WIRE_BUS); | |||||
// Pass our oneWire reference to Dallas Temperature. | |||||
DallasTemperature sensors(&oneWire); | |||||
/* | |||||
* The setup function. We only start the sensors here | |||||
*/ | |||||
void setup(void) | |||||
{ | |||||
// start serial port | |||||
Serial.begin(9600); | |||||
Serial.println("Dallas Temperature IC Control Library Demo"); | |||||
// Start up the library | |||||
sensors.begin(); | |||||
} | |||||
/* | |||||
* Main function, get and show the temperature | |||||
*/ | |||||
void loop(void) | |||||
{ | |||||
// call sensors.requestTemperatures() to issue a global temperature | |||||
// request to all devices on the bus | |||||
Serial.print("Requesting temperatures..."); | |||||
sensors.requestTemperatures(); // Send the command to get temperatures | |||||
Serial.println("DONE"); | |||||
// After we got the temperatures, we can print them here. | |||||
// We use the function ByIndex, and as an example get the temperature from the first sensor only. | |||||
float tempC = sensors.getTempCByIndex(0); | |||||
// Check if reading was successful | |||||
if(tempC != DEVICE_DISCONNECTED_C) | |||||
{ | |||||
Serial.print("Temperature for the device 1 (index 0) is: "); | |||||
Serial.println(tempC); | |||||
} | |||||
else | |||||
{ | |||||
Serial.println("Error: Could not read temperature data"); | |||||
} | |||||
} |
@@ -1,121 +0,0 @@ | |||||
// Include the libraries we need | |||||
#include <OneWire.h> | |||||
#include <DallasTemperature.h> | |||||
// Data wire is plugged into port 2 on the Arduino | |||||
#define ONE_WIRE_BUS 2 | |||||
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) | |||||
OneWire oneWire(ONE_WIRE_BUS); | |||||
// Pass our oneWire reference to Dallas Temperature. | |||||
DallasTemperature sensors(&oneWire); | |||||
// arrays to hold device address | |||||
DeviceAddress insideThermometer; | |||||
/* | |||||
* Setup function. Here we do the basics | |||||
*/ | |||||
void setup(void) | |||||
{ | |||||
// start serial port | |||||
Serial.begin(9600); | |||||
Serial.println("Dallas Temperature IC Control Library Demo"); | |||||
// locate devices on the bus | |||||
Serial.print("Locating devices..."); | |||||
sensors.begin(); | |||||
Serial.print("Found "); | |||||
Serial.print(sensors.getDeviceCount(), DEC); | |||||
Serial.println(" devices."); | |||||
// report parasite power requirements | |||||
Serial.print("Parasite power is: "); | |||||
if (sensors.isParasitePowerMode()) Serial.println("ON"); | |||||
else Serial.println("OFF"); | |||||
// Assign address manually. The addresses below will beed to be changed | |||||
// to valid device addresses on your bus. Device address can be retrieved | |||||
// by using either oneWire.search(deviceAddress) or individually via | |||||
// sensors.getAddress(deviceAddress, index) | |||||
// Note that you will need to use your specific address here | |||||
//insideThermometer = { 0x28, 0x1D, 0x39, 0x31, 0x2, 0x0, 0x0, 0xF0 }; | |||||
// Method 1: | |||||
// Search for devices on the bus and assign based on an index. Ideally, | |||||
// you would do this to initially discover addresses on the bus and then | |||||
// use those addresses and manually assign them (see above) once you know | |||||
// the devices on your bus (and assuming they don't change). | |||||
if (!sensors.getAddress(insideThermometer, 0)) Serial.println("Unable to find address for Device 0"); | |||||
// method 2: search() | |||||
// search() looks for the next device. Returns 1 if a new address has been | |||||
// returned. A zero might mean that the bus is shorted, there are no devices, | |||||
// or you have already retrieved all of them. It might be a good idea to | |||||
// check the CRC to make sure you didn't get garbage. The order is | |||||
// deterministic. You will always get the same devices in the same order | |||||
// | |||||
// Must be called before search() | |||||
//oneWire.reset_search(); | |||||
// assigns the first address found to insideThermometer | |||||
//if (!oneWire.search(insideThermometer)) Serial.println("Unable to find address for insideThermometer"); | |||||
// show the addresses we found on the bus | |||||
Serial.print("Device 0 Address: "); | |||||
printAddress(insideThermometer); | |||||
Serial.println(); | |||||
// set the resolution to 9 bit (Each Dallas/Maxim device is capable of several different resolutions) | |||||
sensors.setResolution(insideThermometer, 9); | |||||
Serial.print("Device 0 Resolution: "); | |||||
Serial.print(sensors.getResolution(insideThermometer), DEC); | |||||
Serial.println(); | |||||
} | |||||
// function to print the temperature for a device | |||||
void printTemperature(DeviceAddress deviceAddress) | |||||
{ | |||||
// method 1 - slower | |||||
//Serial.print("Temp C: "); | |||||
//Serial.print(sensors.getTempC(deviceAddress)); | |||||
//Serial.print(" Temp F: "); | |||||
//Serial.print(sensors.getTempF(deviceAddress)); // Makes a second call to getTempC and then converts to Fahrenheit | |||||
// method 2 - faster | |||||
float tempC = sensors.getTempC(deviceAddress); | |||||
if(tempC == DEVICE_DISCONNECTED_C) | |||||
{ | |||||
Serial.println("Error: Could not read temperature data"); | |||||
return; | |||||
} | |||||
Serial.print("Temp C: "); | |||||
Serial.print(tempC); | |||||
Serial.print(" Temp F: "); | |||||
Serial.println(DallasTemperature::toFahrenheit(tempC)); // Converts tempC to Fahrenheit | |||||
} | |||||
/* | |||||
* Main function. It will request the tempC from the sensors and display on Serial. | |||||
*/ | |||||
void loop(void) | |||||
{ | |||||
// call sensors.requestTemperatures() to issue a global temperature | |||||
// request to all devices on the bus | |||||
Serial.print("Requesting temperatures..."); | |||||
sensors.requestTemperatures(); // Send the command to get temperatures | |||||
Serial.println("DONE"); | |||||
// It responds almost immediately. Let's print out the data | |||||
printTemperature(insideThermometer); // Use a simple function to print out the data | |||||
} | |||||
// function to print a device address | |||||
void printAddress(DeviceAddress deviceAddress) | |||||
{ | |||||
for (uint8_t i = 0; i < 8; i++) | |||||
{ | |||||
if (deviceAddress[i] < 16) Serial.print("0"); | |||||
Serial.print(deviceAddress[i], HEX); | |||||
} | |||||
} |
@@ -1,129 +0,0 @@ | |||||
#include <OneWire.h> | |||||
#include <DallasTemperature.h> | |||||
// Data wire is plugged into port 2 on the Arduino | |||||
#define ONE_WIRE_BUS 2 | |||||
#define TEMPERATURE_PRECISION 9 // Lower resolution | |||||
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) | |||||
OneWire oneWire(ONE_WIRE_BUS); | |||||
// Pass our oneWire reference to Dallas Temperature. | |||||
DallasTemperature sensors(&oneWire); | |||||
int numberOfDevices; // Number of temperature devices found | |||||
DeviceAddress tempDeviceAddress; // We'll use this variable to store a found device address | |||||
void setup(void) | |||||
{ | |||||
// start serial port | |||||
Serial.begin(9600); | |||||
Serial.println("Dallas Temperature IC Control Library Demo"); | |||||
// Start up the library | |||||
sensors.begin(); | |||||
// Grab a count of devices on the wire | |||||
numberOfDevices = sensors.getDeviceCount(); | |||||
// locate devices on the bus | |||||
Serial.print("Locating devices..."); | |||||
Serial.print("Found "); | |||||
Serial.print(numberOfDevices, DEC); | |||||
Serial.println(" devices."); | |||||
// report parasite power requirements | |||||
Serial.print("Parasite power is: "); | |||||
if (sensors.isParasitePowerMode()) Serial.println("ON"); | |||||
else Serial.println("OFF"); | |||||
// Loop through each device, print out address | |||||
for(int i=0;i<numberOfDevices; i++) | |||||
{ | |||||
// Search the wire for address | |||||
if(sensors.getAddress(tempDeviceAddress, i)) | |||||
{ | |||||
Serial.print("Found device "); | |||||
Serial.print(i, DEC); | |||||
Serial.print(" with address: "); | |||||
printAddress(tempDeviceAddress); | |||||
Serial.println(); | |||||
Serial.print("Setting resolution to "); | |||||
Serial.println(TEMPERATURE_PRECISION, DEC); | |||||
// set the resolution to TEMPERATURE_PRECISION bit (Each Dallas/Maxim device is capable of several different resolutions) | |||||
sensors.setResolution(tempDeviceAddress, TEMPERATURE_PRECISION); | |||||
Serial.print("Resolution actually set to: "); | |||||
Serial.print(sensors.getResolution(tempDeviceAddress), DEC); | |||||
Serial.println(); | |||||
}else{ | |||||
Serial.print("Found ghost device at "); | |||||
Serial.print(i, DEC); | |||||
Serial.print(" but could not detect address. Check power and cabling"); | |||||
} | |||||
} | |||||
} | |||||
// function to print the temperature for a device | |||||
void printTemperature(DeviceAddress deviceAddress) | |||||
{ | |||||
// method 1 - slower | |||||
//Serial.print("Temp C: "); | |||||
//Serial.print(sensors.getTempC(deviceAddress)); | |||||
//Serial.print(" Temp F: "); | |||||
//Serial.print(sensors.getTempF(deviceAddress)); // Makes a second call to getTempC and then converts to Fahrenheit | |||||
// method 2 - faster | |||||
float tempC = sensors.getTempC(deviceAddress); | |||||
if(tempC == DEVICE_DISCONNECTED_C) | |||||
{ | |||||
Serial.println("Error: Could not read temperature data"); | |||||
return; | |||||
} | |||||
Serial.print("Temp C: "); | |||||
Serial.print(tempC); | |||||
Serial.print(" Temp F: "); | |||||
Serial.println(DallasTemperature::toFahrenheit(tempC)); // Converts tempC to Fahrenheit | |||||
} | |||||
void loop(void) | |||||
{ | |||||
// call sensors.requestTemperatures() to issue a global temperature | |||||
// request to all devices on the bus | |||||
Serial.print("Requesting temperatures..."); | |||||
sensors.requestTemperatures(); // Send the command to get temperatures | |||||
Serial.println("DONE"); | |||||
// Loop through each device, print out temperature data | |||||
for(int i=0;i<numberOfDevices; i++) | |||||
{ | |||||
// Search the wire for address | |||||
if(sensors.getAddress(tempDeviceAddress, i)) | |||||
{ | |||||
// Output the device ID | |||||
Serial.print("Temperature for device: "); | |||||
Serial.println(i,DEC); | |||||
// It responds almost immediately. Let's print out the data | |||||
printTemperature(tempDeviceAddress); // Use a simple function to print out the data | |||||
} | |||||
//else ghost device! Check your power requirements and cabling | |||||
} | |||||
} | |||||
// function to print a device address | |||||
void printAddress(DeviceAddress deviceAddress) | |||||
{ | |||||
for (uint8_t i = 0; i < 8; i++) | |||||
{ | |||||
if (deviceAddress[i] < 16) Serial.print("0"); | |||||
Serial.print(deviceAddress[i], HEX); | |||||
} | |||||
} |
@@ -1,45 +0,0 @@ | |||||
// | |||||
// FILE: TwoPin_DS18B20.ino | |||||
// AUTHOR: Rob Tillaart | |||||
// VERSION: 0.1.00 | |||||
// PURPOSE: two pins for two sensors demo | |||||
// DATE: 2014-06-13 | |||||
// URL: http://forum.arduino.cc/index.php?topic=216835.msg1764333#msg1764333 | |||||
// | |||||
// Released to the public domain | |||||
// | |||||
#include <OneWire.h> | |||||
#include <DallasTemperature.h> | |||||
#define ONE_WIRE_BUS_1 2 | |||||
#define ONE_WIRE_BUS_2 4 | |||||
OneWire oneWire_in(ONE_WIRE_BUS_1); | |||||
OneWire oneWire_out(ONE_WIRE_BUS_2); | |||||
DallasTemperature sensor_inhouse(&oneWire_in); | |||||
DallasTemperature sensor_outhouse(&oneWire_out); | |||||
void setup(void) | |||||
{ | |||||
Serial.begin(9600); | |||||
Serial.println("Dallas Temperature Control Library Demo - TwoPin_DS18B20"); | |||||
sensor_inhouse.begin(); | |||||
sensor_outhouse.begin(); | |||||
} | |||||
void loop(void) | |||||
{ | |||||
Serial.print("Requesting temperatures..."); | |||||
sensor_inhouse.requestTemperatures(); | |||||
sensor_outhouse.requestTemperatures(); | |||||
Serial.println(" done"); | |||||
Serial.print("Inhouse: "); | |||||
Serial.println(sensor_inhouse.getTempCByIndex(0)); | |||||
Serial.print("Outhouse: "); | |||||
Serial.println(sensor_outhouse.getTempCByIndex(0)); | |||||
} |
@@ -1,115 +0,0 @@ | |||||
// | |||||
// FILE: UserDataDemo.ino | |||||
// AUTHOR: Rob Tillaart | |||||
// VERSION: 0.1.0 | |||||
// PURPOSE: use of alarm field as user identification demo | |||||
// DATE: 2019-12-23 | |||||
// URL: | |||||
// | |||||
// Released to the public domain | |||||
// | |||||
#include <OneWire.h> | |||||
#include <DallasTemperature.h> | |||||
#define ONE_WIRE_BUS 2 | |||||
OneWire oneWire(ONE_WIRE_BUS); | |||||
DallasTemperature sensors(&oneWire); | |||||
uint8_t deviceCount = 0; | |||||
// Add 4 prepared sensors to the bus | |||||
// use the UserDataWriteBatch demo to prepare 4 different labeled sensors | |||||
struct | |||||
{ | |||||
int id; | |||||
DeviceAddress addr; | |||||
} T[4]; | |||||
float getTempByID(int id) | |||||
{ | |||||
for (uint8_t index = 0; index < deviceCount; index++) | |||||
{ | |||||
if (T[index].id == id) | |||||
{ | |||||
return sensors.getTempC(T[index].addr); | |||||
} | |||||
} | |||||
return -999; | |||||
} | |||||
void printAddress(DeviceAddress deviceAddress) | |||||
{ | |||||
for (uint8_t i = 0; i < 8; i++) | |||||
{ | |||||
// zero pad the address if necessary | |||||
if (deviceAddress[i] < 16) Serial.print("0"); | |||||
Serial.print(deviceAddress[i], HEX); | |||||
} | |||||
} | |||||
void setup(void) | |||||
{ | |||||
Serial.begin(115200); | |||||
Serial.println(__FILE__); | |||||
Serial.println("Dallas Temperature Demo"); | |||||
sensors.begin(); | |||||
// count devices | |||||
deviceCount = sensors.getDeviceCount(); | |||||
Serial.print("#devices: "); | |||||
Serial.println(deviceCount); | |||||
// Read ID's per sensor | |||||
// and put them in T array | |||||
for (uint8_t index = 0; index < deviceCount; index++) | |||||
{ | |||||
// go through sensors | |||||
sensors.getAddress(T[index].addr, index); | |||||
T[index].id = sensors.getUserData(T[index].addr); | |||||
} | |||||
// Check all 4 sensors are set | |||||
for (uint8_t index = 0; index < deviceCount; index++) | |||||
{ | |||||
Serial.println(); | |||||
Serial.println(T[index].id); | |||||
printAddress(T[index].addr); | |||||
Serial.println(); | |||||
} | |||||
Serial.println(); | |||||
} | |||||
void loop(void) | |||||
{ | |||||
Serial.println(); | |||||
Serial.print(millis()); | |||||
Serial.println("\treq temp"); | |||||
sensors.requestTemperatures(); | |||||
Serial.print(millis()); | |||||
Serial.println("\tGet temp by address"); | |||||
for (int i = 0; i < 4; i++) | |||||
{ | |||||
Serial.print(millis()); | |||||
Serial.print("\t temp:\t"); | |||||
Serial.println(sensors.getTempC(T[i].addr)); | |||||
} | |||||
Serial.print(millis()); | |||||
Serial.println("\tGet temp by ID"); // assume ID = 0, 1, 2, 3 | |||||
for (int id = 0; id < 4; id++) | |||||
{ | |||||
Serial.print(millis()); | |||||
Serial.print("\t temp:\t"); | |||||
Serial.println(getTempByID(id)); | |||||
} | |||||
delay(1000); | |||||
} | |||||
// END OF FILE |
@@ -1,107 +0,0 @@ | |||||
// | |||||
// FILE: UserDataWriteBatch.ino | |||||
// AUTHOR: Rob Tillaart | |||||
// VERSION: 0.1.0 | |||||
// PURPOSE: use of alarm field as user identification demo | |||||
// DATE: 2019-12-23 | |||||
// URL: | |||||
// | |||||
// Released to the public domain | |||||
// | |||||
#include <OneWire.h> | |||||
#include <DallasTemperature.h> | |||||
#define ONE_WIRE_BUS 2 | |||||
OneWire oneWire(ONE_WIRE_BUS); | |||||
DallasTemperature sensors(&oneWire); | |||||
uint8_t deviceCount = 0; | |||||
void printAddress(DeviceAddress deviceAddress) | |||||
{ | |||||
for (uint8_t i = 0; i < 8; i++) | |||||
{ | |||||
// zero pad the address if necessary | |||||
if (deviceAddress[i] < 16) Serial.print("0"); | |||||
Serial.print(deviceAddress[i], HEX); | |||||
} | |||||
} | |||||
void setup(void) | |||||
{ | |||||
Serial.begin(115200); | |||||
Serial.println(__FILE__); | |||||
Serial.println("Write user ID to DS18B20\n"); | |||||
sensors.begin(); | |||||
// count devices | |||||
deviceCount = sensors.getDeviceCount(); | |||||
Serial.print("#devices: "); | |||||
Serial.println(deviceCount); | |||||
Serial.println(); | |||||
Serial.println("current ID's"); | |||||
for (uint8_t index = 0; index < deviceCount; index++) | |||||
{ | |||||
DeviceAddress t; | |||||
sensors.getAddress(t, index); | |||||
printAddress(t); | |||||
Serial.print("\t\tID: "); | |||||
int id = sensors.getUserData(t); | |||||
Serial.println(id); | |||||
} | |||||
Serial.println(); | |||||
Serial.print("Enter ID for batch: "); | |||||
int c = 0; | |||||
int id = 0; | |||||
while (c != '\n' && c != '\r') | |||||
{ | |||||
c = Serial.read(); | |||||
switch(c) | |||||
{ | |||||
case '0'...'9': | |||||
id *= 10; | |||||
id += (c - '0'); | |||||
break; | |||||
default: | |||||
break; | |||||
} | |||||
} | |||||
Serial.println(); | |||||
Serial.println(id); | |||||
Serial.println(); | |||||
Serial.println("Start labeling ..."); | |||||
for (uint8_t index = 0; index < deviceCount; index++) | |||||
{ | |||||
Serial.print("."); | |||||
DeviceAddress t; | |||||
sensors.getAddress(t, index); | |||||
sensors.setUserData(t, id); | |||||
} | |||||
Serial.println(); | |||||
Serial.println(); | |||||
Serial.println("Show results ..."); | |||||
for (uint8_t index = 0; index < deviceCount; index++) | |||||
{ | |||||
DeviceAddress t; | |||||
sensors.getAddress(t, index); | |||||
printAddress(t); | |||||
Serial.print("\t\tID: "); | |||||
int id = sensors.getUserData(t); | |||||
Serial.println(id); | |||||
} | |||||
Serial.println("Done ..."); | |||||
} | |||||
void loop(void) {} | |||||
// END OF FILE |
@@ -1,66 +0,0 @@ | |||||
#include <OneWire.h> | |||||
#include <DallasTemperature.h> | |||||
// Data wire is plugged into port 2 on the Arduino | |||||
#define ONE_WIRE_BUS 2 | |||||
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) | |||||
OneWire oneWire(ONE_WIRE_BUS); | |||||
// Pass our oneWire reference to Dallas Temperature. | |||||
DallasTemperature sensors(&oneWire); | |||||
void setup(void) | |||||
{ | |||||
// start serial port | |||||
Serial.begin(115200); | |||||
Serial.println("Dallas Temperature Control Library - Async Demo"); | |||||
Serial.println("\nDemo shows the difference in length of the call\n\n"); | |||||
// Start up the library | |||||
sensors.begin(); | |||||
} | |||||
void loop(void) | |||||
{ | |||||
// Request temperature conversion (traditional) | |||||
Serial.println("Before blocking requestForConversion"); | |||||
unsigned long start = millis(); | |||||
sensors.requestTemperatures(); | |||||
unsigned long stop = millis(); | |||||
Serial.println("After blocking requestForConversion"); | |||||
Serial.print("Time used: "); | |||||
Serial.println(stop - start); | |||||
// get temperature | |||||
Serial.print("Temperature: "); | |||||
Serial.println(sensors.getTempCByIndex(0)); | |||||
Serial.println("\n"); | |||||
// Request temperature conversion - non-blocking / async | |||||
Serial.println("Before NON-blocking/async requestForConversion"); | |||||
start = millis(); | |||||
sensors.setWaitForConversion(false); // makes it async | |||||
sensors.requestTemperatures(); | |||||
sensors.setWaitForConversion(true); | |||||
stop = millis(); | |||||
Serial.println("After NON-blocking/async requestForConversion"); | |||||
Serial.print("Time used: "); | |||||
Serial.println(stop - start); | |||||
// 9 bit resolution by default | |||||
// Note the programmer is responsible for the right delay | |||||
// we could do something usefull here instead of the delay | |||||
int resolution = 9; | |||||
delay(750/ (1 << (12-resolution))); | |||||
// get temperature | |||||
Serial.print("Temperature: "); | |||||
Serial.println(sensors.getTempCByIndex(0)); | |||||
Serial.println("\n\n\n\n"); | |||||
delay(5000); | |||||
} |
@@ -1,80 +0,0 @@ | |||||
// | |||||
// Sample of using Async reading of Dallas Temperature Sensors | |||||
// | |||||
#include <OneWire.h> | |||||
#include <DallasTemperature.h> | |||||
// Data wire is plugged into port 2 on the Arduino | |||||
#define ONE_WIRE_BUS 2 | |||||
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) | |||||
OneWire oneWire(ONE_WIRE_BUS); | |||||
// Pass our oneWire reference to Dallas Temperature. | |||||
DallasTemperature sensors(&oneWire); | |||||
DeviceAddress tempDeviceAddress; | |||||
int resolution = 12; | |||||
unsigned long lastTempRequest = 0; | |||||
int delayInMillis = 0; | |||||
float temperature = 0.0; | |||||
int idle = 0; | |||||
// | |||||
// SETUP | |||||
// | |||||
void setup(void) | |||||
{ | |||||
Serial.begin(115200); | |||||
Serial.println("Dallas Temperature Control Library - Async Demo"); | |||||
Serial.print("Library Version: "); | |||||
Serial.println(DALLASTEMPLIBVERSION); | |||||
Serial.println("\n"); | |||||
sensors.begin(); | |||||
sensors.getAddress(tempDeviceAddress, 0); | |||||
sensors.setResolution(tempDeviceAddress, resolution); | |||||
sensors.setWaitForConversion(false); | |||||
sensors.requestTemperatures(); | |||||
delayInMillis = 750 / (1 << (12 - resolution)); | |||||
lastTempRequest = millis(); | |||||
pinMode(13, OUTPUT); | |||||
} | |||||
void loop(void) | |||||
{ | |||||
if (millis() - lastTempRequest >= delayInMillis) // waited long enough?? | |||||
{ | |||||
digitalWrite(13, LOW); | |||||
Serial.print(" Temperature: "); | |||||
temperature = sensors.getTempCByIndex(0); | |||||
Serial.println(temperature, resolution - 8); | |||||
Serial.print(" Resolution: "); | |||||
Serial.println(resolution); | |||||
Serial.print("Idle counter: "); | |||||
Serial.println(idle); | |||||
Serial.println(); | |||||
idle = 0; | |||||
// immediately after fetching the temperature we request a new sample | |||||
// in the async modus | |||||
// for the demo we let the resolution change to show differences | |||||
resolution++; | |||||
if (resolution > 12) resolution = 9; | |||||
sensors.setResolution(tempDeviceAddress, resolution); | |||||
sensors.requestTemperatures(); | |||||
delayInMillis = 750 / (1 << (12 - resolution)); | |||||
lastTempRequest = millis(); | |||||
} | |||||
digitalWrite(13, HIGH); | |||||
// we can do usefull things here | |||||
// for the demo we just count the idle time in millis | |||||
delay(1); | |||||
idle++; | |||||
} |
@@ -1,67 +0,0 @@ | |||||
// | |||||
// FILE: oneWireSearch.ino | |||||
// AUTHOR: Rob Tillaart | |||||
// VERSION: 0.1.02 | |||||
// PURPOSE: scan for 1-Wire devices + code snippet generator | |||||
// DATE: 2015-june-30 | |||||
// URL: http://forum.arduino.cc/index.php?topic=333923 | |||||
// | |||||
// inspired by http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html | |||||
// | |||||
// Released to the public domain | |||||
// | |||||
// 0.1.00 initial version | |||||
// 0.1.01 first published version | |||||
// 0.1.02 small output changes | |||||
#include <OneWire.h> | |||||
void setup() | |||||
{ | |||||
Serial.begin(115200); | |||||
Serial.println("//\n// Start oneWireSearch.ino \n//"); | |||||
for (uint8_t pin = 2; pin < 13; pin++) | |||||
{ | |||||
findDevices(pin); | |||||
} | |||||
Serial.println("\n//\n// End oneWireSearch.ino \n//"); | |||||
} | |||||
void loop() | |||||
{ | |||||
} | |||||
uint8_t findDevices(int pin) | |||||
{ | |||||
OneWire ow(pin); | |||||
uint8_t address[8]; | |||||
uint8_t count = 0; | |||||
if (ow.search(address)) | |||||
{ | |||||
Serial.print("\nuint8_t pin"); | |||||
Serial.print(pin, DEC); | |||||
Serial.println("[][8] = {"); | |||||
do { | |||||
count++; | |||||
Serial.println(" {"); | |||||
for (uint8_t i = 0; i < 8; i++) | |||||
{ | |||||
Serial.print("0x"); | |||||
if (address[i] < 0x10) Serial.print("0"); | |||||
Serial.print(address[i], HEX); | |||||
if (i < 7) Serial.print(", "); | |||||
} | |||||
Serial.println(" },"); | |||||
} while (ow.search(address)); | |||||
Serial.println("};"); | |||||
Serial.print("// nr devices found: "); | |||||
Serial.println(count); | |||||
} | |||||
return count; | |||||
} |
@@ -1,92 +0,0 @@ | |||||
// | |||||
// FILE: readPowerSupply.ino | |||||
// AUTHOR: Rob Tillaart | |||||
// VERSION: 0.1.0 | |||||
// PURPOSE: demo | |||||
// DATE: 2020-02-10 | |||||
// | |||||
// Released to the public domain | |||||
// | |||||
// Include the libraries we need | |||||
#include <OneWire.h> | |||||
#include <DallasTemperature.h> | |||||
// Data wire is plugged into port 2 on the Arduino | |||||
#define ONE_WIRE_BUS 2 | |||||
// Setup a oneWire instance to communicate with any OneWire devices | |||||
OneWire oneWire(ONE_WIRE_BUS); | |||||
// Pass our oneWire reference to Dallas Temperature. | |||||
DallasTemperature sensors(&oneWire); | |||||
// arrays to hold device addresses | |||||
DeviceAddress insideThermometer, outsideThermometer; | |||||
// Assign address manually. The addresses below will beed to be changed | |||||
// to valid device addresses on your bus. Device address can be retrieved | |||||
// by using either oneWire.search(deviceAddress) or individually via | |||||
// sensors.getAddress(deviceAddress, index) | |||||
// DeviceAddress insideThermometer = { 0x28, 0x1D, 0x39, 0x31, 0x2, 0x0, 0x0, 0xF0 }; | |||||
// DeviceAddress outsideThermometer = { 0x28, 0x3F, 0x1C, 0x31, 0x2, 0x0, 0x0, 0x2 }; | |||||
int devCount = 0; | |||||
/* | |||||
* The setup function. We only start the sensors here | |||||
*/ | |||||
void setup(void) | |||||
{ | |||||
Serial.begin(115200); | |||||
Serial.println("Arduino Temperature Control Library Demo - readPowerSupply"); | |||||
sensors.begin(); | |||||
devCount = sensors.getDeviceCount(); | |||||
Serial.print("#devices: "); | |||||
Serial.println(devCount); | |||||
// report parasite power requirements | |||||
Serial.print("Parasite power is: "); | |||||
if (sensors.readPowerSupply()) Serial.println("ON"); // no address means "scan all devices for parasite mode" | |||||
else Serial.println("OFF"); | |||||
// Search for devices on the bus and assign based on an index. | |||||
if (!sensors.getAddress(insideThermometer, 0)) Serial.println("Unable to find address for Device 0"); | |||||
if (!sensors.getAddress(outsideThermometer, 1)) Serial.println("Unable to find address for Device 1"); | |||||
// show the addresses we found on the bus | |||||
Serial.print("Device 0 Address: "); | |||||
printAddress(insideThermometer); | |||||
Serial.println(); | |||||
Serial.print("Power = parasite: "); | |||||
Serial.println(sensors.readPowerSupply(insideThermometer)); | |||||
Serial.println(); | |||||
Serial.println(); | |||||
Serial.print("Device 1 Address: "); | |||||
printAddress(outsideThermometer); | |||||
Serial.println(); | |||||
Serial.print("Power = parasite: "); | |||||
Serial.println(sensors.readPowerSupply(outsideThermometer)); | |||||
Serial.println(); | |||||
Serial.println(); | |||||
} | |||||
// function to print a device address | |||||
void printAddress(DeviceAddress deviceAddress) | |||||
{ | |||||
for (uint8_t i = 0; i < 8; i++) | |||||
{ | |||||
// zero pad the address if necessary | |||||
if (deviceAddress[i] < 0x10) Serial.print("0"); | |||||
Serial.print(deviceAddress[i], HEX); | |||||
} | |||||
} | |||||
// empty on purpose | |||||
void loop(void) | |||||
{ | |||||
} | |||||
// END OF FILE |
@@ -1,54 +0,0 @@ | |||||
####################################### | |||||
# Syntax Coloring Map For DallasTemperature | |||||
####################################### | |||||
####################################### | |||||
# Datatypes (KEYWORD1) | |||||
####################################### | |||||
DallasTemperature KEYWORD1 | |||||
OneWire KEYWORD1 | |||||
AlarmHandler KEYWORD1 | |||||
DeviceAddress KEYWORD1 | |||||
####################################### | |||||
# Methods and Functions (KEYWORD2) | |||||
####################################### | |||||
setResolution KEYWORD2 | |||||
getResolution KEYWORD2 | |||||
getTempC KEYWORD2 | |||||
toFahrenheit KEYWORD2 | |||||
getTempF KEYWORD2 | |||||
getTempCByIndex KEYWORD2 | |||||
getTempFByIndex KEYWORD2 | |||||
setWaitForConversion KEYWORD2 | |||||
getWaitForConversion KEYWORD2 | |||||
requestTemperatures KEYWORD2 | |||||
requestTemperaturesByAddress KEYWORD2 | |||||
requestTemperaturesByIndex KEYWORD2 | |||||
isParasitePowerMode KEYWORD2 | |||||
begin KEYWORD2 | |||||
getDeviceCount KEYWORD2 | |||||
getAddress KEYWORD2 | |||||
validAddress KEYWORD2 | |||||
isConnected KEYWORD2 | |||||
readScratchPad KEYWORD2 | |||||
writeScratchPad KEYWORD2 | |||||
readPowerSupply KEYWORD2 | |||||
setHighAlarmTemp KEYWORD2 | |||||
setLowAlarmTemp KEYWORD2 | |||||
getHighAlarmTemp KEYWORD2 | |||||
getLowAlarmTemp KEYWORD2 | |||||
resetAlarmSearch KEYWORD2 | |||||
alarmSearch KEYWORD2 | |||||
hasAlarm KEYWORD2 | |||||
toCelsius KEYWORD2 | |||||
processAlarmss KEYWORD2 | |||||
setAlarmHandlers KEYWORD2 | |||||
defaultAlarmHandler KEYWORD2 | |||||
calculateTemperature KEYWORD2 | |||||
####################################### | |||||
# Constants (LITERAL1) | |||||
####################################### | |||||
@@ -1,40 +0,0 @@ | |||||
{ | |||||
"name": "DallasTemperature", | |||||
"keywords": "onewire, 1-wire, bus, sensor, temperature", | |||||
"description": "Arduino Library for Dallas Temperature ICs (DS18B20, DS18S20, DS1822, DS1820)", | |||||
"repository": | |||||
{ | |||||
"type": "git", | |||||
"url": "https://github.com/milesburton/Arduino-Temperature-Control-Library.git" | |||||
}, | |||||
"authors": | |||||
[ | |||||
{ | |||||
"name": "Miles Burton", | |||||
"email": "miles@mnetcs.com", | |||||
"url": "http://www.milesburton.com", | |||||
"maintainer": true | |||||
}, | |||||
{ | |||||
"name": "Tim Newsome", | |||||
"email": "nuisance@casualhacker.net" | |||||
}, | |||||
{ | |||||
"name": "Guil Barros", | |||||
"email": "gfbarros@bappos.com" | |||||
}, | |||||
{ | |||||
"name": "Rob Tillaart", | |||||
"email": "rob.tillaart@gmail.com" | |||||
} | |||||
], | |||||
"dependencies": | |||||
{ | |||||
"name": "OneWire", | |||||
"authors": "Paul Stoffregen", | |||||
"frameworks": "arduino" | |||||
}, | |||||
"version": "3.8.1", | |||||
"frameworks": "arduino", | |||||
"platforms": "*" | |||||
} |
@@ -1,10 +0,0 @@ | |||||
name=DallasTemperature | |||||
version=3.8.1 | |||||
author=Miles Burton <miles@mnetcs.com>, Tim Newsome <nuisance@casualhacker.net>, Guil Barros <gfbarros@bappos.com>, Rob Tillaart <rob.tillaart@gmail.com> | |||||
maintainer=Miles Burton <miles@mnetcs.com> | |||||
sentence=Arduino Library for Dallas Temperature ICs | |||||
paragraph=Supports DS18B20, DS18S20, DS1822, DS1820 | |||||
category=Sensors | |||||
url=https://github.com/milesburton/Arduino-Temperature-Control-Library | |||||
architectures=* | |||||
depends=OneWire |
@@ -14,4 +14,5 @@ board = esp32doit-devkit-v1 | |||||
framework = arduino | framework = arduino | ||||
board_build.partitions = no_ota.csv | board_build.partitions = no_ota.csv | ||||
monitor_speed = 115200 | monitor_speed = 115200 | ||||
upload_speed = 115200 | |||||
upload_speed = 115200 | |||||
lib_deps = david-spirulerie/La Spirulerie @ ^0.0.2 |
@@ -16,6 +16,7 @@ void Application::Init() | |||||
{ | { | ||||
// Init RTOS queues | // Init RTOS queues | ||||
temperatureQueue = xQueueCreate(1, sizeof(float)); | temperatureQueue = xQueueCreate(1, sizeof(float)); | ||||
TSensorActiveQueue = xQueueCreate(1, sizeof(bool)); | |||||
PWMActionsQueue = xQueueCreate(20, sizeof(ActuatorPWMAction)); | PWMActionsQueue = xQueueCreate(20, sizeof(ActuatorPWMAction)); | ||||
inputQueue = xQueueCreate(5, sizeof(BtnEvent)); | inputQueue = xQueueCreate(5, sizeof(BtnEvent)); | ||||
audioQueue = xQueueCreate(5, sizeof(Melodies)); | audioQueue = xQueueCreate(5, sizeof(Melodies)); | ||||
@@ -60,7 +61,9 @@ void Application::Init() | |||||
void Application::Update() | void Application::Update() | ||||
{ | { | ||||
// ******** App Functions ******** | // ******** App Functions ******** | ||||
//WifiSystem.Update(); | |||||
// authorize temperature reading only on main menu | |||||
xQueueOverwrite(TSensorActiveQueue, &isOnMainMenu); | |||||
if (modeNeedsRefresh) | if (modeNeedsRefresh) | ||||
{ | { | ||||
@@ -83,7 +86,7 @@ void Application::Update() | |||||
if (pumpNominal) | if (pumpNominal) | ||||
Pump(); | Pump(); | ||||
if (canGoToScreenSaver && DataSaveLoad::ReadCanScreenSave() && !m_is_in_screensaver | |||||
if (isOnMainMenu && DataSaveLoad::ReadCanScreenSave() && !m_is_in_screensaver | |||||
&& (millis() - m_last_btn_press_time) / 1000 > SECONDS_TO_SCREENSAVER) | && (millis() - m_last_btn_press_time) / 1000 > SECONDS_TO_SCREENSAVER) | ||||
{ | { | ||||
digitalWrite(PIN_LCDLIGHT, LOW); | digitalWrite(PIN_LCDLIGHT, LOW); | ||||
@@ -8,7 +8,7 @@ void SceneMainMenu::Initialize() | |||||
Serial.printf("<== scene Main Menu ==>\n"); | Serial.printf("<== scene Main Menu ==>\n"); | ||||
Scene::Initialize(); | Scene::Initialize(); | ||||
app->canGoToScreenSaver = true; | |||||
app->isOnMainMenu = true; | |||||
app->Graphics.LoadFont("Comfortaa_26", SPIRULERIE_LIGHT, SPIRULERIE_GREEN/*SPIRULERIE_GREY*/); | app->Graphics.LoadFont("Comfortaa_26", SPIRULERIE_LIGHT, SPIRULERIE_GREEN/*SPIRULERIE_GREY*/); | ||||
app->PlayMelody(Melodies::VALID); | app->PlayMelody(Melodies::VALID); | ||||
} | } | ||||
@@ -54,7 +54,7 @@ void SceneMainMenu::OnButtonClic(BTN btn) | |||||
case BTN::MIDDLE: | case BTN::MIDDLE: | ||||
break; | break; | ||||
case BTN::RIGHT: | case BTN::RIGHT: | ||||
app->canGoToScreenSaver = false; | |||||
app->isOnMainMenu = false; | |||||
app->LoadScene(new SceneTopMenu()); | app->LoadScene(new SceneTopMenu()); | ||||
break; | break; | ||||
default: | default: | ||||
@@ -121,7 +121,6 @@ void ScenePumpUse::Initialize() | |||||
Serial.printf("<== scene ScenePumpUse ==>\n"); | Serial.printf("<== scene ScenePumpUse ==>\n"); | ||||
Scene::Initialize(); | Scene::Initialize(); | ||||
//app->canGoToScreenSaver = false; | |||||
app->pumpNominal = false; // Tell the app NOT to update the pump anymore | app->pumpNominal = false; // Tell the app NOT to update the pump anymore | ||||
app->SendAction(PWMC_IO_D, 0, 500); // Tell the pump to stop | app->SendAction(PWMC_IO_D, 0, 500); // Tell the pump to stop | ||||
@@ -178,7 +177,6 @@ void ScenePumpUse::Update() | |||||
break; | break; | ||||
case EXIT: | case EXIT: | ||||
app->pumpNominal = true; // Give back control of the pump to the App | app->pumpNominal = true; // Give back control of the pump to the App | ||||
//app->canGoToScreenSaver = true; | |||||
app->LoadScene(new SceneMainMenu()); | app->LoadScene(new SceneMainMenu()); | ||||
break; | break; | ||||
default: | default: | ||||
@@ -17,6 +17,7 @@ TaskHandle_t InitThermometer() | |||||
void ThermometerTask(void *parameter) | void ThermometerTask(void *parameter) | ||||
{ | { | ||||
QueueHandle_t temperatureQueue = Application::singleton->temperatureQueue; | QueueHandle_t temperatureQueue = Application::singleton->temperatureQueue; | ||||
QueueHandle_t TSensorActiveQueue = Application::singleton->TSensorActiveQueue; | |||||
Thermometer thermometer; | Thermometer thermometer; | ||||
// we should fill the queue with at least an error value. Not the undefined default | // we should fill the queue with at least an error value. Not the undefined default | ||||
@@ -31,24 +32,29 @@ void ThermometerTask(void *parameter) | |||||
delay(400); | delay(400); | ||||
// Wait a bit between initialization and first reading | // Wait a bit between initialization and first reading | ||||
delay(1000); | |||||
delay(5000); | |||||
// Read termperature and send it in to the RTOS queue | // Read termperature and send it in to the RTOS queue | ||||
for (;;) | for (;;) | ||||
{ | { | ||||
float tempC = -1; | |||||
// Check Temperature | |||||
tempC = thermometer.GetTemperature(); | |||||
if (tempC == -1) | |||||
thermometer.StartDevice(); | |||||
if (tempC < -1) | |||||
tempC = -1; // sometime gets -127 for some reason | |||||
// Send temperature to Queue | |||||
xQueueOverwrite(temperatureQueue, &tempC); | |||||
float tempC = -1; | |||||
bool canCheckTemperature = false; | |||||
// Check if authorized to get temperature (because its freezes for a few milliseconds) | |||||
xQueuePeek(TSensorActiveQueue, &canCheckTemperature, 10); | |||||
if (canCheckTemperature) | |||||
{ | |||||
// Check Temperature | |||||
tempC = thermometer.GetTemperature(); | |||||
if (tempC == -1) | |||||
thermometer.StartDevice(); | |||||
if (tempC < -1) | |||||
tempC = -1; // sometime gets -127 for some reason | |||||
// Send temperature to Queue | |||||
xQueueOverwrite(temperatureQueue, &tempC); | |||||
} | |||||
if (tempC != -1) | if (tempC != -1) | ||||
delay(READING_DELAY); | delay(READING_DELAY); | ||||
else | else | ||||