OneWire DS18S20, DS18B20, DS1822 Temperature

DS18B20

The DS18B20 digital thermometer provides 9-bit to 12-bit Celsius temperature measurements and has an alarm function with nonvolatile user programmable upper and lower trigger points. The DS18B20 communicates over a 1-Wire bus that by definition requires only one data line (and ground) for communication with a central microprocessor. It has an operating temperature range of -55°C to +125°C and is accurate to ±0.5°C over the range of -10°C to +85°C. In addition, the DS18B20 can derive power directly from the data line (“parasite power”), eliminating the need for an external power supply.  分辨率9-12位,可设置报警,适用于1-Wire 总线,测量温度-55-125摄氏度
Each DS18B20 has a unique 64-bit serial code, which allows multiple DS18B20s to function on the same 1-Wire bus. Thus, it is simple to use one microprocessor to control many DS18B20s distributed over a large area. Applications that can benefit from this feature include HVAC environmental controls, temperature monitoring systems inside buildings, equipment, or machinery, and process monitoring and control systems.  一个控制器可连接多个传感器,可应用于许多领域

FEATURES 特点
§ Unique 1-Wire Interface Requires Only One Port Pin for Communication
§ Each Device has a Unique 64-Bit Serial Code Stored in an On-Board ROM
§ Multidrop Capability Simplifies Distributed Temperature-Sensing Applications
§ Requires No External Components
§ Can Be Powered from Data Line; Power Supply Range is 3.0V to 5.5V
§ Measures Temperatures from -55°C to +125°C (-67°F to +257°F)
§ ±0.5°C Accuracy from -10°C to +85°C
§ Thermometer Resolution is User Selectable from 9 to 12 Bits
§ Converts Temperature to 12-Bit Digital Word in 750ms (Max)

64-BIT LASERED ROM CODE   64位光刻ROM编码
Each DS18B20 contains a unique 64–bit code (see Figure 6) stored in ROM. The least significant 8 bits of the ROM code contain the DS18B20’s 1-Wire family code: 28h(8位家族编码). The next 48 bits contain a unique serial number(48位序列码). The most significant 8 bits contain a cyclic redundancy check (CRC) byte that is calculated from the first 56 bits of the ROM code(8位冗余检验码). A detailed explanation of the CRC bits is provided in the CRC Generation section. The 64-bit ROM code and associated ROM function control logic allow the DS18B20 to operate as a 1-Wire device using the protocol detailed in the 1-Wire Bus System section.
Figure 6. 64-Bit Lasered ROM Code

示例程序

  1 #include <OneWire.h>
