9
9
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
10
10
OneWire oneWire(ONE_WIRE_BUS );
11
11
12
- // Pass our oneWire reference to Dallas Temperature.
12
+ // Pass our oneWire reference to Dallas Temperature.
13
13
DallasTemperature sensors(& oneWire);
14
14
15
15
// arrays to hold device addresses
16
16
DeviceAddress insideThermometer, outsideThermometer;
17
17
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
+
18
25
void setup (void )
19
26
{
20
27
// start serial port
@@ -31,31 +38,24 @@ void setup(void)
31
38
Serial . println(" devices." );
32
39
33
40
// report parasite power requirements
34
- Serial . print(" Parasite power is: " );
41
+ Serial . print(" Parasite power is: " );
35
42
if (sensors. isParasitePowerMode()) Serial . println(" ON" );
36
43
else Serial . println(" OFF" );
37
44
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
-
45
45
// 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
48
48
// the devices on your bus (and assuming they don't change).
49
- //
49
+ //
50
50
// 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" );
53
53
54
54
// method 2: search()
55
55
// 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
59
59
// deterministic. You will always get the same devices in the same order
60
60
//
61
61
// Must be called before search()
@@ -79,11 +79,11 @@ void setup(void)
79
79
sensors. setResolution(outsideThermometer, TEMPERATURE_PRECISION );
80
80
81
81
Serial . print(" Device 0 Resolution: " );
82
- Serial . print(sensors. getResolution(insideThermometer), DEC );
82
+ Serial . print(sensors. getResolution(insideThermometer), DEC );
83
83
Serial . println();
84
84
85
85
Serial . print(" Device 1 Resolution: " );
86
- Serial . print(sensors. getResolution(outsideThermometer), DEC );
86
+ Serial . print(sensors. getResolution(outsideThermometer), DEC );
87
87
Serial . println();
88
88
}
89
89
@@ -113,7 +113,7 @@ void printResolution(DeviceAddress deviceAddress)
113
113
{
114
114
Serial . print(" Resolution: " );
115
115
Serial . print(sensors. getResolution(deviceAddress));
116
- Serial . println();
116
+ Serial . println();
117
117
}
118
118
119
119
// main function to print information about a device
@@ -127,11 +127,11 @@ void printData(DeviceAddress deviceAddress)
127
127
}
128
128
129
129
/*
130
- * Main function, calls the temperatures in a loop.
131
- */
130
+ Main function, calls the temperatures in a loop.
131
+ */
132
132
void loop (void )
133
- {
134
- // call sensors.requestTemperatures() to issue a global temperature
133
+ {
134
+ // call sensors.requestTemperatures() to issue a global temperature
135
135
// request to all devices on the bus
136
136
Serial . print(" Requesting temperatures..." );
137
137
sensors. requestTemperatures();
@@ -141,4 +141,3 @@ void loop(void)
141
141
printData(insideThermometer);
142
142
printData(outsideThermometer);
143
143
}
144
-
0 commit comments