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
0 commit comments