2
3
4
5 // OneWire DS18S20, DS18B20, DS1822 Temperature Example
6
7 //
8
9 // http://www.pjrc.com/teensy/td_libs_OneWire.html
10
11 //
12
13 // The DallasTemperature library can do all this work for you!
14
15 // http://milesburton.com/Dallas_Temperature_Control_Library
16
17
18
19 OneWire ds(10); // on pin 10,定义单总线设备ds,连接于10号引脚
20
21
22
23 void setup(void)
24
25 {
26
27 Serial.begin(9600);
28
29 }
30
31
32
33 void loop(void)
34
35 {
36
37 byte i;
38
39 byte present = 0;
40
41 byte type_s;
42
43 byte data[12];
44
45 byte addr[8]; //传感器的ROM,共8个字节的数据,64位
46
47 float celsius, fahrenheit;
48
49
50
51 if ( !ds.search(addr)) //查询不到ds就一直查询
52
53 {
54
55 Serial.println("No more addresses.");
56
57 Serial.println();
58
59 ds.reset_search();
60
61 delay(250);
62
63 return;
64
65 }
66
67
68
69 Serial.print("ROM ="); //查询到则显示ds的地址
70
71 for( i = 0; i < 8; i++)
72
73 {
74
75 Serial.write(' ');
76
77 Serial.print(addr[i], HEX);
78
79 }
80
81
82
83 if (OneWire::crc8(addr, 7) != addr[7]) // CRC检验失败的情况
84
85 {
86
87 Serial.println("CRC is not valid!");
88
89 return;
90
91 }
92
93 Serial.println();
94
95
96
97 // the first ROM byte indicates which chip ,根据addr[0]决定DS18系列的型号
98
99 switch (addr[0])
100
101 {
102
103 case 0x10:
104
105 Serial.println(" Chip = DS18S20"); // or old DS1820
106
107 type_s = 1;
108
109 break;
110
111 case 0x28: //0x28是DS18B20的家族编码
112
113 Serial.println(" Chip = DS18B20");
114
115 type_s = 0;
116
117 break;
118
119 case 0x22:
120
121 Serial.println(" Chip = DS1822");
122
123 type_s = 0;
124
125 break;
126
127 default:
128
129 Serial.println("Device is not a DS18x20 family device.");
130
131 return;
132
133 }
134
135
136
137 ds.reset(); //复位
138
139 ds.select(addr); // 选择设备
140
141 ds.write(0x44,1);
142
143 // start conversion, with parasite power on at the end,
144
145 //传感器内部温度变换保存在暂存器,0x44是传感器的协议编码
146
147
148
149 delay(1000); // maybe 750ms is enough, maybe not
150
151 // we might do a ds.depower() here, but the reset will take care of it.
152
153
154
155 present = ds.reset(); //返回1表示有设备存在
156
157 ds.select(addr);
158
159 ds.read(0xBE); // Read Scratchpad 读暂存器,0xBE是传感器的协议编码
160
161
162
163 Serial.print(" Data = ");
164
165 Serial.print(present,HEX);
166
167 Serial.print(" ");
168
169 for ( i = 0; i < 9; i++)
170
171 { // we need 9 bytes
172
173 data[i] = ds.read();
174
175 Serial.print(data[i], HEX);
176
177 Serial.print(" ");
178
179 }
180
181 Serial.print(" CRC=");
182
183 Serial.print(OneWire::crc8(data, 8), HEX);
184
185 Serial.println();
186
187
188
189 // convert the data to actual temperature
190
191
192
193 unsigned int raw = (data[1] << 8) | data[0];
194
195 if (type_s) //DS18S20对应的温度转换
196
197 {
198
199 raw = raw << 3; // 9 bit resolution default
200
201 if (data[7] == 0x10)
202
203 {
204
205 // count remain gives full 12 bit resolution
206
207 raw = (raw & 0xFFF0) + 12 - data[6];
208
209 }
210
211 }
212
213 else //DS18B20,DS1822对应的温度转换
214
215 {
216
217 byte cfg = (data[4] & 0x60);
218
219 if (cfg == 0x00) raw = raw << 3; // 9 bit resolution, 93.75 ms
220
221 else if (cfg == 0x20) raw = raw << 2; // 10 bit res, 187.5 ms
222
223 else if (cfg == 0x40) raw = raw << 1; // 11 bit res, 375 ms
224
225 // default is 12 bit resolution, 750 ms conversion time
226
227 }
228
229 celsius = (float)raw / 16.0; //摄氏温度
230
231 fahrenheit = celsius * 1.8 + 32.0; //华氏温度
232
233 Serial.print(" Temperature = ");
234
235 Serial.print(celsius);
236
237 Serial.print(" Celsius, ");
238
239 Serial.print(fahrenheit);
240
241 Serial.println(" Fahrenheit");
242
243 }

