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 "Software/OWI.h"
4 #include "Driver/DS18B20.h"
5 #include "Software/Serial.h"
6 #include "assert.h"
7 
8 Software::Serial<BOARD::D0> Serial;
10 DS18B20 sensor(owi);
11 
12 void setup()
13 {
14  Serial.begin(57600);
15  while (!Serial);
16 
17  // Set sensor alarm triggers (20..25 C) and resolution (10 bits)
18  // Iterate though all thermometers and configure.
19  uint8_t* rom = sensor.rom();
20  int8_t last = owi.FIRST;
21  do {
22  last = owi.search_rom(sensor.FAMILY_CODE, rom, last);
23  if (last == owi.ERROR) break;
24  sensor.resolution(10);
25  sensor.set_trigger(20, 25);
26  ASSERT(sensor.write_scratchpad());
27  } while (last != owi.LAST);
28 }
29 
30 void loop()
31 {
32  // Check if any thermometer sersors have exceeded thresholds.
33  // Broadcast a convert request to all thermometer sensors.
34  // Print timestamp and sensor identity and temperature.
35 
36  int8_t last = owi.FIRST;
37  uint8_t* rom = sensor.rom();
38  static uint16_t timestamp = 0;
39  uint8_t id = 0;
40  if (!sensor.convert_request(true)) return;
41  delay(sensor.conversion_time());
42  do {
43  last = owi.alarm_search(rom, last);
44  if (last == owi.ERROR) break;
45  ASSERT(sensor.read_scratchpad(false));
46  Serial.print(timestamp);
47  Serial.print('.');
48  Serial.print(id++);
49  Serial.print(F(":rom="));
50  for (size_t i = 1; i < owi.ROM_MAX; i++) {
51  if (rom[i] < 0x10) Serial.print(0);
52  Serial.print(rom[i], HEX);
53  }
54  Serial.print(F(",temperature="));
55  Serial.println(sensor.temperature());
56  } while (last != owi.LAST);
57  timestamp += 1;
58  delay(1000);
59 }
int8_t alarm_search(uint8_t *code, int8_t last=FIRST)
Definition: OWI.h:261
static const uint8_t FAMILY_CODE
Definition: DS18B20.h:44
Error during search.
Definition: OWI.h:192
void setup()
Definition: Alarm.ino:10
bool read_scratchpad(bool match=true)
Definition: DS18B20.h:185
int8_t search_rom(uint8_t family, uint8_t *code, int8_t last=FIRST)
Definition: OWI.h:204
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
Last position, search completed.
Definition: OWI.h:193
Start position of search.
Definition: OWI.h:191
void set_trigger(int8_t low, int8_t high)
Definition: DS18B20.h:82
static const size_t ROM_MAX
Definition: OWI.h:32
float temperature() const
Definition: DS18B20.h:94
uint16_t conversion_time()
Definition: DS18B20.h:143
void loop()
Definition: Alarm.ino:28