-
Notifications
You must be signed in to change notification settings - Fork 14
/
DS18B20.ino
75 lines (61 loc) · 1.68 KB
/
DS18B20.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "GPIO.h"
#include "OWI.h"
#include "Software/OWI.h"
#include "Driver/DS18B20.h"
#include "assert.h"
Software::OWI<BOARD::D7> owi;
DS18B20 sensor(owi);
void setup()
{
Serial.begin(57600);
while (!Serial);
}
void loop()
{
// Broadcast a convert request to all thermometer sensors
// Print list of sensors, rom code, and temperature
if (!sensor.convert_request(true)) return;
sensor.convert_await();
int8_t last = owi.FIRST;
uint8_t* rom = sensor.rom();
int id = 0;
do {
// Search for the next digital thermometer
last = owi.search_rom(sensor.FAMILY_CODE, rom, last);
if (last == owi.ERROR) break;
// Read the scratchpad with current temperature, tiggers, etc
sensor.read_scratchpad(false);
// Print sequence number
Serial.print(id++);
// Print family code
Serial.print(F(":family="));
Serial.print(rom[0], HEX);
// Print serial number
Serial.print(F(",sn="));
size_t i = 1;
do {
if (rom[i] < 0x10) Serial.print(0);
Serial.print(rom[i], HEX);
i += 1;
} while (i < owi.ROM_MAX - 1);
// Print cyclic redundancy check sum
Serial.print(F(",crc="));
if (rom[i] < 0x10) Serial.print(0);
Serial.print(rom[i], HEX);
// Print conversion resolution
Serial.print(F(",resolution="));
Serial.print(sensor.resolution());
// Print alarm trigger threshols
int8_t low, high;
sensor.get_trigger(low, high);
Serial.print(F(",trigger="));
Serial.print(low);
Serial.print(F(".."));
Serial.print(high);
// And temperature
Serial.print(F(",temperature="));
Serial.println(sensor.temperature());
} while (last != owi.LAST);
Serial.println();
delay(2000);
}