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