Skip to content

Commit 468bca3

Browse files
authored
Merge pull request #102 from RobTillaart/master
issue #77 - fixed code so manual assigned address works
2 parents d3b74d6 + ec155df commit 468bca3

File tree

1 file changed

+24
-25
lines changed

1 file changed

+24
-25
lines changed

examples/Multiple/Multiple.pde

+24-25
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,19 @@
99
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
1010
OneWire oneWire(ONE_WIRE_BUS);
1111

12-
// Pass our oneWire reference to Dallas Temperature.
12+
// Pass our oneWire reference to Dallas Temperature.
1313
DallasTemperature sensors(&oneWire);
1414

1515
// arrays to hold device addresses
1616
DeviceAddress insideThermometer, outsideThermometer;
1717

18+
// Assign address manually. The addresses below will beed to be changed
19+
// to valid device addresses on your bus. Device address can be retrieved
20+
// by using either oneWire.search(deviceAddress) or individually via
21+
// sensors.getAddress(deviceAddress, index)
22+
// DeviceAddress insideThermometer = { 0x28, 0x1D, 0x39, 0x31, 0x2, 0x0, 0x0, 0xF0 };
23+
// DeviceAddress outsideThermometer = { 0x28, 0x3F, 0x1C, 0x31, 0x2, 0x0, 0x0, 0x2 };
24+
1825
void setup(void)
1926
{
2027
// start serial port
@@ -31,31 +38,24 @@ void setup(void)
3138
Serial.println(" devices.");
3239

3340
// report parasite power requirements
34-
Serial.print("Parasite power is: ");
41+
Serial.print("Parasite power is: ");
3542
if (sensors.isParasitePowerMode()) Serial.println("ON");
3643
else Serial.println("OFF");
3744

38-
// Assign address manually. The addresses below will beed to be changed
39-
// to valid device addresses on your bus. Device address can be retrieved
40-
// by using either oneWire.search(deviceAddress) or individually via
41-
// sensors.getAddress(deviceAddress, index)
42-
//insideThermometer = { 0x28, 0x1D, 0x39, 0x31, 0x2, 0x0, 0x0, 0xF0 };
43-
//outsideThermometer = { 0x28, 0x3F, 0x1C, 0x31, 0x2, 0x0, 0x0, 0x2 };
44-
4545
// Search for devices on the bus and assign based on an index. Ideally,
46-
// you would do this to initially discover addresses on the bus and then
47-
// use those addresses and manually assign them (see above) once you know
46+
// you would do this to initially discover addresses on the bus and then
47+
// use those addresses and manually assign them (see above) once you know
4848
// the devices on your bus (and assuming they don't change).
49-
//
49+
//
5050
// method 1: by index
51-
if (!sensors.getAddress(insideThermometer, 0)) Serial.println("Unable to find address for Device 0");
52-
if (!sensors.getAddress(outsideThermometer, 1)) Serial.println("Unable to find address for Device 1");
51+
if (!sensors.getAddress(insideThermometer, 0)) Serial.println("Unable to find address for Device 0");
52+
if (!sensors.getAddress(outsideThermometer, 1)) Serial.println("Unable to find address for Device 1");
5353

5454
// method 2: search()
5555
// search() looks for the next device. Returns 1 if a new address has been
56-
// returned. A zero might mean that the bus is shorted, there are no devices,
57-
// or you have already retrieved all of them. It might be a good idea to
58-
// check the CRC to make sure you didn't get garbage. The order is
56+
// returned. A zero might mean that the bus is shorted, there are no devices,
57+
// or you have already retrieved all of them. It might be a good idea to
58+
// check the CRC to make sure you didn't get garbage. The order is
5959
// deterministic. You will always get the same devices in the same order
6060
//
6161
// Must be called before search()
@@ -79,11 +79,11 @@ void setup(void)
7979
sensors.setResolution(outsideThermometer, TEMPERATURE_PRECISION);
8080

8181
Serial.print("Device 0 Resolution: ");
82-
Serial.print(sensors.getResolution(insideThermometer), DEC);
82+
Serial.print(sensors.getResolution(insideThermometer), DEC);
8383
Serial.println();
8484

8585
Serial.print("Device 1 Resolution: ");
86-
Serial.print(sensors.getResolution(outsideThermometer), DEC);
86+
Serial.print(sensors.getResolution(outsideThermometer), DEC);
8787
Serial.println();
8888
}
8989

@@ -113,7 +113,7 @@ void printResolution(DeviceAddress deviceAddress)
113113
{
114114
Serial.print("Resolution: ");
115115
Serial.print(sensors.getResolution(deviceAddress));
116-
Serial.println();
116+
Serial.println();
117117
}
118118

119119
// main function to print information about a device
@@ -127,11 +127,11 @@ void printData(DeviceAddress deviceAddress)
127127
}
128128

129129
/*
130-
* Main function, calls the temperatures in a loop.
131-
*/
130+
Main function, calls the temperatures in a loop.
131+
*/
132132
void loop(void)
133-
{
134-
// call sensors.requestTemperatures() to issue a global temperature
133+
{
134+
// call sensors.requestTemperatures() to issue a global temperature
135135
// request to all devices on the bus
136136
Serial.print("Requesting temperatures...");
137137
sensors.requestTemperatures();
@@ -141,4 +141,3 @@ void loop(void)
141141
printData(insideThermometer);
142142
printData(outsideThermometer);
143143
}
144-

0 commit comments

Comments
 (0)