oneWireSearch.ino example

scan for 1-Wire devices + code snippet generator DATE: 2015-june-30 URL: http://forum.arduino.cc/index.php?topic=333923

scan for 1-Wire devices + code snippet generator DATE: 2015-june-30 URL: http://forum.arduino.cc/index.php?topic=333923@author Rob Tillaart VERSION: 0.1.02

inspired by http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html

Released to the public domain

0.1.00 initial version 0.1.01 first published version 0.1.02 small output changes

1/** =========================================================================
2 * @example{lineno} oneWireSearch.ino
3 * @author Rob Tillaart
4 * VERSION: 0.1.02
5 * @brief 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
10 * http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html
11 *
12 * Released to the public domain
13 *
14 * 0.1.00 initial version
15 * 0.1.01 first published version
16 * 0.1.02 small output changes
17 *
18 * @m_examplenavigation{page_extra_helper_sketches,}
19 * ======================================================================= */
20
21#include <Arduino.h>
22#include <OneWire.h>
23
24uint8_t findDevices(int pin) {
25 OneWire ow(pin);
26
27 uint8_t address[8];
28 uint8_t count = 0;
29
30
31 if (ow.search(address)) {
32 Serial.print("\nuint8_t pin");
33 Serial.print(pin, DEC);
34 Serial.println("[][8] = {");
35 do {
36 count++;
37 Serial.print(" {");
38 for (uint8_t i = 0; i < 8; i++) {
39 Serial.print("0x");
40 if (address[i] < 0x10) Serial.print("0");
41 Serial.print(address[i], HEX);
42 if (i < 7) Serial.print(", ");
43 }
44 Serial.println("},");
45 } while (ow.search(address));
46
47 Serial.println("};");
48 Serial.print("// nr devices found: ");
49 Serial.println(count);
50 }
51
52 return count;
53}
54
55void setup() {
56 Serial.begin(9600);
57 Serial.println(
58 "//\n// Start oneWireSearch.ino \n// -----------------------");
59
60 // Power the sensors;
61 pinMode(22, OUTPUT);
62 digitalWrite(22, HIGH);
63 delay(2000);
64
65 for (uint8_t pin = 2; pin < 37; pin++) { findDevices(pin); }
66 Serial.println("\n//\n// End oneWireSearch.ino \n// ---------------------");
67
68 // Cut power
69 digitalWrite(22, LOW);
70}
71
72void loop() {}