Difference between revisions of "Sensors: DS18B20"

From HiveTool
Jump to: navigation, search
(Read a device)
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
  
 +
<gallery>
 +
File:DS18B20-TO92.jpeg|DS18B20 TO92 case
 +
File:DS18B20.jpeg|DS18B20 stainless steel tube with leads
 +
</gallery>
  
 
+
[[File:DS18B20.pdf|Spec sheet]]
File:DS18B20.pdf
 
  
  
Line 15: Line 18:
 
allows multiple DS18B20s to function on the same 1-Wire  
 
allows multiple DS18B20s to function on the same 1-Wire  
 
bus
 
bus
 +
 +
The readings from 3 devices thermally tied together are very stable and close to each other:
 +
 +
Tue Jul 10 12:39:58 EDT 2018
 +
t=20750
 +
t=20562
 +
t=20625
 +
Tue Jul 10 12:40:30 EDT 2018
 +
t=20750
 +
t=20562
 +
t=20625
 +
Tue Jul 10 12:41:03 EDT 2018
 +
t=20750
 +
t=20562
 +
t=20625
 +
 +
Tue Jul 10 12:44:20 EDT 2018
 +
t=20750
 +
t=20562
 +
t=20625
 +
 +
===List the devices on the bus===
 +
 +
ls -l /sys/bus/w1/devices/
 +
 +
total 0
 +
lrwxrwxrwx 1 root root 0 Jul 10 12:49 00-400000000000 -> ../../../devices/w1_bus_master1/00-400000000000
 +
lrwxrwxrwx 1 root root 0 Jul 10 12:49 28-0317201a05ff -> ../../../devices/w1_bus_master1/28-0317201a05ff
 +
lrwxrwxrwx 1 root root 0 Jul 10 12:49 28-03172025fdff -> ../../../devices/w1_bus_master1/28-03172025fdff
 +
lrwxrwxrwx 1 root root 0 Jul 10 12:49 28-041720c6d4ff -> ../../../devices/w1_bus_master1/28-041720c6d4ff
 +
lrwxrwxrwx 1 root root 0 Jul  9 22:09 w1_bus_master1 -> ../../../devices/w1_bus_master1
 +
 +
Note that 00-400000000000 is a "phantom" device.
 +
 +
=== Read a device===
 +
cat /sys/bus/w1/devices/28-03172025fdff/w1_slave|grep -Eo "t=\-*[0-9]{1,5}"
 +
 +
t=20875
 +
=== Read all devices===
 +
 +
# /bin/bash
 +
#
 +
PREFIX="/sys/bus/w1/devices/"
 +
PREFIX_LEN=${#PREFIX};
 +
 +
DIRLIST=(${PREFIX}28*)
 +
 +
for FILENAME in ${DIRLIST[@]}
 +
do
 +
  DEVICE="${FILENAME:$PREFIX_LEN}";
 +
  echo -n "$DEVICE "
 +
  cat $FILENAME/w1_slave|grep -Eo "t=\-*[0-9]{1,5}"
 +
done

Latest revision as of 19:09, 16 March 2019

File:DS18B20.pdf


  1. Power supply range: 3.0V to 5.5V.
  2. Operating temperature range: -55°C to +125°C (-67°F to +257°F).
  3. Accuracy over the range of -10°C to +85°C: ±0.5°C.
  4. No other components, uses 1-Wire Bus
  5. TO-92 case or in encapsulated in stainless steel tube.
  6. Output lead: red (VCC), yellow(DATA) , black(GND).

Each DS18B20 has a unique 64-bit serial code, which allows multiple DS18B20s to function on the same 1-Wire bus

The readings from 3 devices thermally tied together are very stable and close to each other:

Tue Jul 10 12:39:58 EDT 2018
t=20750
t=20562
t=20625
Tue Jul 10 12:40:30 EDT 2018
t=20750
t=20562
t=20625
Tue Jul 10 12:41:03 EDT 2018
t=20750
t=20562
t=20625

Tue Jul 10 12:44:20 EDT 2018
t=20750
t=20562
t=20625

List the devices on the bus

ls -l /sys/bus/w1/devices/
total 0
lrwxrwxrwx 1 root root 0 Jul 10 12:49 00-400000000000 -> ../../../devices/w1_bus_master1/00-400000000000
lrwxrwxrwx 1 root root 0 Jul 10 12:49 28-0317201a05ff -> ../../../devices/w1_bus_master1/28-0317201a05ff
lrwxrwxrwx 1 root root 0 Jul 10 12:49 28-03172025fdff -> ../../../devices/w1_bus_master1/28-03172025fdff
lrwxrwxrwx 1 root root 0 Jul 10 12:49 28-041720c6d4ff -> ../../../devices/w1_bus_master1/28-041720c6d4ff
lrwxrwxrwx 1 root root 0 Jul  9 22:09 w1_bus_master1 -> ../../../devices/w1_bus_master1

Note that 00-400000000000 is a "phantom" device.

Read a device

cat /sys/bus/w1/devices/28-03172025fdff/w1_slave|grep -Eo "t=\-*[0-9]{1,5}"

t=20875

Read all devices

# /bin/bash
#
PREFIX="/sys/bus/w1/devices/"
PREFIX_LEN=${#PREFIX};

DIRLIST=(${PREFIX}28*)

for FILENAME in ${DIRLIST[@]}
do
  DEVICE="${FILENAME:$PREFIX_LEN}";
  echo -n "$DEVICE "
  cat $FILENAME/w1_slave|grep -Eo "t=\-*[0-9]{1,5}"
done