File tree Expand file tree Collapse file tree 1 file changed +67
-0
lines changed
Expand file tree Collapse file tree 1 file changed +67
-0
lines changed Original file line number Diff line number Diff line change 1+ //
2+ // FILE: oneWireSearch.ino
3+ // AUTHOR: Rob Tillaart
4+ // VERSION: 0.1.02
5+ // PURPOSE: scan for 1-Wire devices + code snippet generator
6+ // DATE: 2015-june-30
7+ // URL: http://forum.arduino.cc/index.php?topic=333923
8+ //
9+ // inspired by http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html
10+ //
11+ // Released to the public domain
12+ //
13+ // 0.1.00 initial version
14+ // 0.1.01 first published version
15+ // 0.1.02 small output changes
16+
17+ #include < OneWire.h>
18+
19+ void setup ()
20+ {
21+ Serial.begin (115200 );
22+ Serial.println (" //\n // Start oneWireSearch.ino \n //" );
23+
24+ for (uint8_t pin = 2 ; pin < 13 ; pin++)
25+ {
26+ findDevices (pin);
27+ }
28+ Serial.println (" \n //\n // End oneWireSearch.ino \n //" );
29+ }
30+
31+ void loop ()
32+ {
33+ }
34+
35+ uint8_t findDevices (int pin)
36+ {
37+ OneWire ow (pin);
38+
39+ uint8_t address[8 ];
40+ uint8_t count = 0 ;
41+
42+
43+ if (ow.search (address))
44+ {
45+ Serial.print (" \n uint8_t pin" );
46+ Serial.print (pin, DEC);
47+ Serial.println (" [][8] = {" );
48+ {
49+ count++;
50+ Serial.println (" {" );
51+ for (uint8_t i = 0 ; i < 8 ; i++)
52+ {
53+ Serial.print (" 0x" );
54+ if (address[i] < 0x10 ) Serial.print (" 0" );
55+ Serial.print (address[i], HEX);
56+ if (i < 7 ) Serial.print (" , " );
57+ }
58+ Serial.println (" }," );
59+ } while (ow.search (address));
60+
61+ Serial.println (" };" );
62+ Serial.print (" // nr devices found: " );
63+ Serial.println (count);
64+ }
65+
66+ return count;
67+ }
You can’t perform that action at this time.
0 commit comments