Skip to content

Commit a333d1b

Browse files
committedFeb 10, 2020
- fix 145 - readPowerSupply extended + example added
1 parent 6e94aae commit a333d1b

File tree

5 files changed

+116
-11
lines changed

5 files changed

+116
-11
lines changed
 

Diff for: ‎DallasTemperature.cpp

+15-7
Original file line numberDiff line numberDiff line change
@@ -233,17 +233,25 @@ void DallasTemperature::writeScratchPad(const uint8_t* deviceAddress,
233233

234234
}
235235

236-
bool DallasTemperature::readPowerSupply(const uint8_t* deviceAddress) {
237-
238-
bool ret = false;
236+
// returns true if parasite mode is used (2 wire)
237+
// returns false if normal mode is used (3 wire)
238+
// if no address is given (or nullptr) it checks if any device on the bus
239+
// uses parasite mode.
240+
// See issue #145
241+
bool DallasTemperature::readPowerSupply(const uint8_t* deviceAddress)
242+
{
243+
bool parasiteMode = false;
239244
_wire->reset();
240-
_wire->select(deviceAddress);
245+
if (deviceAddress == nullptr)
246+
_wire->skip();
247+
else
248+
_wire->select(deviceAddress);
249+
241250
_wire->write(READPOWERSUPPLY);
242251
if (_wire->read_bit() == 0)
243-
ret = true;
252+
parasiteMode = true;
244253
_wire->reset();
245-
return ret;
246-
254+
return parasiteMode;
247255
}
248256

249257
// set resolution of all devices to 9, 10, 11, or 12 bits

Diff for: ‎DallasTemperature.h

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef DallasTemperature_h
22
#define DallasTemperature_h
33

4-
#define DALLASTEMPLIBVERSION "3.7.9" // To be deprecated
4+
#define DALLASTEMPLIBVERSION "3.8.1" // To be deprecated -> TODO remove in 4.0.0
55

66
// This library is free software; you can redistribute it and/or
77
// modify it under the terms of the GNU Lesser General Public
@@ -37,6 +37,11 @@
3737
#define DEVICE_DISCONNECTED_F -196.6
3838
#define DEVICE_DISCONNECTED_RAW -7040
3939

40+
// For readPowerSupply on oneWire bus
41+
#ifndef nullptr
42+
#define nullptr NULL
43+
#endif
44+
4045
typedef uint8_t DeviceAddress[8];
4146

4247
class DallasTemperature {
@@ -82,7 +87,7 @@ class DallasTemperature {
8287
void writeScratchPad(const uint8_t*, const uint8_t*);
8388

8489
// read device's power requirements
85-
bool readPowerSupply(const uint8_t*);
90+
bool readPowerSupply(const uint8_t* deviceAddress = nullptr);
8691

8792
// get global resolution
8893
uint8_t getResolution();

Diff for: ‎examples/readPowerSupply/readPowerSupply.ino

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
//
2+
// FILE: readPowerSupply.ino
3+
// AUTHOR: Rob Tillaart
4+
// VERSION: 0.1.0
5+
// PURPOSE: demo
6+
// DATE: 2020-02-10
7+
//
8+
// Released to the public domain
9+
//
10+
11+
// Include the libraries we need
12+
#include <OneWire.h>
13+
#include <DallasTemperature.h>
14+
15+
// Data wire is plugged into port 2 on the Arduino
16+
#define ONE_WIRE_BUS 2
17+
18+
// Setup a oneWire instance to communicate with any OneWire devices
19+
OneWire oneWire(ONE_WIRE_BUS);
20+
21+
// Pass our oneWire reference to Dallas Temperature.
22+
DallasTemperature sensors(&oneWire);
23+
24+
// arrays to hold device addresses
25+
DeviceAddress insideThermometer, outsideThermometer;
26+
// Assign address manually. The addresses below will beed to be changed
27+
// to valid device addresses on your bus. Device address can be retrieved
28+
// by using either oneWire.search(deviceAddress) or individually via
29+
// sensors.getAddress(deviceAddress, index)
30+
// DeviceAddress insideThermometer = { 0x28, 0x1D, 0x39, 0x31, 0x2, 0x0, 0x0, 0xF0 };
31+
// DeviceAddress outsideThermometer = { 0x28, 0x3F, 0x1C, 0x31, 0x2, 0x0, 0x0, 0x2 };
32+
33+
int devCount = 0;
34+
35+
/*
36+
* The setup function. We only start the sensors here
37+
*/
38+
void setup(void)
39+
{
40+
Serial.begin(115200);
41+
Serial.println("Arduino Temperature Control Library Demo - readPowerSupply");
42+
43+
sensors.begin();
44+
45+
devCount = sensors.getDeviceCount();
46+
Serial.print("#devices: ");
47+
Serial.println(devCount);
48+
49+
// report parasite power requirements
50+
Serial.print("Parasite power is: ");
51+
if (sensors.readPowerSupply()) Serial.println("ON"); // no address means "scan all devices for parasite mode"
52+
else Serial.println("OFF");
53+
54+
// Search for devices on the bus and assign based on an index.
55+
if (!sensors.getAddress(insideThermometer, 0)) Serial.println("Unable to find address for Device 0");
56+
if (!sensors.getAddress(outsideThermometer, 1)) Serial.println("Unable to find address for Device 1");
57+
58+
// show the addresses we found on the bus
59+
Serial.print("Device 0 Address: ");
60+
printAddress(insideThermometer);
61+
Serial.println();
62+
Serial.print("Power = parasite: ");
63+
Serial.println(sensors.readPowerSupply(insideThermometer));
64+
Serial.println();
65+
Serial.println();
66+
67+
Serial.print("Device 1 Address: ");
68+
printAddress(outsideThermometer);
69+
Serial.println();
70+
Serial.print("Power = parasite: ");
71+
Serial.println(sensors.readPowerSupply(outsideThermometer));
72+
Serial.println();
73+
Serial.println();
74+
}
75+
76+
// function to print a device address
77+
void printAddress(DeviceAddress deviceAddress)
78+
{
79+
for (uint8_t i = 0; i < 8; i++)
80+
{
81+
// zero pad the address if necessary
82+
if (deviceAddress[i] < 0x10) Serial.print("0");
83+
Serial.print(deviceAddress[i], HEX);
84+
}
85+
}
86+
87+
// empty on purpose
88+
void loop(void)
89+
{
90+
}
91+
92+
// END OF FILE

Diff for: ‎library.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"authors": "Paul Stoffregen",
3535
"frameworks": "arduino"
3636
},
37-
"version": "3.8.0",
37+
"version": "3.8.1",
3838
"frameworks": "arduino",
3939
"platforms": "*"
4040
}

Diff for: ‎library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=DallasTemperature
2-
version=3.8.0
2+
version=3.8.1
33
author=Miles Burton <miles@mnetcs.com>, Tim Newsome <nuisance@casualhacker.net>, Guil Barros <gfbarros@bappos.com>, Rob Tillaart <rob.tillaart@gmail.com>
44
maintainer=Miles Burton <miles@mnetcs.com>
55
sentence=Arduino Library for Dallas Temperature ICs

0 commit comments

Comments
 (0)
Please sign in to comment.