<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Arduino中国 &#187; ds18b20</title>
	<atom:link href="http://blog.flamingoeda.com/tag/ds18b20/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.flamingoeda.com</link>
	<description>Flamingo EDA</description>
	<lastBuildDate>Mon, 02 Aug 2010 05:45:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>电子积木 数字温度传感器 DS18B20</title>
		<link>http://blog.flamingoeda.com/2009/08/22/%e7%94%b5%e5%ad%90%e7%a7%af%e6%9c%a8-%e6%95%b0%e5%ad%97%e6%b8%a9%e5%ba%a6%e4%bc%a0%e6%84%9f%e5%99%a8-ds18b20/</link>
		<comments>http://blog.flamingoeda.com/2009/08/22/%e7%94%b5%e5%ad%90%e7%a7%af%e6%9c%a8-%e6%95%b0%e5%ad%97%e6%b8%a9%e5%ba%a6%e4%bc%a0%e6%84%9f%e5%99%a8-ds18b20/#comments</comments>
		<pubDate>Sat, 22 Aug 2009 14:09:18 +0000</pubDate>
		<dc:creator>flamingoeda</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[RoR]]></category>
		<category><![CDATA[电子积木]]></category>
		<category><![CDATA[电路板]]></category>
		<category><![CDATA[ds18b20]]></category>

		<guid isPermaLink="false">http://blog.arduino.cn/?p=482</guid>
		<description><![CDATA[DS18B20是DALLAS公司推出的单线数字温度传感器，测量温度范围为 -55°C~+125°C，在-10~+85°C范围内的精度为±0.5°C，由于其优越的性价比，因此在实际项目中被大量采用。同基于热敏电阻的温度传感器不同，使用数字温度传感器避免了复杂的换算，可以直接从传感中读出温度的数值。 由于DS18B20采用的是1－Wire总线协议方式，即在一根数据线实现数据的双向传输，这对硬件上并不支持单总线协议的单片机来讲可是一个不小的麻烦，因为只能采用软件的方法来模拟单总线的协议时序，从而完成对DS18B20芯片的访问。听起来有点复杂，好在Arduino上已经有了相应的实现，并封装好了相应的库来让我们直接读出DS18B20的数据。 我们提供了DS18B20的电子积木模块，以方便在Arduino上的使用： 连接上依然使用的是通用传感器连接线和Arduino专用传感器扩展板V4，此处我们将数字温度传感器连接到了数字I/O第12号引脚上了： 硬件准备好之后，首先下载相应的软件包，并将其解压缩到Arduino安装目录下的hardware\libraries目录下： 重新启动Arduino之后，就可以在代码中使用这一为DS18B20量身打造的库了，下面是我测试时所使用的代码： #include &#60;DallasTemperature.h&#62; DallasTemperature tempSensor; void setup(void) { Serial.begin(9600); tempSensor.begin(12); // DS18B20接在数字I/O第12号引脚上 } void loop(void) { // 检查温度传感器是否正常工作 switch(tempSensor.isValid()) { case 1: Serial.println("Invalid CRC"); tempSensor.reset(); // 重置温度传感器 return; case 2: Serial.println("Not a valid device"); tempSensor.reset(); // 重置温度传感器 return; } // 从DS18B20读取温度值 Serial.print(tempSensor.getTemperature()); Serial.print("C"); Serial.println(); } 在将代码下载到Arduino中并运行起来之后，打开Arduino的串口监视工具，我们就可以看到从数字温度传感器DS18B20中读出来的温度值了：]]></description>
			<content:encoded><![CDATA[<p>DS18B20是DALLAS公司推出的单线数字温度传感器，测量温度范围为 -55°C~+125°C，在-10~+85°C范围内的精度为±0.5°C，由于其优越的性价比，因此在实际项目中被大量采用。同基于热敏电阻的温度传感器不同，使用数字温度传感器避免了复杂的换算，可以直接从传感中读出温度的数值。</p>
<p>由于DS18B20采用的是1－Wire总线协议方式，即在一根数据线实现数据的双向传输，这对硬件上并不支持单总线协议的单片机来讲可是一个不小的麻烦，因为只能采用软件的方法来模拟单总线的协议时序，从而完成对DS18B20芯片的访问。听起来有点复杂，好在<a href="http://milesburton.com/wiki/index.php?title=Dallas_Temperature_Control_Library">Arduino上已经有了相应的实现</a>，并封装好了相应的库来让我们直接读出DS18B20的数据。</p>
<p>我们提供了DS18B20的电子积木模块，以方便在Arduino上的使用：</p>
<p style="text-align: center;"><img class="aligncenter" title="DSB18B20" src="http://image.flamingoeda.com/albums/userpics/bb_digital_ds18b20_1.jpg" alt="" width="460" height="345" /></p>
<p>连接上依然使用的是通用传感器连接线和Arduino专用传感器扩展板V4，此处我们将数字温度传感器连接到了数字I/O第12号引脚上了：</p>
<p style="text-align: center;"><img class="aligncenter" title="DS18B20" src="http://image.flamingoeda.com/albums/userpics/bb_digital_ds18b20_2.jpg" alt="" width="460" height="345" /></p>
<p>硬件准备好之后，首先<a href="http://milesburton.com/downloads/Arduino/DallasTemperature/DallasTemperature.rar">下载相应的软件包</a>，并将其解压缩到Arduino安装目录下的hardware\libraries目录下：</p>
<p style="text-align: center;"><a href="http://blog.flamingoeda.com/wp-content/uploads/2009/08/ds18b20_library.jpg"><img class="size-full wp-image-483 aligncenter" title="ds18b20_library" src="http://blog.flamingoeda.com/wp-content/uploads/2009/08/ds18b20_library.jpg" alt="" width="453" height="427" /></a></p>
<p>重新启动Arduino之后，就可以在代码中使用这一为DS18B20量身打造的库了，下面是我测试时所使用的代码：</p>
<pre>
#include &lt;DallasTemperature.h&gt;

DallasTemperature tempSensor;

<span style="color: #CC6600;">void</span> <span style="color: #993300;"><b>setup</b></span>(<span style="color: #CC6600;">void</span>) {
  <span style="color: #996600;">Serial</span>.<span style="color: #996600;">begin</span>(9600);
  tempSensor.<span style="color: #996600;">begin</span>(12); <span style="color: #777755;">// DS18B20接在数字I/O第12号引脚上</span>
}

<span style="color: #CC6600;">void</span> <span style="color: #993300;"><b>loop</b></span>(<span style="color: #CC6600;">void</span>) {
    <span style="color: #777755;">// 检查温度传感器是否正常工作</span>
    <span style="color: #CC6600;">switch</span>(tempSensor.isValid())
    {
        <span style="color: #CC6600;">case</span> 1:
            <span style="color: #996600;">Serial</span>.<span style="color: #996600;">println</span>(<span style="color: #CC0000;">"Invalid CRC"</span>);
            tempSensor.reset(); <span style="color: #777755;">// 重置温度传感器</span>
            <span style="color: #CC6600;">return</span>;
        <span style="color: #CC6600;">case</span> 2:
            <span style="color: #996600;">Serial</span>.<span style="color: #996600;">println</span>(<span style="color: #CC0000;">"Not a valid device"</span>);
            tempSensor.reset(); <span style="color: #777755;">// 重置温度传感器</span>
            <span style="color: #CC6600;">return</span>;
    }

  <span style="color: #777755;">// 从DS18B20读取温度值</span>
  <span style="color: #996600;">Serial</span>.<span style="color: #996600;">print</span>(tempSensor.getTemperature());
  <span style="color: #996600;">Serial</span>.<span style="color: #996600;">print</span>(<span style="color: #CC0000;">"C"</span>);
  <span style="color: #996600;">Serial</span>.<span style="color: #996600;">println</span>();
}
</pre>
<p>在将代码下载到Arduino中并运行起来之后，打开Arduino的串口监视工具，我们就可以看到从数字温度传感器DS18B20中读出来的温度值了：</p>
<p><img class="alignnone size-full wp-image-484" title="ds18b20_result" src="http://blog.flamingoeda.com/wp-content/uploads/2009/08/ds18b20_result.jpg" alt="" width="459" height="600" /></pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.flamingoeda.com/2009/08/22/%e7%94%b5%e5%ad%90%e7%a7%af%e6%9c%a8-%e6%95%b0%e5%ad%97%e6%b8%a9%e5%ba%a6%e4%bc%a0%e6%84%9f%e5%99%a8-ds18b20/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
