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