-
Notifications
You must be signed in to change notification settings - Fork 0
/
ds18s20.ino
57 lines (51 loc) · 1.3 KB
/
ds18s20.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
#include "OneWire/OneWire.h"
OneWire ds = OneWire(D2); // on pin 10 (a 4.7K resistor is necessary)
unsigned long lastUpdate = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
unsigned long now = millis();
if((now - lastUpdate) > 3000)
{
lastUpdate = now;
byte i;
byte present = 0;
byte addr[8];
if ( !ds.search(addr)) {
Serial.println("No more addresses.");
Serial.println();
ds.reset_search();
//delay(250);
return;
}
// the first ROM byte indicates which chip
switch (addr[0]) {
case 0x10:
Serial.println("Chip = DS18S20"); // or old DS1820
break;
case 0x28:
Serial.println("Chip = DS18B20");
break;
case 0x22:
Serial.println("Chip = DS1822");
break;
default:
Serial.println("Device is not a DS18x20 family device.");
return;
}
Serial.print("ROM = ");
Serial.print("0x");
Serial.print(addr[0],HEX);
for( i = 1; i < 8; i++) {
Serial.print(", 0x");
Serial.print(addr[i],HEX);
}
if (OneWire::crc8(addr, 7) != addr[7]) {
Serial.println("CRC is not valid!");
return;
}
Serial.println();
ds.reset();
}
}