Arduino-OWI
One-Wire Interface (OWI) library for Arduino
Alarm.ino
Go to the documentation of this file.
1 #include "GPIO.h"
2 #include "OWI.h"
3 #include "TWI.h"
4 #include "Hardware/TWI.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  // Set sensor alarm triggers (20..25 C) and resolution (10 bits)
19  // Iterate though all thermometers and configure.
20  uint8_t* rom = sensor.rom();
21  int8_t last = owi.FIRST;
22  do {
23  last = owi.search_rom(sensor.FAMILY_CODE, rom, last);
24  if (last == owi.ERROR) break;
25  sensor.resolution(10);
26  sensor.set_trigger(20, 25);
27  ASSERT(sensor.write_scratchpad());
28  } while (last != owi.LAST);
29 }
30 
31 void loop()
32 {
33  // Check if any thermometer sersors have exceeded thresholds.
34  // Broadcast a convert request to all thermometer sensors.
35  // Print timestamp and sensor identity and temperature.
36 
37  int8_t last = owi.FIRST;
38  uint8_t* rom = sensor.rom();
39  static uint16_t timestamp = 0;
40  uint8_t id = 0;
41  if (!sensor.convert_request(true)) return;
42  delay(sensor.conversion_time());
43  do {
44  last = owi.alarm_search(rom, last);
45  if (last == owi.ERROR) break;
46  ASSERT(sensor.read_scratchpad(false));
47  Serial.print(timestamp);
48  Serial.print('.');
49  Serial.print(id++);
50  Serial.print(F(":rom="));
51  for (size_t i = 1; i < owi.ROM_MAX; i++) {
52  if (rom[i] < 0x10) Serial.print(0);
53  Serial.print(rom[i], HEX);
54  }
55  Serial.print(F(",temperature="));
56  Serial.println(sensor.temperature());
57  } while (last != owi.LAST);
58  timestamp += 1;
59  delay(1000);
60 }
static const uint8_t FAMILY_CODE
Definition: DS18B20.h:44
void setup()
Definition: Alarm.ino:10
bool read_scratchpad(bool match=true)
Definition: DS18B20.h:185
bool convert_request(bool broadcast=false)
Definition: DS18B20.h:125
Software::Serial< BOARD::D0 > Serial
Definition: Alarm.ino:8
DS18B20 sensor(owi)
void resolution(uint8_t bits)
Definition: DS18B20.h:70
Software::OWI< BOARD::D7 > owi
Definition: Alarm.ino:7
bool write_scratchpad(bool match=true)
Definition: DS18B20.h:199
void rom(const uint8_t *rom)
Definition: OWI.h:303
Hardware::TWI twi
Definition: Alarm.ino:9
void set_trigger(int8_t low, int8_t high)
Definition: DS18B20.h:82
float temperature() const
Definition: DS18B20.h:94
uint16_t conversion_time()
Definition: DS18B20.h:143
void loop()
Definition: Alarm.ino:28