Arduino-OWI
One-Wire Interface (OWI) library for Arduino
Search.ino
Go to the documentation of this file.
1 #include "GPIO.h"
2 #include "OWI.h"
3 
4 // Configure: Software/Hardware OWI Bus Manager
5 #define USE_SOFTWARE_OWI
6 #if defined(USE_SOFTWARE_OWI)
7 #include "Software/OWI.h"
9 
10 #else
11 // Configure: Software/Hardware TWI Bus Manager
12 // #define USE_SOFTWARE_TWI
13 #include "TWI.h"
14 #include "Hardware/OWI.h"
15 #if defined(USE_SOFTWARE_TWI)
16 #include "Software/TWI.h"
17 #if defined(SAM)
18 Software::TWI<BOARD::D8,BOARD::D9> twi;
19 #else
20 Software::TWI<BOARD::D18,BOARD::D19> twi;
21 #endif
22 #else
23 #include "Hardware/TWI.h"
24 Hardware::TWI twi;
25 #endif
27 #endif
28 
29 void setup()
30 {
31  Serial.begin(57600);
32  while (!Serial);
33 }
34 
35 void loop()
36 {
37  // Scan one-wire bus and print rom code for all detected devices
38  // on binary format and indicate discrepancy position.
39  uint8_t rom[owi.ROM_MAX] = { 0 };
40  int8_t last = owi.FIRST;
41  int i = 0;
42  do {
43  last = owi.search_rom(0, rom, last);
44  if (last == owi.ERROR) break;
45  Serial.print(i++);
46  Serial.print(':');
47  int8_t pos = 0;
48  for (size_t i = 0; i < sizeof(rom); i++)
49  for (uint8_t mask = 0x80; mask != 0; mask >>= 1, pos++) {
50  Serial.print((rom[i] & mask) != 0);
51  if (pos == last) Serial.print('*');
52  }
53  if (pos == last) Serial.print('*');
54  Serial.println();
55  } while (last != owi.LAST);
56  Serial.println();
57 
58  delay(5000);
59 }
Software::Serial< BOARD::D0 > Serial
Definition: Search.ino:7
Error during search.
Definition: OWI.h:192
void setup()
Definition: Search.ino:10
int8_t search_rom(uint8_t family, uint8_t *code, int8_t last=FIRST)
Definition: OWI.h:204
Hardware::TWI twi
Definition: Search.ino:8
Software::OWI< BOARD::D1 > owi
Definition: Search.ino:8
Last position, search completed.
Definition: OWI.h:193
Start position of search.
Definition: OWI.h:191
static const size_t ROM_MAX
Definition: OWI.h:32
void loop()
Definition: Search.ino:16