Arduino-OWI
One-Wire Interface (OWI) library for Arduino
DS18B20.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 "Driver/DS18B20.h"
7 #include "assert.h"
8 
9 Hardware::TWI twi;
12 
13 void setup()
14 {
15  Serial.begin(57600);
16  while (!Serial);
17 }
18 
19 void loop()
20 {
21  // Broadcast a convert request to all thermometer sensors
22  // Print list of sensors, rom code, and temperature
23 
24  if (!sensor.convert_request(true)) return;
25  delay(sensor.conversion_time());
26 
27  int8_t last = owi.FIRST;
28  uint8_t* rom = sensor.rom();
29  int id = 0;
30  do {
31  // Search for the next digital thermometer
32  last = owi.search_rom(sensor.FAMILY_CODE, rom, last);
33  if (last == owi.ERROR) break;
34 
35  // Read the scratchpad with current temperature, tiggers, etc
36  ASSERT(sensor.read_scratchpad(false));
37  int8_t low, high;
38  sensor.get_trigger(low, high);
39 
40  // Print sequence number
41  Serial.print(id++);
42 
43  // Print family code
44  Serial.print(F(":family="));
45  Serial.print(rom[0], HEX);
46 
47  // Print serial number
48  Serial.print(F(",sn="));
49  size_t i = 1;
50  do {
51  if (rom[i] < 0x10) Serial.print(0);
52  Serial.print(rom[i], HEX);
53  i += 1;
54  } while (i < owi.ROM_MAX - 1);
55 
56  // Print cyclic redundancy check sum
57  Serial.print(F(",crc="));
58  if (rom[i] < 0x10) Serial.print(0);
59  Serial.print(rom[i], HEX);
60 
61  // Print conversion resolution
62  Serial.print(F(",resolution="));
63  Serial.print(sensor.resolution());
64 
65  // Print alarm trigger threshols
66  Serial.print(F(",trigger=["));
67  Serial.print(low);
68  Serial.print(F(".."));
69  Serial.print(high);
70 
71  // And temperature
72  Serial.print(F("],temperature="));
73  Serial.println(sensor.temperature());
74  } while (last != owi.LAST);
75 
76  Serial.println();
77  delay(4000);
78 }
static const uint8_t FAMILY_CODE
Definition: DS18B20.h:44
Hardware::TWI twi
Definition: DS18B20.ino:9
Software::Serial< BOARD::D0 > Serial
Definition: DS18B20.ino:8
Software::OWI< BOARD::D1 > owi
Definition: DS18B20.ino:9
void get_trigger(int8_t &low, int8_t &high) const
Definition: DS18B20.h:113
bool read_scratchpad(bool match=true)
Definition: DS18B20.h:185
bool convert_request(bool broadcast=false)
Definition: DS18B20.h:125
void resolution(uint8_t bits)
Definition: DS18B20.h:70
DS18B20 sensor(owi)
void rom(const uint8_t *rom)
Definition: OWI.h:303
float temperature() const
Definition: DS18B20.h:94
uint16_t conversion_time()
Definition: DS18B20.h:143
void loop()
Definition: DS18B20.ino:18
void setup()
Definition: DS18B20.ino:12