OneWire应用 单总线温度传感器DS18系列的更多相关文章

  1. 【蓝桥杯单片机11】单总线温度传感器DS18B20的基本操作

    [蓝桥杯单片机11]单总线温度传感器DS18B20的基本操作 广东职业技术学院 欧浩源 单总线数字温度传感器DS18B20几乎成了各类单片机甚至ARM实验板的标配模块来,在蓝桥杯的往届省赛和国赛中,这 ...

  2. 玩转X-CTR100 l STM32F4 l DS18B20单总线温度传感器

    我造轮子,你造车,创客一起造起来!塔克创新资讯[塔克社区 www.xtark.cn ][塔克博客 www.cnblogs.com/xtark/ ]      本文介绍X-CTR100控制器 扩展DS1 ...

  3. EFM32JG系列MCU内部温度传感器使用方法

    在很多电子类应用场合中,我们经常需要采集产品工作的周围环境温度,一般采取的方式有两种: 1)外加温度传感器 2)采用MCU内部温度传感器 外加温度传感器会增加产品的成本以及布板空间,所以在很多场合,我 ...

  4. 「雕爷学编程」Arduino动手做(39)——DS18B20温度传感器

    37款传感器与模块的提法,在网络上广泛流传,其实Arduino能够兼容的传感器模块肯定是不止37种的.鉴于本人手头积累了一些传感器和模块,依照实践出真知(一定要动手做)的理念,以学习和交流为目的,这里 ...

  5. Arduion学习(三)驱动温度传感器

    一.实验目的: 1.将温度值打印显示在串口监视器 1.将温度值打印显示在串口,不同温度段显示不同的灯光,并在温度过高或过低时利用蜂鸣器报警. 二.实验准备: 1.查阅相关资料,了解本次实验所用到的引脚 ...

  6. 单片机学习(十二)1-Wire通信协议和DS18B20温度传感器

    目录 一.DS18B20 1. DS18B20简介 2. 电路原理图 3. 内部结构 内部完整结构框图 存储器结构 二.单总线(1-Wire BUS) 1. 单总线简介 2. 电路规范 3. 单总线的 ...

  7. DS18B20温度传感器知识点总结

    2018-01-1818:20:48 感觉自己最近有点凌乱,一个很简单的问题都能困扰自己很久.以前能很好使用和调试的DS18B20温度传感器,今天愣是搞了很久,妈卖批. 仅仅一个上拉电阻就困扰了我很久 ...

  8. Arduino入门笔记(6):温度传感器及感温杯实验

    转载请注明:@小五义 http://www.cnblogs.com/xiaowuyi 欢迎加入讨论群 64770604 一.本次实验所需器材 1.Arduino板 :https://item.taob ...

  9. 树莓派 Zero W+温度传感器DS18B20

    树莓派 Zero W+温度传感器DS18B20 作者:陈拓chentuo@ms.xab.ac.cn 2018.05.28/2018.06.01 0.  概述 用树莓派 Zero W读取DS18B20温 ...

随机推荐

  1. 文件属性及find命令总结

    第1章   文件属性 1.1   文件的属性 1.1.1    查看文件的详细属性       PS:ls查看的文件或目录默认的是按照名字的第一个字母进行正序排序       ls 参数选项: -t ...

  2. Photon PUN 二 大厅 & 房间

    一, 简介 玩过 LOL , dota2, 王者荣耀 等MOBA类的游戏,就很容易理解大厅和房间了. LOL中一个服务器就相当与一个大厅; 什么电一,电二 ,,, 联通一区等 每一个区就相当于一个大厅 ...

  3. cg语言学习&&阳春白雪GPU编程入门学习

    虽然所知甚少,但康大的<GPU编程与Cg编程之阳春白雪下里巴人>确实带我入了shader的门,在里面我第一次清晰地知道了“语义”的意思,非常感谢. 入门shader,我觉得可以先读3本书: ...

  4. JVM学习第三天(JVM的执行子系统)之类加载机制

    好几天没有学习了,前几天因为导出的事情,一直在忙,今天继续学习, 其实今天我也遇到了一个问题,如果有会的兄弟可以评论留给我谢谢; 问题:fastJSON中JSONObject.parseObject做 ...

  5. agumaster增加了网易数据源

  6. 一起来读官方文档-----SpringIOC(03)

    1.4.依存关系 典型的企业应用程序不坑你只包含单个对象或单个bean.即使是最简单的应用程序,也有一些对象可以协同工作,以呈现最终用户视为一致的应用程序.下一部分将说明如何从定义多个独立的Bean定 ...

  7. 吴恩达《深度学习》-第一门课 (Neural Networks and Deep Learning)-第三周:浅层神经网络(Shallow neural networks) -课程笔记

    第三周:浅层神经网络(Shallow neural networks) 3.1 神经网络概述(Neural Network Overview) 使用符号$ ^{[

  8. [LeetCode]695. 岛屿的最大面积(DFS/BFS)、200. 岛屿数量(DFS/BFS待做/并差集待做)

    695. 岛屿的最大面积 题目 给定一个包含了一些 0 和 1的非空二维数组 grid , 一个 岛屿 是由四个方向 (水平或垂直) 的 1 (代表土地) 构成的组合.你可以假设二维矩阵的四个边缘都被 ...

  9. NX二次开发-NX访问SqlServer数据库(增删改查)C#版

    版本:NX9+VS2012+SqlServer2008r2 以前我写过一个NX访问MySQL数据库(增删改查)的文章https://www.cnblogs.com/nxopen2018/p/12297 ...

  10. 你还在寻找Navicat的破解版本?你应该了解开源免费的DBeaver

    前言 你是否还在各个"免费绿色"的下载网站上寻找navicat的破解版本,或者已经通过某些方式破解了navicat的特定版本.你或者是在一家对安全和软件著作权比较看重的公司,明令禁 ...