Arduino-OWI
One-Wire Interface (OWI) library for Arduino
Scanner.ino
Go to the documentation of this file.
1 #include "GPIO.h"
2 #include "OWI.h"
3 #include "Software/OWI.h"
4 
6 
7 void setup()
8 {
9  Serial.begin(57600);
10  while (!Serial);
11 }
12 
13 void loop()
14 {
15  // Scan one-wire bus and print rom code for all detected devices
16  // Print family, serial number and cyclic redundancy check sum
17  uint8_t rom[owi.ROM_MAX] = { 0 };
18  int8_t last = owi.FIRST;
19  int id = 0;
20 
21  do {
22  last = owi.search_rom(0, rom, last);
23  if (last == owi.ERROR) break;
24 
25  // Print sequence number
26  Serial.print(id++);
27 
28  // Print family code
29  Serial.print(F(":family="));
30  Serial.print(rom[0], HEX);
31 
32  // Print serial number
33  Serial.print(F(",sn="));
34  size_t i = 1;
35  do {
36  if (rom[i] < 0x10) Serial.print(0);
37  Serial.print(rom[i], HEX);
38  i += 1;
39  } while (i < owi.ROM_MAX - 1);
40 
41  // Print cyclic redundancy check sum
42  Serial.print(F(",crc="));
43  if (rom[i] < 0x10) Serial.print(0);
44  Serial.println(rom[i], HEX);
45  } while (last != owi.LAST);
46 
47  Serial.println();
48  delay(2000);
49 }
Software::Serial< BOARD::D0 > Serial
Definition: Scanner.ino:7
void loop()
Definition: Scanner.ino:16
Error during search.
Definition: OWI.h:192
void setup()
Definition: Scanner.ino:10
int8_t search_rom(uint8_t family, uint8_t *code, int8_t last=FIRST)
Definition: OWI.h:204
Software::OWI< BOARD::D1 > owi
Definition: Scanner.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