<?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; 电子积木</title>
	<atom:link href="http://blog.flamingoeda.com/category/%e7%94%b5%e5%ad%90%e7%a7%af%e6%9c%a8/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>电子积木 通用传感器模块</title>
		<link>http://blog.flamingoeda.com/2010/07/28/%e7%94%b5%e5%ad%90%e7%a7%af%e6%9c%a8-%e9%80%9a%e7%94%a8%e4%bc%a0%e6%84%9f%e5%99%a8%e6%a8%a1%e5%9d%97/</link>
		<comments>http://blog.flamingoeda.com/2010/07/28/%e7%94%b5%e5%ad%90%e7%a7%af%e6%9c%a8-%e9%80%9a%e7%94%a8%e4%bc%a0%e6%84%9f%e5%99%a8%e6%a8%a1%e5%9d%97/#comments</comments>
		<pubDate>Wed, 28 Jul 2010 15:22:41 +0000</pubDate>
		<dc:creator>flamingoeda</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[电子积木]]></category>

		<guid isPermaLink="false">http://blog.flamingoeda.com/?p=625</guid>
		<description><![CDATA[对于大部分简单的传感器来讲，通常有三根连接线就足够了：地GND、电源和信号，为此我们设计了这一通用传感器模块： 该模块左侧的黑色座可以通过传感器连接线连接到传感器扩展板，右侧的绿色座则可以用来连接传感器，比如下面的红外反射开关： 这样我们就可以将这些传感器连接到传感器扩展板上了，从而进一步做到同Arduino的连接：]]></description>
			<content:encoded><![CDATA[<p>对于大部分简单的传感器来讲，通常有三根连接线就足够了：地GND、电源和信号，为此我们设计了这一通用传感器模块：</p>
<p><img class="aligncenter" title="sensor" src="http://image.flamingoeda.com/albums/userpics/febb_general_sensor_1.JPG" alt="" width="460" height="345" /></p>
<p>该模块左侧的黑色座可以通过传感器连接线连接到传感器扩展板，右侧的绿色座则可以用来连接传感器，比如下面的红外反射开关：</p>
<p><img class="aligncenter" title="sensor" src="http://image.flamingoeda.com/albums/userpics/febb_general_sensor_2.JPG" alt="" width="460" height="345" />这样我们就可以将这些传感器连接到传感器扩展板上了，从而进一步做到同Arduino的连接：</p>
<p><img class="aligncenter" title="sensor" src="http://image.flamingoeda.com/albums/userpics/febb_general_sensor_3.JPG" alt="" width="460" height="251" /></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.flamingoeda.com/2010/07/28/%e7%94%b5%e5%ad%90%e7%a7%af%e6%9c%a8-%e9%80%9a%e7%94%a8%e4%bc%a0%e6%84%9f%e5%99%a8%e6%a8%a1%e5%9d%97/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Arduino 电子积木 专用传感器扩展板 V5</title>
		<link>http://blog.flamingoeda.com/2010/07/28/arduino-%e7%94%b5%e5%ad%90%e7%a7%af%e6%9c%a8-%e4%b8%93%e7%94%a8%e4%bc%a0%e6%84%9f%e5%99%a8%e6%89%a9%e5%b1%95%e6%9d%bf-v5/</link>
		<comments>http://blog.flamingoeda.com/2010/07/28/arduino-%e7%94%b5%e5%ad%90%e7%a7%af%e6%9c%a8-%e4%b8%93%e7%94%a8%e4%bc%a0%e6%84%9f%e5%99%a8%e6%89%a9%e5%b1%95%e6%9d%bf-v5/#comments</comments>
		<pubDate>Wed, 28 Jul 2010 14:37:49 +0000</pubDate>
		<dc:creator>flamingoeda</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[扩展板]]></category>
		<category><![CDATA[电子积木]]></category>

		<guid isPermaLink="false">http://blog.flamingoeda.com/?p=622</guid>
		<description><![CDATA[继Arduino电子积木专用传感器扩展板V4之后，我们推出了新一版本的Arduino电子积木专用传感器扩展板V5： 与V4相比，V5的改动并不算太大，主要是在吸收了用户的反馈意见后，将COM和I2C的接口分开了，这样就可以同时连接基于串口的模块（如串行LCD）或者IIC接口的模块（如EEPROM存储模块）。这一改动同时导致端口0,1,2,3的位置下移了： 至于使用方法则基本上没有做什么改动，仍然是直接插在Arduino的标准版本（如Arduino 2009)就可以了：]]></description>
			<content:encoded><![CDATA[<p>继<a href="http://blog.flamingoeda.com/2008/12/17/arduino-%E7%94%B5%E5%AD%90%E7%A7%AF%E6%9C%A8-%E4%B8%93%E7%94%A8%E4%BC%A0%E6%84%9F%E5%99%A8%E6%89%A9%E5%B1%95%E6%9D%BF-v4/">Arduino电子积木专用传感器扩展板V4</a>之后，我们推出了新一版本的Arduino电子积木专用传感器扩展板V5：</p>
<p><img class="aligncenter" title="v5" src="http://image.flamingoeda.com/albums/userpics/arduino_sensor_shield_v5.JPG" alt="" width="460" height="345" />与V4相比，V5的改动并不算太大，主要是在吸收了用户的反馈意见后，将COM和I2C的接口分开了，这样就可以同时连接基于串口的模块（如串行LCD）或者IIC接口的模块（如EEPROM存储模块）。这一改动同时导致端口0,1,2,3的位置下移了：</p>
<p><img class="aligncenter" title="v5" src="http://image.flamingoeda.com/albums/userpics/arduino_sensor_shield_v5_1.JPG" alt="" width="460" height="345" /></p>
<p>至于使用方法则基本上没有做什么改动，仍然是直接插在Arduino的标准版本（如Arduino 2009)就可以了：</p>
<p><img class="aligncenter" title="v5" src="http://image.flamingoeda.com/albums/userpics/arduino_sensor_shield_v5_2.JPG" alt="" width="460" height="345" /></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.flamingoeda.com/2010/07/28/arduino-%e7%94%b5%e5%ad%90%e7%a7%af%e6%9c%a8-%e4%b8%93%e7%94%a8%e4%bc%a0%e6%84%9f%e5%99%a8%e6%89%a9%e5%b1%95%e6%9d%bf-v5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>电子积木 EEPROM 存储模块</title>
		<link>http://blog.flamingoeda.com/2010/07/18/%e7%94%b5%e5%ad%90%e7%a7%af%e6%9c%a8-eeprom-%e5%ad%98%e5%82%a8%e6%a8%a1%e5%9d%97/</link>
		<comments>http://blog.flamingoeda.com/2010/07/18/%e7%94%b5%e5%ad%90%e7%a7%af%e6%9c%a8-eeprom-%e5%ad%98%e5%82%a8%e6%a8%a1%e5%9d%97/#comments</comments>
		<pubDate>Sun, 18 Jul 2010 05:39:38 +0000</pubDate>
		<dc:creator>flamingoeda</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[电子积木]]></category>
		<category><![CDATA[EEPROM]]></category>

		<guid isPermaLink="false">http://blog.flamingoeda.com/?p=616</guid>
		<description><![CDATA[如果你的Arduino中要做少量的数据存储，那么使用EEPROM可能是最简单易行的做法了。其实Arduino所使用的芯片ATmega本身就具备一定的EEPROM存储器，只不过数量有限罢了。我们设计的这款外置式EEPROM存储模块使用I2C总线来与Arduino进行连接，并且采用可插拔的芯片，直插式系列，这样在扩展容量时会比较容易，基本上只需要按一个更大容量的EEPROM芯片就可以了。 该存储模块上使用的是AT24C系列的EEPROM芯片，其I2C基地址为0&#215;50，最后三位地址可以根据应用需要进行设置。因此使用时我们首先要对其地址的最后三位进行设置，这是通过4位拨码开关上的A2，A1和A0来完成的，其中A0表示地址的最后一位。拨码开关向上推时相应的位为1，向下推时相应的位为0。也就是说，如果将A2，A1，A0都拨到上方时，相应的地址为0&#215;57；而如果将A2，A1，A0都拨到下方时，相应的地址为0&#215;50。 该存储模块上另外一个需要设置的地方就是开关RS，它是用来设置是否往I2C总线上的SDA和SCL上接入板载的上拉电阻。我们知道，I2C之所以被称为总线，就是因为可以连接多个I2C设备，接照I2C协议的规定，只允许在离控制器最近的一个I2C设备处接上拉电阻。说到这里你可能已经明白了，如果有多个这个的存储模块连接到Arduino的I2C总线上时，我们必须将第一个（离Arduino最近）存储模块的RS开关设置到ON的位置，而其它存储模块上的RS则不能设置到ON的位置： 如果使用的是Arduino专用传感器扩展扩展板V4，注意IIC/COM跳线的位置要设置到IIC这一边，因为此时我们需要用到I2C连接方式： 上述设置完成之后，我们只需要用I2C/COM连接线将EEPROM存储模块连接到传感器扩展板上就完成硬件的连接了： 至于软件部分，Arduino的官方网站上提供了两个不错的链接：I2CEEPROM和TWIPROM，需要的话可以参考。下面是我们测试时所用的代码： #include &#60;Wire.h&#62; #define EEPROM_ADDR 0x50           // I2C Buss address of 24LC256 256K EEPROM void setup() {   Wire.begin(); // join I2C bus (address optional for master)   Serial.begin(9600);   // TESTS FOR EACH FUNCTION BEGIN HERE   Serial.println("Writing Test:");   for (int i=0; i&#60;20; i++){ // loop for first 20 slots     i2c_eeprom_write_byte(EEPROM_ADDR,i,i+65);   // write address + 65 A or [...]]]></description>
			<content:encoded><![CDATA[<p>如果你的Arduino中要做少量的数据存储，那么使用EEPROM可能是最简单易行的做法了。其实Arduino所使用的芯片ATmega本身就具备一定的EEPROM存储器，只不过数量有限罢了。我们设计的这款外置式EEPROM存储模块使用I2C总线来与Arduino进行连接，并且采用可插拔的芯片，直插式系列，这样在扩展容量时会比较容易，基本上只需要按一个更大容量的EEPROM芯片就可以了。<br />
<img class="aligncenter" title="eeprom" src="http://image.flamingoeda.com/albums/userpics/febb_eeprom_1.JPG" alt="" width="460" height="345" /><br />
该存储模块上使用的是AT24C系列的EEPROM芯片，其I2C基地址为0&#215;50，最后三位地址可以根据应用需要进行设置。因此使用时我们首先要对其地址的最后三位进行设置，这是通过4位拨码开关上的A2，A1和A0来完成的，其中A0表示地址的最后一位。拨码开关向上推时相应的位为1，向下推时相应的位为0。也就是说，如果将A2，A1，A0都拨到上方时，相应的地址为0&#215;57；而如果将A2，A1，A0都拨到下方时，相应的地址为0&#215;50。<br />
<img class="aligncenter" title="eeprom" src="http://image.flamingoeda.com/albums/userpics/febb_eeprom_2.JPG" alt="" width="230" height="173" /><br />
该存储模块上另外一个需要设置的地方就是开关RS，它是用来设置是否往I2C总线上的SDA和SCL上接入板载的上拉电阻。我们知道，I2C之所以被称为总线，就是因为可以连接多个I2C设备，接照I2C协议的规定，只允许在离控制器最近的一个I2C设备处接上拉电阻。说到这里你可能已经明白了，如果有多个这个的存储模块连接到Arduino的I2C总线上时，我们必须将第一个（离Arduino最近）存储模块的RS开关设置到ON的位置，而其它存储模块上的RS则不能设置到ON的位置：<br />
<img class="aligncenter" title="eeprom" src="http://image.flamingoeda.com/albums/userpics/febb_rtc_ds1307_2.JPG" alt="" width="230" height="173" /><br />
如果使用的是Arduino专用传感器扩展扩展板V4，注意IIC/COM跳线的位置要设置到IIC这一边，因为此时我们需要用到I2C连接方式：<br />
<img class="aligncenter" title="eeprom" src="http://image.flamingoeda.com/albums/userpics/febb_eeprom_3.JPG" alt="" width="230" height="173" /><br />
上述设置完成之后，我们只需要用I2C/COM连接线将EEPROM存储模块连接到传感器扩展板上就完成硬件的连接了：<br />
<img class="aligncenter" title="eeprom" src="http://image.flamingoeda.com/albums/userpics/febb_eeprom_4.JPG" alt="" width="460" height="345" /><br />
至于软件部分，Arduino的官方网站上提供了两个不错的链接：<a href="http://www.arduino.cc/playground/Code/I2CEEPROM">I2CEEPROM</a>和<a href="http://www.arduino.cc/playground/Code/TWIPROM">TWIPROM</a>，需要的话可以参考。下面是我们测试时所用的代码：</p>
<pre>#include &lt;<span style="color: #cc6600;">Wire</span>.h&gt;
#define EEPROM_ADDR 0x50           <span style="color: #7e7e7e;">// I2C Buss address of 24LC256 256K EEPROM</span>

<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><strong>setup</strong></span>()
{
  <span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">begin</span>();                        <span style="color: #7e7e7e;">// join I2C bus (address optional for master)</span>
  <span style="color: #cc6600;"><strong>Serial</strong></span>.<span style="color: #cc6600;">begin</span>(9600);

  <span style="color: #7e7e7e;">// TESTS FOR EACH FUNCTION BEGIN HERE</span>
  <span style="color: #cc6600;"><strong>Serial</strong></span>.<span style="color: #cc6600;">println</span>(<span style="color: #006699;">"Writing Test:"</span>);
  <span style="color: #cc6600;">for</span> (<span style="color: #cc6600;">int</span> i=0; i&lt;20; i++){            <span style="color: #7e7e7e;">// loop for first 20 slots</span>
    i2c_eeprom_write_byte(EEPROM_ADDR,i,i+65);   <span style="color: #7e7e7e;">// write address + 65 A or 97 a</span>
    <span style="color: #cc6600;"><strong>Serial</strong></span>.<span style="color: #cc6600;">print</span>(<span style="color: #006699;">". "</span>);
    <span style="color: #cc6600;">delay</span>(10);                         <span style="color: #7e7e7e;">// NEED THIS DELAY!</span>
  }
  <span style="color: #cc6600;"><strong>Serial</strong></span>.<span style="color: #cc6600;">println</span>(<span style="color: #006699;">""</span>);
  <span style="color: #cc6600;">delay</span>(500);

  <span style="color: #cc6600;"><strong>Serial</strong></span>.<span style="color: #cc6600;">println</span>(<span style="color: #006699;">"Reading Test:"</span>);
  <span style="color: #cc6600;">for</span> (<span style="color: #cc6600;">int</span> i=0; i&lt;20; i++){            <span style="color: #7e7e7e;">// loop for first 20 slots</span>
    <span style="color: #cc6600;"><strong>Serial</strong></span>.<span style="color: #cc6600;">print</span>(i2c_eeprom_read_byte(EEPROM_ADDR, i),<span style="color: #006699;">BYTE</span>);
    <span style="color: #cc6600;"><strong>Serial</strong></span>.<span style="color: #cc6600;">print</span>(<span style="color: #006699;">" "</span>);
  }

  <span style="color: #7e7e7e;">// setup for page tests . . .</span>
  <span style="color: #cc6600;">byte</span> PageData[30];                   <span style="color: #7e7e7e;">// array that will hold test data for a page</span>
  <span style="color: #cc6600;">byte</span> PageRead[30];                   <span style="color: #7e7e7e;">// array that will hold result of data for a page</span>
  <span style="color: #cc6600;">for</span> (<span style="color: #cc6600;">int</span> i=0; i&lt;30; i++){            <span style="color: #7e7e7e;">// zero both arrays for next test</span>
    PageData[i] = 0;
    PageRead[i] = 0;
  }
  <span style="color: #cc6600;"><strong>Serial</strong></span>.<span style="color: #cc6600;">println</span>(<span style="color: #006699;">""</span>);
  <span style="color: #cc6600;">for</span> (<span style="color: #cc6600;">int</span> i=0; i&lt;30; i++) PageData[i] = i+33;  <span style="color: #7e7e7e;">// fill up array for next test char 33 = !</span>

  <span style="color: #cc6600;"><strong>Serial</strong></span>.<span style="color: #cc6600;">println</span>(<span style="color: #006699;">"Writing Page Test:"</span>);
  i2c_eeprom_write_page(EEPROM_ADDR, 100, PageData, 28 ); <span style="color: #7e7e7e;">// 28 bytes/page is max</span>

  <span style="color: #cc6600;"><strong>Serial</strong></span>.<span style="color: #cc6600;">println</span>(<span style="color: #006699;">"Reading Page Test:"</span>);
  i2c_eeprom_read_buffer( EEPROM_ADDR, 100, PageRead, 28);
  <span style="color: #cc6600;">for</span> (<span style="color: #cc6600;">int</span> i=0; i&lt;28; i++){
    <span style="color: #cc6600;"><strong>Serial</strong></span>.<span style="color: #cc6600;">print</span>(PageRead[i],<span style="color: #006699;">BYTE</span>);    <span style="color: #7e7e7e;">// display the array read</span>
    <span style="color: #cc6600;"><strong>Serial</strong></span>.<span style="color: #cc6600;">print</span>(<span style="color: #006699;">" "</span>);
  }
}

<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><strong>loop</strong></span>()
{
}

<span style="color: #cc6600;">void</span> i2c_eeprom_write_byte( <span style="color: #cc6600;">int</span> deviceaddress, <span style="color: #cc6600;">unsigned</span> <span style="color: #cc6600;">int</span> eeaddress, <span style="color: #cc6600;">byte</span> data )
{
  <span style="color: #cc6600;">int</span> rdata = data;
  <span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">beginTransmission</span>(deviceaddress);
  <span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">send</span>((<span style="color: #cc6600;">int</span>)(eeaddress &gt;&gt; 8));    <span style="color: #7e7e7e;">// Address High Byte</span>
  <span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">send</span>((<span style="color: #cc6600;">int</span>)(eeaddress &amp; 0xFF));  <span style="color: #7e7e7e;">// Address Low Byte</span>
  <span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">send</span>(rdata);
  <span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">endTransmission</span>();
}

<span style="color: #7e7e7e;">// Address is a page address, 6-bit (63). More and end will wrap around</span>
<span style="color: #7e7e7e;">// But data can be maximum of 28 bytes, because the Wire library has a buffer of 32 bytes</span>
<span style="color: #cc6600;">void</span> i2c_eeprom_write_page( <span style="color: #cc6600;">int</span> deviceaddress, <span style="color: #cc6600;">unsigned</span> <span style="color: #cc6600;">int</span> eeaddresspage, <span style="color: #cc6600;">byte</span>* data, <span style="color: #cc6600;">byte</span> length )
{
  <span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">beginTransmission</span>(deviceaddress);
  <span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">send</span>((<span style="color: #cc6600;">int</span>)(eeaddresspage &gt;&gt; 8)); <span style="color: #7e7e7e;">// Address High Byte</span>
  <span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">send</span>((<span style="color: #cc6600;">int</span>)(eeaddresspage &amp; 0xFF)); <span style="color: #7e7e7e;">// Address Low Byte</span>
  <span style="color: #cc6600;">byte</span> c;
  <span style="color: #cc6600;">for</span> ( c = 0; c &lt; length; c++)
    <span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">send</span>(data[c]);
  <span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">endTransmission</span>();
  <span style="color: #cc6600;">delay</span>(10);                           <span style="color: #7e7e7e;">// need some delay</span>
}

<span style="color: #cc6600;">byte</span> i2c_eeprom_read_byte( <span style="color: #cc6600;">int</span> deviceaddress, <span style="color: #cc6600;">unsigned</span> <span style="color: #cc6600;">int</span> eeaddress )
{
  <span style="color: #cc6600;">byte</span> rdata = 0xFF;
  <span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">beginTransmission</span>(deviceaddress);
  <span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">send</span>((<span style="color: #cc6600;">int</span>)(eeaddress &gt;&gt; 8));    <span style="color: #7e7e7e;">// Address High Byte</span>
  <span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">send</span>((<span style="color: #cc6600;">int</span>)(eeaddress &amp; 0xFF));  <span style="color: #7e7e7e;">// Address Low Byte</span>
  <span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">endTransmission</span>();
  <span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">requestFrom</span>(deviceaddress,1);
  <span style="color: #cc6600;">if</span> (<span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">available</span>()) rdata = <span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">receive</span>();
  <span style="color: #cc6600;">return</span> rdata;
}

<span style="color: #7e7e7e;">// should not read more than 28 bytes at a time!</span>
<span style="color: #cc6600;">void</span> i2c_eeprom_read_buffer( <span style="color: #cc6600;">int</span> deviceaddress, <span style="color: #cc6600;">unsigned</span> <span style="color: #cc6600;">int</span> eeaddress, <span style="color: #cc6600;">byte</span> *buffer, <span style="color: #cc6600;">int</span> length )
{
  <span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">beginTransmission</span>(deviceaddress);
  <span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">send</span>((<span style="color: #cc6600;">int</span>)(eeaddress &gt;&gt; 8));    <span style="color: #7e7e7e;">// Address High Byte</span>
  <span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">send</span>((<span style="color: #cc6600;">int</span>)(eeaddress &amp; 0xFF));  <span style="color: #7e7e7e;">// Address Low Byte</span>
  <span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">endTransmission</span>();
  <span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">requestFrom</span>(deviceaddress,length);
  <span style="color: #7e7e7e;">//int c = 0;</span>
  <span style="color: #cc6600;">for</span> ( <span style="color: #cc6600;">int</span> c = 0; c &lt; length; c++ )
    <span style="color: #cc6600;">if</span> (<span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">available</span>()) buffer[c] = <span style="color: #cc6600;">Wire</span>.<span style="color: #cc6600;">receive</span>();
}
</pre>
<p>上述代码运行时的效果如下图所示：</p>
<p><a href="http://blog.flamingoeda.com/wp-content/uploads/2010/07/febb_eeprom_5.jpg"><img class="aligncenter size-medium wp-image-620" title="febb_eeprom_5" src="http://blog.flamingoeda.com/wp-content/uploads/2010/07/febb_eeprom_5-260x300.jpg" alt="" width="260" height="300" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.flamingoeda.com/2010/07/18/%e7%94%b5%e5%ad%90%e7%a7%af%e6%9c%a8-eeprom-%e5%ad%98%e5%82%a8%e6%a8%a1%e5%9d%97/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>电子积木 实时钟模块 RTC DS1307</title>
		<link>http://blog.flamingoeda.com/2010/07/16/%e7%94%b5%e5%ad%90%e7%a7%af%e6%9c%a8-%e5%ae%9e%e6%97%b6%e9%92%9f%e6%a8%a1%e5%9d%97-rtc-ds1307/</link>
		<comments>http://blog.flamingoeda.com/2010/07/16/%e7%94%b5%e5%ad%90%e7%a7%af%e6%9c%a8-%e5%ae%9e%e6%97%b6%e9%92%9f%e6%a8%a1%e5%9d%97-rtc-ds1307/#comments</comments>
		<pubDate>Fri, 16 Jul 2010 15:45:25 +0000</pubDate>
		<dc:creator>flamingoeda</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[电子积木]]></category>
		<category><![CDATA[实时钟]]></category>
		<category><![CDATA[DS1307]]></category>
		<category><![CDATA[RTC]]></category>

		<guid isPermaLink="false">http://blog.flamingoeda.com/?p=607</guid>
		<description><![CDATA[实时钟通常也被称为实时时钟，它能够向电子电路提供日期和时间信息，包括年、月、日、时、分、秒，被广泛应用在需要进行计时的场合中。许多实时钟电路还提供电池供电的方式，这样在发生掉电时仍能准确计时。通常说来，功能稍多一点的实时钟电路还会提供包括警报、看门狗，以及支持高精度要求的校准寄存器等附加功能。 DS1307是DALLAS公司的一款实时种芯片，采用I2C协议与单片机通讯，而Arduino上正好有这一接口，因此连接起来就非常方便了。DS1307中有一个可编程波形输出口，它可以用来驱动LED小灯，或者作为中断来触发某些事件，不过用它去带一些大功率的东西的时候要注意。我们设计的这一款实时钟模块，将Ds1307的I2C接口和可编程波形输出接口SQW都连接出来了，不过一般情况下我们只会用到I2C接口来实现基本的时钟设置/读取功能。需要注意的是，该模块必须先安装上电池才可以正常工作。电池使用的是纽扣电池（型号CR1220），正极朝上： 在电路连接上我们可以使用Arduino专用传感器扩展板V4，不过要将相应的跳线设置到IIC的位置上： 剩下的工作就是用4芯的I2C/COM连接线将传感器扩展板上的专用接口，与实时钟模块上的IIC（I2C其实就是IIC的缩写）端口连接起来了： 硬件连接的工作完成之后，如何在Arduino里对该模块进行编程呢？上网搜索了一下，发现在Arduino上使用DS1307做为时钟芯片的玩家还真不少，而且还封装好了相应的Arduino库，实验时我使用的是Google Code上的这个DS1307库，你也可以在这里下载到我使用的版本。将下载好的压缩文件解压缩到Arduino 0018的libraries目录下后，重新启动Arduino并用它自带的测试程序进行测试： #include &#60;WProgram.h&#62; #include &#60;Wire.h&#62; #include &#60;DS1307.h&#62; // written by mattt on the Arduino forum and modified by D. Sjunnesson void setup() {   Serial.begin(9600);   RTC.stop();   RTC.set(DS1307_SEC,1);        //set the seconds   RTC.set(DS1307_MIN,23);     //set the minutes   RTC.set(DS1307_HR,12);       //set the hours   RTC.set(DS1307_DOW,4);       //set the day of the week   RTC.set(DS1307_DATE,15);       //set the date   RTC.set(DS1307_MTH,7);        //set the month   RTC.set(DS1307_YR,10);         //set the year   RTC.start(); } void loop() [...]]]></description>
			<content:encoded><![CDATA[<p>实时钟通常也被称为实时时钟，它能够向电子电路提供日期和时间信息，包括年、月、日、时、分、秒，被广泛应用在需要进行计时的场合中。许多实时钟电路还提供电池供电的方式，这样在发生掉电时仍能准确计时。通常说来，功能稍多一点的实时钟电路还会提供包括警报、看门狗，以及支持高精度要求的校准寄存器等附加功能。</p>
<p>DS1307是DALLAS公司的一款实时种芯片，采用I2C协议与单片机通讯，而Arduino上正好有这一接口，因此连接起来就非常方便了。DS1307中有一个可编程波形输出口，它可以用来驱动LED小灯，或者作为中断来触发某些事件，不过用它去带一些大功率的东西的时候要注意。我们设计的这一款实时钟模块，将Ds1307的I2C接口和可编程波形输出接口SQW都连接出来了，不过一般情况下我们只会用到I2C接口来实现基本的时钟设置/读取功能。需要注意的是，该模块必须先安装上电池才可以正常工作。电池使用的是纽扣电池（型号CR1220），正极朝上：</p>
<p><img class="aligncenter" title="rtc" src="http://image.flamingoeda.com/albums/userpics/febb_rtc_ds1307_1.JPG" alt="" width="460" height="345" /></p>
<p>在电路连接上我们可以使用Arduino专用传感器扩展板V4，不过要将相应的跳线设置到IIC的位置上：</p>
<p><img class="aligncenter" title="rtc" src="http://image.flamingoeda.com/albums/userpics/febb_rtc_ds1307_2.JPG" alt="" width="230" height="173" /></p>
<p>剩下的工作就是用4芯的I2C/COM连接线将传感器扩展板上的专用接口，与实时钟模块上的IIC（I2C其实就是IIC的缩写）端口连接起来了：</p>
<p><img class="aligncenter" title="rtc" src="http://image.flamingoeda.com/albums/userpics/febb_rtc_ds1307_3.JPG" alt="" width="460" height="345" /></p>
<p>硬件连接的工作完成之后，如何在Arduino里对该模块进行编程呢？上网搜索了一下，发现在Arduino上使用DS1307做为时钟芯片的玩家还真不少，而且还封装好了相应的Arduino库，实验时我使用的是<a href="http://code.google.com/p/ds1307/downloads/list">Google Code上的这个DS1307库</a>，你也可以<a href="http://blog.flamingoeda.com/wp-content/uploads/2010/07/DS1307.zip">在这里下载</a>到我使用的版本。将下载好的压缩文件解压缩到Arduino 0018的libraries目录下后，重新启动Arduino并用它自带的测试程序进行测试：</p>
<pre>#include &lt;<span style="color: #cc6600;">WProgram</span>.h&gt;
#include &lt;<span style="color: #cc6600;">Wire</span>.h&gt;
#include &lt;<span style="color: #cc6600;">DS1307</span>.h&gt; <span style="color: #7e7e7e;">// written by  mattt on the Arduino forum and modified by D. Sjunnesson</span>

<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><strong>setup</strong></span>()
{
  <span style="color: #cc6600;"><strong>Serial</strong></span>.<span style="color: #cc6600;">begin</span>(9600);

  RTC.<span style="color: #cc6600;">stop</span>();
  RTC.set(DS1307_SEC,1);        <span style="color: #7e7e7e;">//set the seconds</span>
  RTC.set(DS1307_MIN,23);     <span style="color: #7e7e7e;">//set the minutes</span>
  RTC.set(DS1307_HR,12);       <span style="color: #7e7e7e;">//set the hours</span>
  RTC.set(DS1307_DOW,4);       <span style="color: #7e7e7e;">//set the day of the week</span>
  RTC.set(DS1307_DATE,15);       <span style="color: #7e7e7e;">//set the date</span>
  RTC.set(DS1307_MTH,7);        <span style="color: #7e7e7e;">//set the month</span>
  RTC.set(DS1307_YR,10);         <span style="color: #7e7e7e;">//set the year</span>
  RTC.start();

}

<span style="color: #cc6600;">void</span> <span style="color: #cc6600;"><strong>loop</strong></span>()
{

  <span style="color: #cc6600;"><strong>Serial</strong></span>.<span style="color: #cc6600;">print</span>(RTC.get(DS1307_HR,<span style="color: #cc6600;">true</span>)); <span style="color: #7e7e7e;">//read the hour and also update all the values by pushing in true</span>
  <span style="color: #cc6600;"><strong>Serial</strong></span>.<span style="color: #cc6600;">print</span>(<span style="color: #006699;">":"</span>);
  <span style="color: #cc6600;"><strong>Serial</strong></span>.<span style="color: #cc6600;">print</span>(RTC.get(DS1307_MIN,<span style="color: #cc6600;">false</span>));<span style="color: #7e7e7e;">//read minutes without update (false)</span>
  <span style="color: #cc6600;"><strong>Serial</strong></span>.<span style="color: #cc6600;">print</span>(<span style="color: #006699;">":"</span>);
  <span style="color: #cc6600;"><strong>Serial</strong></span>.<span style="color: #cc6600;">print</span>(RTC.get(DS1307_SEC,<span style="color: #cc6600;">false</span>));<span style="color: #7e7e7e;">//read seconds</span>
  <span style="color: #cc6600;"><strong>Serial</strong></span>.<span style="color: #cc6600;">print</span>(<span style="color: #006699;">"      "</span>);                 <span style="color: #7e7e7e;">// some space for a more happy life</span>
  <span style="color: #cc6600;"><strong>Serial</strong></span>.<span style="color: #cc6600;">print</span>(RTC.get(DS1307_DATE,<span style="color: #cc6600;">false</span>));<span style="color: #7e7e7e;">//read date</span>
  <span style="color: #cc6600;"><strong>Serial</strong></span>.<span style="color: #cc6600;">print</span>(<span style="color: #006699;">"/"</span>);
  <span style="color: #cc6600;"><strong>Serial</strong></span>.<span style="color: #cc6600;">print</span>(RTC.get(DS1307_MTH,<span style="color: #cc6600;">false</span>));<span style="color: #7e7e7e;">//read month</span>
  <span style="color: #cc6600;"><strong>Serial</strong></span>.<span style="color: #cc6600;">print</span>(<span style="color: #006699;">"/"</span>);
  <span style="color: #cc6600;"><strong>Serial</strong></span>.<span style="color: #cc6600;">print</span>(RTC.get(DS1307_YR,<span style="color: #cc6600;">false</span>)); <span style="color: #7e7e7e;">//read year </span>
  <span style="color: #cc6600;"><strong>Serial</strong></span>.<span style="color: #cc6600;">println</span>();

  <span style="color: #cc6600;">delay</span>(1000);
}
</pre>
<p>程序读起来应该不算困难，基本上就是使用RTC.set来对时钟进行设置，然后就可以通过RTC.get来读取相应的时间信息了，至于时钟怎么维护，那就是 DS1307 的工作了:)</p>
<p>将程序下载到Arduino里并运行起来之后，就可以通过串口监控窗口来查看相应的输出结果了：<br />
<a href="http://blog.flamingoeda.com/wp-content/uploads/2010/07/febb_rtc_ds1307_4.jpg"><img class="aligncenter size-medium wp-image-610" title="febb_rtc_ds1307_4" src="http://blog.flamingoeda.com/wp-content/uploads/2010/07/febb_rtc_ds1307_4-260x300.jpg" alt="" width="260" height="300" /></a>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.flamingoeda.com/2010/07/16/%e7%94%b5%e5%ad%90%e7%a7%af%e6%9c%a8-%e5%ae%9e%e6%97%b6%e9%92%9f%e6%a8%a1%e5%9d%97-rtc-ds1307/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>电子积木 无线数传模块 APC220</title>
		<link>http://blog.flamingoeda.com/2010/07/06/%e7%94%b5%e5%ad%90%e7%a7%af%e6%9c%a8-%e6%97%a0%e7%ba%bf%e6%95%b0%e4%bc%a0%e6%a8%a1%e5%9d%97-apc220/</link>
		<comments>http://blog.flamingoeda.com/2010/07/06/%e7%94%b5%e5%ad%90%e7%a7%af%e6%9c%a8-%e6%97%a0%e7%ba%bf%e6%95%b0%e4%bc%a0%e6%a8%a1%e5%9d%97-apc220/#comments</comments>
		<pubDate>Tue, 06 Jul 2010 10:24:00 +0000</pubDate>
		<dc:creator>flamingoeda</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[电子积木]]></category>
		<category><![CDATA[APC220]]></category>
		<category><![CDATA[无线]]></category>

		<guid isPermaLink="false">http://blog.flamingoeda.com/?p=594</guid>
		<description><![CDATA[在使用APC220实现Arduino无线数据传输那篇文章里，我们介绍了如何使用APC220模块在PC和Arduino间实现无线数据传输。那时我们使用的是厂家提供的USB适配器。，由于这个适配器只能接APC220模块，而不能起到其它的作用，或多或少觉得有些浪费。更加重要的是，为此我们得提供两个不同的套件，一个给Arduino使用，一个给PC使用，两者之间不能实现互换。 正是基于上面的这些问题，我们针对电子积木系列开发了一款USB转串口的适配器Serial Dongle，使用它就可以通过PC机来连接和使用各种基于串口的电子积木模块了，比如这里介绍的无线数传模块APC220。 APC220模块的使用可以参考使用APC220实现Arduino无线数据传输那篇文章，两者间的唯一区别只在于如何对USB虚拟出来的串口进行设置，以便能够使用厂家提供的设置程序RF-ANET来对APC220的各个参数进行调整。首先我们将USB转串口适配器Serial Dongle连接到PC机上，然后从设备管理器中找到该串口，并打开其属性设置窗口： 点击Advanced按钮打开高级属性设置窗口，我们需要从Com Port Number列表中为Serial Dongle设置一个较小的COM号（如COM5），否则厂家给的设置程序会出现无法打开该串口的错识。另一个需要修改的地方是BM Options中的延时设置需要从16改为更小的值（如8）： 现在可以运行厂家给的设置程序了，此时特别需要注意的是操作顺序。应该先接好Serial Dongle，并将Serial Dongle右上角的开关拨到M的位置： 接着运行设置程序RF-ANET，最后再用连接线将APC220模块连接到Serial Dongle上，此时应该可以看到APC220设置程序窗口的最下面会显示Found device，表明APC220模块已经成功找到。如果设置程序没有找到APC220模块，可以试着断开APC220与Serial Dongle的连接，然后再次将APC220模块连接到SerialDongle上，直到设置程序成功找到APC220模块。 当APC220模块成功地被设置程序RF-ANET找到之后，我们就可以按照实际的需要来使用Serial Dongle对APC220模块进行各种参数配置了，而不再依赖厂家提供的USB适配器了;-) 至于随后的使用过程，那就完全一致了。一方面，我们可以将APC220模块通过4芯的串口连接线，与Arduino传感器扩展板相连接，这样Arduino就可以通过串口来操作APC220模块实现无线数据的收发： 另一方面，我们可以通过Serial Dongle连接APC220模块与电脑，并通过电脑的串口读写功能来操作APC220模块实现无线数据的收发： 下图就是利用两个APC220模块实现Arduino与电脑间无线数据传输的连接图：]]></description>
			<content:encoded><![CDATA[<p>在<a href="http://blog.flamingoeda.com/2009/06/14/%E4%BD%BF%E7%94%A8apc220%E5%AE%9E%E7%8E%B0arduino%E6%97%A0%E7%BA%BF%E6%95%B0%E6%8D%AE%E4%BC%A0%E8%BE%93/" target="_blank">使用APC220实现Arduino无线数据传输</a>那篇文章里，我们介绍了如何使用APC220模块在PC和Arduino间实现无线数据传输。那时我们使用的是厂家提供的USB适配器。，由于这个适配器只能接APC220模块，而不能起到其它的作用，或多或少觉得有些浪费。更加重要的是，为此我们得提供两个不同的套件，一个给Arduino使用，一个给PC使用，两者之间不能实现互换。</p>
<p>正是基于上面的这些问题，我们针对电子积木系列开发了一款USB转串口的适配器Serial Dongle，使用它就可以通过PC机来连接和使用各种基于串口的电子积木模块了，比如这里介绍的无线数传模块APC220。</p>
<p><img class="aligncenter" title="APC220" src="http://image.flamingoeda.com/albums/userpics/febb_apc220_2.JPG" alt="" width="460" height="345" />APC220模块的使用可以参考<a href="../2009/06/14/%E4%BD%BF%E7%94%A8apc220%E5%AE%9E%E7%8E%B0arduino%E6%97%A0%E7%BA%BF%E6%95%B0%E6%8D%AE%E4%BC%A0%E8%BE%93/" target="_blank">使用APC220实现Arduino无线数据传输</a>那篇文章，两者间的唯一区别只在于如何对USB虚拟出来的串口进行设置，以便能够使用厂家提供的设置程序RF-ANET来对APC220的各个参数进行调整。首先我们将USB转串口适配器Serial Dongle连接到PC机上，然后从设备管理器中找到该串口，并打开其属性设置窗口：</p>
<p><a href="http://blog.flamingoeda.com/wp-content/uploads/2010/07/2.jpg"><img class="aligncenter size-medium wp-image-595" title="2" src="http://blog.flamingoeda.com/wp-content/uploads/2010/07/2-277x300.jpg" alt="" width="277" height="300" /></a></p>
<p>点击Advanced按钮打开高级属性设置窗口，我们需要从Com Port Number列表中为Serial Dongle设置一个较小的COM号（如COM5），否则厂家给的设置程序会出现无法打开该串口的错识。另一个需要修改的地方是BM Options中的延时设置需要从16改为更小的值（如8）：</p>
<p><a href="http://blog.flamingoeda.com/wp-content/uploads/2010/07/3.jpg"><img class="aligncenter size-medium wp-image-596" title="3" src="http://blog.flamingoeda.com/wp-content/uploads/2010/07/3-300x214.jpg" alt="" width="300" height="214" /></a></p>
<p>现在可以运行厂家给的设置程序了，此时特别需要注意的是操作顺序。应该先接好Serial Dongle，并将Serial Dongle右上角的开关拨到M的位置：</p>
<p><img class="aligncenter" title="APC220" src="http://image.flamingoeda.com/albums/userpics/normal_febb_serial_dongle_1.JPG" alt="" width="399" height="295" /></p>
<p>接着运行设置程序RF-ANET，最后再用连接线将APC220模块连接到Serial Dongle上，此时应该可以看到APC220设置程序窗口的最下面会显示Found device，表明APC220模块已经成功找到。如果设置程序没有找到APC220模块，可以试着断开APC220与Serial Dongle的连接，然后再次将APC220模块连接到SerialDongle上，直到设置程序成功找到APC220模块。</p>
<p><a href="http://blog.flamingoeda.com/wp-content/uploads/2010/07/4.jpg"><img class="aligncenter size-medium wp-image-597" title="4" src="http://blog.flamingoeda.com/wp-content/uploads/2010/07/4-300x272.jpg" alt="" width="300" height="272" /></a></p>
<p>当APC220模块成功地被设置程序RF-ANET找到之后，我们就可以按照实际的需要来使用Serial Dongle对APC220模块进行各种参数配置了，而不再依赖厂家提供的USB适配器了;-)</p>
<p>至于随后的使用过程，那就完全一致了。一方面，我们可以将APC220模块通过4芯的串口连接线，与Arduino传感器扩展板相连接，这样Arduino就可以通过串口来操作APC220模块实现无线数据的收发：</p>
<p><img class="aligncenter" title="apc220" src="http://image.flamingoeda.com/albums/userpics/normal_febb_apc220_3.JPG" alt="" width="400" height="300" /></p>
<p>另一方面，我们可以通过Serial Dongle连接APC220模块与电脑，并通过电脑的串口读写功能来操作APC220模块实现无线数据的收发：</p>
<p><img class="aligncenter" title="apc220" src="http://image.flamingoeda.com/albums/userpics/normal_febb_serial_dongle_2.JPG" alt="" width="400" height="300" />下图就是利用两个APC220模块实现Arduino与电脑间无线数据传输的连接图：</p>
<p><img class="aligncenter" title="apc220" src="http://image.flamingoeda.com/albums/userpics/normal_febb_apc220_4.JPG" alt="" width="400" height="172" /></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.flamingoeda.com/2010/07/06/%e7%94%b5%e5%ad%90%e7%a7%af%e6%9c%a8-%e6%97%a0%e7%ba%bf%e6%95%b0%e4%bc%a0%e6%a8%a1%e5%9d%97-apc220/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>用电子积木搭建的光控开关原型</title>
		<link>http://blog.flamingoeda.com/2010/04/17/%e7%94%a8%e7%94%b5%e5%ad%90%e7%a7%af%e6%9c%a8%e6%90%ad%e5%bb%ba%e7%9a%84%e5%85%89%e6%8e%a7%e5%bc%80%e5%85%b3%e5%8e%9f%e5%9e%8b/</link>
		<comments>http://blog.flamingoeda.com/2010/04/17/%e7%94%a8%e7%94%b5%e5%ad%90%e7%a7%af%e6%9c%a8%e6%90%ad%e5%bb%ba%e7%9a%84%e5%85%89%e6%8e%a7%e5%bc%80%e5%85%b3%e5%8e%9f%e5%9e%8b/#comments</comments>
		<pubDate>Sat, 17 Apr 2010 15:39:39 +0000</pubDate>
		<dc:creator>flamingoeda</dc:creator>
				<category><![CDATA[电子积木]]></category>

		<guid isPermaLink="false">http://blog.flamingoeda.com/?p=589</guid>
		<description><![CDATA[光控开关所要实现的基本功能是当光线强度达到一定的值时，可以触发相应的继电器动作。如果使用Arduino和电子积木的话，最容易想到的一个方案是在Arduino的模拟输入引脚上接一个光线传感器，通过判断读入的光线传感器的值，来驱动相应的继电器动作。继电器上可以接一个用电设备，比如白炽灯。 但其实还有一个更加简单而直接的做法，就是通过一个运放电路，将光线传感器上读出的电压值，与预先设置好的一个电压值进行比较。如果光线传感器输出的电压值大于这一事先定义好的电压值时，驱动相应的继电器动作。这一“预先设置好的电压值”，是通过电位器来调节的。 借助于光线传感器和继电器这两个已经成型的电子积木模块，再加上相应的运放电路和电压调节电路，整个光控开关的原型搭建的还是比较顺利的。在将光控开关置于环境光线比较暗的情况下时，继电器吸合： 而在将光控开关所在环境的光线增强时，继电器断开： 通过调节电位器，可以控制继电器吸合或者断开时的光线强度。不过由于没有软件的滤波处理，在调整到临界点的位置时，容易产生继电器不断吸合和断开的情况，因此使用时要将电位器调节到越过这一临界点的位置上。]]></description>
			<content:encoded><![CDATA[<p>光控开关所要实现的基本功能是当光线强度达到一定的值时，可以触发相应的继电器动作。如果使用Arduino和电子积木的话，最容易想到的一个方案是在Arduino的模拟输入引脚上接一个光线传感器，通过判断读入的光线传感器的值，来驱动相应的继电器动作。继电器上可以接一个用电设备，比如白炽灯。</p>
<p>但其实还有一个更加简单而直接的做法，就是通过一个运放电路，将光线传感器上读出的电压值，与预先设置好的一个电压值进行比较。如果光线传感器输出的电压值大于这一事先定义好的电压值时，驱动相应的继电器动作。这一“预先设置好的电压值”，是通过电位器来调节的。</p>
<p>借助于光线传感器和继电器这两个已经成型的电子积木模块，再加上相应的运放电路和电压调节电路，整个光控开关的原型搭建的还是比较顺利的。在将光控开关置于环境光线比较暗的情况下时，继电器吸合：</p>
<p><a href="http://blog.flamingoeda.com/wp-content/uploads/2010/04/light_switch_on.jpg"><img class="aligncenter size-full wp-image-590" title="light_switch_on" src="http://blog.flamingoeda.com/wp-content/uploads/2010/04/light_switch_on.jpg" alt="" width="460" height="345" /></a></p>
<p>而在将光控开关所在环境的光线增强时，继电器断开：</p>
<p><a href="http://blog.flamingoeda.com/wp-content/uploads/2010/04/light_switch_off.jpg"><img class="aligncenter size-full wp-image-591" title="light_switch_off" src="http://blog.flamingoeda.com/wp-content/uploads/2010/04/light_switch_off.jpg" alt="" width="460" height="345" /></a></p>
<p>通过调节电位器，可以控制继电器吸合或者断开时的光线强度。不过由于没有软件的滤波处理，在调整到临界点的位置时，容易产生继电器不断吸合和断开的情况，因此使用时要将电位器调节到越过这一临界点的位置上。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.flamingoeda.com/2010/04/17/%e7%94%a8%e7%94%b5%e5%ad%90%e7%a7%af%e6%9c%a8%e6%90%ad%e5%bb%ba%e7%9a%84%e5%85%89%e6%8e%a7%e5%bc%80%e5%85%b3%e5%8e%9f%e5%9e%8b/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Arduino 电子积木 数字温湿度传感器 SHT10 SHT1x</title>
		<link>http://blog.flamingoeda.com/2010/03/07/arduino-%e7%94%b5%e5%ad%90%e7%a7%af%e6%9c%a8-%e6%95%b0%e5%ad%97%e6%b8%a9%e6%b9%bf%e5%ba%a6%e4%bc%a0%e6%84%9f%e5%99%a8-sht10-sht1x/</link>
		<comments>http://blog.flamingoeda.com/2010/03/07/arduino-%e7%94%b5%e5%ad%90%e7%a7%af%e6%9c%a8-%e6%95%b0%e5%ad%97%e6%b8%a9%e6%b9%bf%e5%ba%a6%e4%bc%a0%e6%84%9f%e5%99%a8-sht10-sht1x/#comments</comments>
		<pubDate>Sun, 07 Mar 2010 14:54:22 +0000</pubDate>
		<dc:creator>flamingoeda</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[电子积木]]></category>

		<guid isPermaLink="false">http://blog.flamingoeda.com/?p=582</guid>
		<description><![CDATA[在对环境温度与湿度进行测量及控制的时候，瑞士Sensirion公司推出的SHT系列数字温湿度集成传感器无疑是一个非常不错的选择。虽然价格较普通的模拟温度或者湿传感器来讲稍微有点偏高，但在需要读出准确的温度和湿度值的场景下却非常合适，而且具有极高的可靠性和出色的长期稳定性。 我们设计的这款数字温湿度传感器就是基于SHT系列中使用最为广泛的SHT10，有关该传感器的具体参数可以参考官方网站上的介绍。 SHT10采用的是一种类似于I2C的两线串行接口（bidirectional 2-wire），因此在物理连接上我们需要使用两根连接线与该电子积木模块连接。 要在Arduino上使用该电子积木，可以从Practical Arduino这本书的官方网站上下载相应的库代码， 或者直接从这里下载我们在在测试时所使用版本的压缩文件。测试时我们使用的是Arduino 0018，只需要将相应的文件解压缩到Arduino安装目录下的libraries目录中就可以了： 测试时将电子积木上的DATA和SCK引脚分别与Arduino的数字I/O的10号引脚和11号引脚连接起来，相应的测试代码如下所示: #include&#160; #define&#160;dataPin&#160;&#160;10&#160;&#160;&#160;// DATA #define&#160;clockPin&#160;11&#160;&#160;&#160;// SCK SHT1x sht1x(dataPin, clockPin); void setup() { &#160;&#160;&#160;Serial.begin(9600); &#160;&#160;&#160;Serial.println("Starting up"); } void loop() { &#160;&#160;float temp_c; &#160;&#160;float temp_f; &#160;&#160;float humidity; &#160;&#160;// Read values from the sensor &#160;&#160;temp_c&#160;=&#160;sht1x.readTemperatureC(); &#160;&#160;temp_f&#160;=&#160;sht1x.readTemperatureF(); &#160;&#160;humidity&#160;=&#160;sht1x.readHumidity(); &#160;&#160;// Print the values to the serial port &#160;&#160;Serial.print("Temperature: "); &#160;&#160;Serial.print(temp_c, DEC); &#160;&#160;Serial.print("C [...]]]></description>
			<content:encoded><![CDATA[<p>在对环境温度与湿度进行测量及控制的时候，瑞士Sensirion公司推出的SHT系列数字温湿度集成传感器无疑是一个非常不错的选择。虽然价格较普通的模拟温度或者湿传感器来讲稍微有点偏高，但在需要读出准确的温度和湿度值的场景下却非常合适，而且具有极高的可靠性和出色的长期稳定性。</p>
<p>我们设计的这款数字温湿度传感器就是基于SHT系列中使用最为广泛的SHT10，有关该传感器的具体参数可以参考<a href="http://tinyurl.com/yabqw3e">官方网站上的介绍</a>。<br />
<img alt="" src="http://image.flamingoeda.com/albums/userpics/febb_sht10_1.JPG" title="SHT10" class="aligncenter" width="460" height="345" /></p>
<p>SHT10采用的是一种类似于I2C的两线串行接口（bidirectional 2-wire），因此在物理连接上我们需要使用两根连接线与该电子积木模块连接。<br />
<img alt="" src="http://image.flamingoeda.com/albums/userpics/febb_sht10_2.JPG" title="SHT10" class="aligncenter" width="460" height="345" /></p>
<p>要在Arduino上使用该电子积木，可以从Practical Arduino这本书的<a href="http://tinyurl.com/yhf8qez">官方网站上下载相应的库代码</a>， 或者直接从这里下载我们在<a href='http://blog.flamingoeda.com/wp-content/uploads/2010/03/SHT1x.zip'>在测试时所使用版本的压缩文件</a>。测试时我们使用的是Arduino 0018，只需要将相应的文件解压缩到Arduino安装目录下的libraries目录中就可以了：</p>
<p><img alt="" src="http://image.flamingoeda.com/albums/userpics/febb_sht10_3.JPG" title="SHT10" class="aligncenter" width="460" height="345" /></p>
<p>测试时将电子积木上的DATA和SCK引脚分别与Arduino的数字I/O的10号引脚和11号引脚连接起来，相应的测试代码如下所示:</p>
<pre>
#include&nbsp;<<span style="color: #CC6600;">SHT1x</span>.h>

#define&nbsp;dataPin&nbsp;&nbsp;10&nbsp;&nbsp;&nbsp;<span style="color: #7E7E7E;">// DATA</span>
#define&nbsp;clockPin&nbsp;11&nbsp;&nbsp;&nbsp;<span style="color: #7E7E7E;">// SCK</span>
<span style="color: #CC6600;">SHT1x</span> sht1x(dataPin, clockPin);

<span style="color: #CC6600;">void</span> <span style="color: #CC6600;"><b>setup</b></span>()
{
&nbsp;&nbsp;&nbsp;<span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">begin</span>(9600);
&nbsp;&nbsp;&nbsp;<span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">println</span>(<span style="color: #006699;">"Starting up"</span>);
}

<span style="color: #CC6600;">void</span> <span style="color: #CC6600;"><b>loop</b></span>()
{
&nbsp;&nbsp;<span style="color: #CC6600;">float</span> temp_c;
&nbsp;&nbsp;<span style="color: #CC6600;">float</span> temp_f;
&nbsp;&nbsp;<span style="color: #CC6600;">float</span> humidity;

&nbsp;&nbsp;<span style="color: #7E7E7E;">// Read values from the sensor</span>
&nbsp;&nbsp;temp_c&nbsp;=&nbsp;sht1x.<span style="color: #CC6600;">readTemperatureC</span>();
&nbsp;&nbsp;temp_f&nbsp;=&nbsp;sht1x.<span style="color: #CC6600;">readTemperatureF</span>();
&nbsp;&nbsp;humidity&nbsp;=&nbsp;sht1x.<span style="color: #CC6600;">readHumidity</span>();

&nbsp;&nbsp;<span style="color: #7E7E7E;">// Print the values to the serial port</span>
&nbsp;&nbsp;<span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">print</span>(<span style="color: #006699;">"Temperature: "</span>);
&nbsp;&nbsp;<span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">print</span>(temp_c, <span style="color: #006699;">DEC</span>);
&nbsp;&nbsp;<span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">print</span>(<span style="color: #006699;">"C / "</span>);
&nbsp;&nbsp;<span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">print</span>(temp_f, <span style="color: #006699;">DEC</span>);
&nbsp;&nbsp;<span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">print</span>(<span style="color: #006699;">"F. Humidity: "</span>);
&nbsp;&nbsp;<span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">print</span>(humidity);
&nbsp;&nbsp;<span style="color: #CC6600;"><b>Serial</b></span>.<span style="color: #CC6600;">println</span>(<span style="color: #006699;">"%"</span>);

&nbsp;&nbsp;<span style="color: #CC6600;">delay</span>(2000);
}
</pre>
<p>下图是相应输出结果：<br />
<img alt="" src="http://image.flamingoeda.com/albums/userpics/febb_sht10_4.JPG" title="SHT10" class="aligncenter" width="460" height="345" /></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.flamingoeda.com/2010/03/07/arduino-%e7%94%b5%e5%ad%90%e7%a7%af%e6%9c%a8-%e6%95%b0%e5%ad%97%e6%b8%a9%e6%b9%bf%e5%ba%a6%e4%bc%a0%e6%84%9f%e5%99%a8-sht10-sht1x/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Arduino 电子积木 八路数字输出模块 74HC595</title>
		<link>http://blog.flamingoeda.com/2010/01/12/arduino-%e7%94%b5%e5%ad%90%e7%a7%af%e6%9c%a8-%e5%85%ab%e8%b7%af%e6%95%b0%e5%ad%97%e8%be%93%e5%87%ba%e6%a8%a1%e5%9d%97-74hc595/</link>
		<comments>http://blog.flamingoeda.com/2010/01/12/arduino-%e7%94%b5%e5%ad%90%e7%a7%af%e6%9c%a8-%e5%85%ab%e8%b7%af%e6%95%b0%e5%ad%97%e8%be%93%e5%87%ba%e6%a8%a1%e5%9d%97-74hc595/#comments</comments>
		<pubDate>Tue, 12 Jan 2010 08:54:35 +0000</pubDate>
		<dc:creator>flamingoeda</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[电子积木]]></category>
		<category><![CDATA[74hc595]]></category>
		<category><![CDATA[shiftout]]></category>

		<guid isPermaLink="false">http://blog.flamingoeda.com/?p=578</guid>
		<description><![CDATA[我们曾经做过一个八路的数字输出扩展模块，那个时候数字传感器的引脚顺序同现在的通用传感器引脚顺序是不一致的，而且连接的时候要用到三根传感器连接线。近期我们在电子积木的开发过程中引入了IDC接口，这样当电路模块有多个引脚时可以更加方便，不过同时灵活性也就降低了。新一版本的八路数字输出模块就是根据新的传感器引脚顺序，以及多个引脚相连接的问题做了修改： 按照新的传感器引脚的顺序定义，相应的为GND(-)，VCC(+)和信号： 连接的时候使用的是IDC扩展板上提供的IDC-6引脚，并通过6芯IDC连接线相连接到八路数字输出模块的595IN插座上： 扩展出来的数字I/O引脚，可以用来连接数字输出模块，比如常用的LED模块： 如果需要多块级连的话，则需要将前一个模块的595OUT座与下一个模块的595IN座相连接： 该模块的核心是一个74HC595芯片，有关Arduino编程的问题可以借用Arduino官网上ShiftOut的说明和例子，但需要按照IDC扩展板上的硬件连线，修改相应的引脚，如下面的代码段所示： int dataPin = 9; // SER int latchPin = 7; //RCK int clockPin = 6; //SCK]]></description>
			<content:encoded><![CDATA[<p>我们曾经做过一个八路的数字输出扩展模块，那个时候数字传感器的引脚顺序同现在的通用传感器引脚顺序是不一致的，而且连接的时候要用到三根传感器连接线。近期我们在电子积木的开发过程中引入了IDC接口，这样当电路模块有多个引脚时可以更加方便，不过同时灵活性也就降低了。新一版本的八路数字输出模块就是根据新的传感器引脚顺序，以及多个引脚相连接的问题做了修改：</p>
<p><img alt="" src="http://image.flamingoeda.com/albums/userpics/febb_shiftout_1.JPG" title="shiftout" class="aligncenter" width="460" height="345" /></p>
<p>按照新的传感器引脚的顺序定义，相应的为GND(-)，VCC(+)和信号：<br />
<img alt="" src="http://image.flamingoeda.com/albums/userpics/febb_shiftout_2.JPG" title="shiftout" class="aligncenter" width="460"  /></p>
<p>连接的时候使用的是IDC扩展板上提供的IDC-6引脚，并通过6芯IDC连接线相连接到八路数字输出模块的595IN插座上：<br />
<img alt="" src="http://image.flamingoeda.com/albums/userpics/febb_shiftout_3.JPG" title="shiftout" class="aligncenter" width="460" height="345" /></p>
<p>扩展出来的数字I/O引脚，可以用来连接数字输出模块，比如常用的LED模块：<br />
<img alt="" src="http://image.flamingoeda.com/albums/userpics/febb_shiftout_4.JPG" title="shiftout" class="aligncenter" width="460" height="345" /></p>
<p>如果需要多块级连的话，则需要将前一个模块的595OUT座与下一个模块的595IN座相连接：<br />
<img alt="" src="http://image.flamingoeda.com/albums/userpics/febb_shiftout_5.JPG" title="shiftout" class="aligncenter" width="460" height="345" /></p>
<p>该模块的核心是一个74HC595芯片，有关Arduino编程的问题可以借用<a href="http://www.arduino.cc/en/Tutorial/ShiftOut">Arduino官网上ShiftOut的说明和例子，但需要按照IDC扩展板上的硬件连线，修改相应的引脚，如下面的代码段所示：</a></p>
<pre>
<span style="color: #CC6600;">int</span> dataPin = 9;   <span style="color: #7E7E7E;">// SER</span>
<span style="color: #CC6600;">int</span> latchPin = 7;  <span style="color: #7E7E7E;">//RCK</span>
<span style="color: #CC6600;">int</span> clockPin = 6; <span style="color: #7E7E7E;">//SCK</span>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.flamingoeda.com/2010/01/12/arduino-%e7%94%b5%e5%ad%90%e7%a7%af%e6%9c%a8-%e5%85%ab%e8%b7%af%e6%95%b0%e5%ad%97%e8%be%93%e5%87%ba%e6%a8%a1%e5%9d%97-74hc595/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Arduino 电子积木 4路MOSFET开关</title>
		<link>http://blog.flamingoeda.com/2010/01/03/arduino-%e7%94%b5%e5%ad%90%e7%a7%af%e6%9c%a8-4%e8%b7%afmosfet%e5%bc%80%e5%85%b3/</link>
		<comments>http://blog.flamingoeda.com/2010/01/03/arduino-%e7%94%b5%e5%ad%90%e7%a7%af%e6%9c%a8-4%e8%b7%afmosfet%e5%bc%80%e5%85%b3/#comments</comments>
		<pubDate>Sun, 03 Jan 2010 02:49:26 +0000</pubDate>
		<dc:creator>flamingoeda</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[电子积木]]></category>

		<guid isPermaLink="false">http://blog.flamingoeda.com/?p=568</guid>
		<description><![CDATA[MOSFET是一种具有很好开关特性的电子器件，被广泛应用在需要电子开关的电路中，如开关电源和马达驱动，以及照明调光等。继电器是大家非常熟悉的另外一种具有开关特性的模块，但由于继电器的工作原理一般是靠机械触点来达到开与关的目的，这就必然导致在开关时间非常短的情况之下，继电器无法工作的情况，另外触点开关时发出的叭叭声在某些场合下也是比较让人烦恼的一件事情。 我们设计的这一4路MOSFET开关最多可以提供4组电子开关，分别用来控制不同的电路模块。受MOSFET工作原理的影响，该电子积木只能用来控制直流电路，比如直流LED屏等，并不适合交流电路的控制。极限情况下该MOSFET开关可以用来控制100V/33A的直流电路，但控制的最小直流电压建议不低于9V。 在电路连接上，受控一端的连线稍微要麻烦一些。以控制12V的LED灯带为例，首先在正极（+）和负极（-）间连接好电源： 接着接LED灯带的正极连接到模块的正极（+）上，LED灯带的负极则连接到开关1（S1）上: 如果有其它的LED灯带需要控制，同样只需将LED灯带的正极连接到模块的正极（+），LED灯带的负极则依次连接到开关2（S2）、开关3（S3）、开关4（S4）上： 控制端的连线就简单多了，我们只需要通过传感器连接线，将相应的控制端口与Arduino的传感器扩展板连接起来，就可以通过Arduino来控制这些12V的LED灯带了。实验中我们接了两个LED灯带： 测试代码如下所示： int s1Pin = 6; int s2Pin = 7; void setup() { &#160;&#160;pinMode(s1Pin, OUTPUT); &#160;&#160;pinMode(s2Pin, OUTPUT); } void loop() { &#160;&#160;int i; &#160;&#160; &#160;&#160;digitalWrite(s1Pin, HIGH); &#160;&#160;digitalWrite(s2Pin, HIGH); &#160;&#160;delay(500); &#160;&#160;digitalWrite(s1Pin, LOW); &#160;&#160;digitalWrite(s2Pin, LOW); &#160;&#160;delay(500); &#160;&#160; &#160;&#160;for (i = 0; i < 10; i ++) { &#160;&#160;&#160;&#160;digitalWrite(s1Pin, HIGH); &#160;&#160;&#160;&#160;delay(500); &#160;&#160;&#160;&#160;digitalWrite(s1Pin, LOW); [...]]]></description>
			<content:encoded><![CDATA[<p>MOSFET是一种具有很好开关特性的电子器件，被广泛应用在需要电子开关的电路中，如开关电源和马达驱动，以及照明调光等。继电器是大家非常熟悉的另外一种具有开关特性的模块，但由于继电器的工作原理一般是靠机械触点来达到开与关的目的，这就必然导致在开关时间非常短的情况之下，继电器无法工作的情况，另外触点开关时发出的叭叭声在某些场合下也是比较让人烦恼的一件事情。</p>
<p>我们设计的这一4路MOSFET开关最多可以提供4组电子开关，分别用来控制不同的电路模块。受MOSFET工作原理的影响，该电子积木只能用来控制直流电路，比如直流LED屏等，并不适合交流电路的控制。极限情况下该MOSFET开关可以用来控制100V/33A的直流电路，但控制的最小直流电压建议不低于9V。</p>
<p><img alt="" src="http://image.flamingoeda.com/albums/userpics/febb_4mosfet.JPG" title="mosfet" class="aligncenter" width="460" height="345" /></p>
<p>在电路连接上，受控一端的连线稍微要麻烦一些。以控制12V的LED灯带为例，首先在正极（+）和负极（-）间连接好电源：<br />
<img alt="" src="http://image.flamingoeda.com/albums/userpics/febb_4mosfet_1.JPG" title="mosfet" class="aligncenter" width="460" height="345" /></p>
<p>接着接LED灯带的正极连接到模块的正极（+）上，LED灯带的负极则连接到开关1（S1）上:<br />
<img alt="" src="http://image.flamingoeda.com/albums/userpics/febb_4mosfet_2.JPG" title="mosfet" class="aligncenter" width="460" height="345" /></p>
<p>如果有其它的LED灯带需要控制，同样只需将LED灯带的正极连接到模块的正极（+），LED灯带的负极则依次连接到开关2（S2）、开关3（S3）、开关4（S4）上：<br />
<img alt="" src="http://image.flamingoeda.com/albums/userpics/febb_4mosfet_3.JPG" title="mosfet" class="aligncenter" width="460" height="345" /></p>
<p>控制端的连线就简单多了，我们只需要通过传感器连接线，将相应的控制端口与Arduino的传感器扩展板连接起来，就可以通过Arduino来控制这些12V的LED灯带了。实验中我们接了两个LED灯带：<br />
<img alt="" src="http://image.flamingoeda.com/albums/userpics/febb_4mosfet_4.JPG" title="mosfet" class="aligncenter" width="460" height="345" /></p>
<p>测试代码如下所示：</p>
<pre>
<span style="color: #CC6600;">int</span> s1Pin = 6;
<span style="color: #CC6600;">int</span> s2Pin = 7;

<span style="color: #CC6600;">void</span> <span style="color: #CC6600;"><b>setup</b></span>() {
&nbsp;&nbsp;<span style="color: #CC6600;">pinMode</span>(s1Pin, <span style="color: #006699;">OUTPUT</span>);
&nbsp;&nbsp;<span style="color: #CC6600;">pinMode</span>(s2Pin, <span style="color: #006699;">OUTPUT</span>);
}

<span style="color: #CC6600;">void</span> <span style="color: #CC6600;"><b>loop</b></span>() {
&nbsp;&nbsp;<span style="color: #CC6600;">int</span> i;
&nbsp;&nbsp;
&nbsp;&nbsp;<span style="color: #CC6600;">digitalWrite</span>(s1Pin, <span style="color: #006699;">HIGH</span>);
&nbsp;&nbsp;<span style="color: #CC6600;">digitalWrite</span>(s2Pin, <span style="color: #006699;">HIGH</span>);
&nbsp;&nbsp;<span style="color: #CC6600;">delay</span>(500);

&nbsp;&nbsp;<span style="color: #CC6600;">digitalWrite</span>(s1Pin, <span style="color: #006699;">LOW</span>);
&nbsp;&nbsp;<span style="color: #CC6600;">digitalWrite</span>(s2Pin, <span style="color: #006699;">LOW</span>);
&nbsp;&nbsp;<span style="color: #CC6600;">delay</span>(500);
&nbsp;&nbsp;
&nbsp;&nbsp;<span style="color: #CC6600;">for</span> (i = 0; i < 10; i ++) {
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #CC6600;">digitalWrite</span>(s1Pin, <span style="color: #006699;">HIGH</span>);
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #CC6600;">delay</span>(500);
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #CC6600;">digitalWrite</span>(s1Pin, <span style="color: #006699;">LOW</span>);
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #CC6600;">delay</span>(500);
&nbsp;&nbsp;}
&nbsp;&nbsp;
&nbsp;&nbsp;<span style="color: #CC6600;">for</span> (i = 0; i < 100; i ++) {
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #CC6600;">digitalWrite</span>(s2Pin, <span style="color: #006699;">HIGH</span>);
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #CC6600;">delay</span>(50);
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #CC6600;">digitalWrite</span>(s2Pin, <span style="color: #006699;">LOW</span>);
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #CC6600;">delay</span>(50);
&nbsp;&nbsp;}
}
</pre>
<p>下面是拍摄的视频效果：<br />
<object width="480" height="400"><param name="movie" value="http://player.youku.com/player.php/sid/XMTQzMDQ5OTA4/v.swf"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="never"></param><param name="allownetworking" value="internal"></param><param name="flashvars" value="isShowRelatedVideo=false&showAd=0&show_pre=1&show_next=1&isAutoPlay=false&isDebug=false&UserID=&winType=interior&playMovie=true&MMControl=false&MMout=false&RecordCode=1001,1002,1003,1004,1005,1006,2001,3001,3002,3003,3004,3005,3007,3008,9999" /><embed src="http://player.youku.com/player.php/sid/XMTQzMDQ5OTA4/v.swf" type="application/x-shockwave-flash" allowscriptaccess="never" allownetworking="internal" allowfullscreen="true" width="480" height="400" flashvars="isShowRelatedVideo=false&showAd=0&show_pre=1&show_next=1&isAutoPlay=false&isDebug=false&UserID=&winType=interior&playMovie=true&MMControl=false&MMout=false&RecordCode=1001,1002,1003,1004,1005,1006,2001,3001,3002,3003,3004,3005,3007,3008,9999"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.flamingoeda.com/2010/01/03/arduino-%e7%94%b5%e5%ad%90%e7%a7%af%e6%9c%a8-4%e8%b7%afmosfet%e5%bc%80%e5%85%b3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Arduino 电子积木 SD卡存储模块</title>
		<link>http://blog.flamingoeda.com/2009/12/25/arduino-%e7%94%b5%e5%ad%90%e7%a7%af%e6%9c%a8-sd%e5%8d%a1%e5%ad%98%e5%82%a8%e6%a8%a1%e5%9d%97/</link>
		<comments>http://blog.flamingoeda.com/2009/12/25/arduino-%e7%94%b5%e5%ad%90%e7%a7%af%e6%9c%a8-sd%e5%8d%a1%e5%ad%98%e5%82%a8%e6%a8%a1%e5%9d%97/#comments</comments>
		<pubDate>Thu, 24 Dec 2009 16:08:30 +0000</pubDate>
		<dc:creator>flamingoeda</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[电子积木]]></category>
		<category><![CDATA[SD卡]]></category>

		<guid isPermaLink="false">http://blog.flamingoeda.com/?p=549</guid>
		<description><![CDATA[SD卡是我们经常使用到的一种存储设备，像数码相机，MP3，阅读器，GPS导航仪等都会使用到它。在使用Arduino的时候，如何我们要将一些数据记录下来，就可以使用到SD卡。不过要让SD卡能够同Arduino配合使用可不是一件简单的事情，首先在硬件上我们要解决其与Arduino连接的问题，其次软件上我们还要解决文件的存储问题，以便使用读卡器之样的设备能够很方便地将保存在SD卡中的数据读出。 针对硬件上的需求，我们开发了SD卡模块，它通过SPI接口与Arduino进行通信： 同时，为了方便同Arduino的SPI接口进行连接，提供了相应的IDC扩展板，该扩展板上有一个专门为SPI设计的六芯插座： 电路的连接上则依然沿用了电子积木所一向强调的即插即用方式，我们只需要用6芯的IDC连接线，将IDC扩展板上的SPI插座与SD卡模块上的相应插座连接起来，就完成了电路部分的连接： 回到软件部分，我们的目标是要让SD卡上记录的数据能够在电脑上顺利地读出，因此在向SD卡上记录相应数据的时候需要遵循一定的规定，即文件系统的类型。对于像Arduino这样的小系统来讲，相对简单的FAT16是一个比较不错的选择。 在这里我们要用到读卡器来对SD卡进行相应的处理，将其格式化成FAT文件系统： Arduino上使用的软件则是基于SparkFun提供的FAT库，但根据硬件差异做了一定的修改，你可以从这里下载到修改过的FAT库。该库需要被解压缩到Arduino的hardware\libraries子目录中。 测试时使用的时FAT库里自带的示例程序： //Include all the libraries necessary for FAT32 #include &#60;byteordering.h&#62; #include &#60;fat.h&#62; #include &#60;FAT16.h&#62; #include &#60;fat_config.h&#62; #include &#60;partition.h&#62; #include &#60;partition_config.h&#62; #include &#60;sd-reader_config.h&#62; #include &#60;sd_raw.h&#62; #include &#60;sd_raw_config.h&#62; FAT TestFile; //This will be the file we manipulate in the sketch char buffer[512]; //Data will be temporarily stored to this buffer [...]]]></description>
			<content:encoded><![CDATA[<p>SD卡是我们经常使用到的一种存储设备，像数码相机，MP3，阅读器，GPS导航仪等都会使用到它。在使用Arduino的时候，如何我们要将一些数据记录下来，就可以使用到SD卡。不过要让SD卡能够同Arduino配合使用可不是一件简单的事情，首先在硬件上我们要解决其与Arduino连接的问题，其次软件上我们还要解决文件的存储问题，以便使用读卡器之样的设备能够很方便地将保存在SD卡中的数据读出。</p>
<p>针对硬件上的需求，我们开发了SD卡模块，它通过SPI接口与Arduino进行通信：<br />
<img alt="" src="http://image.flamingoeda.com/albums/userpics/febb_sd_card.JPG" title="SD卡" class="aligncenter" width="460" height="345" /><br />
同时，为了方便同Arduino的SPI接口进行连接，提供了相应的IDC扩展板，该扩展板上有一个专门为SPI设计的六芯插座：<br />
<img alt="" src="http://image.flamingoeda.com/albums/userpics/arduino_shield_idc.JPG" title="SD卡" class="aligncenter" width="460" height="345" /><br />
电路的连接上则依然沿用了电子积木所一向强调的即插即用方式，我们只需要用6芯的IDC连接线，将IDC扩展板上的SPI插座与SD卡模块上的相应插座连接起来，就完成了电路部分的连接：<br />
<img alt="" src="http://image.flamingoeda.com/albums/userpics/febb_sd_card_1.JPG" title="SD卡" class="aligncenter" width="460" height="345" /></p>
<p>回到软件部分，我们的目标是要让SD卡上记录的数据能够在电脑上顺利地读出，因此在向SD卡上记录相应数据的时候需要遵循一定的规定，即文件系统的类型。对于像Arduino这样的小系统来讲，相对简单的FAT16是一个比较不错的选择。</p>
<p>在这里我们要用到读卡器来对SD卡进行相应的处理，将其格式化成FAT文件系统：</p>
<p><img alt="" src="http://image.flamingoeda.com/albums/userpics/febb_sd_card_2.JPG" title="SD卡" class="aligncenter" width="460" height="345" /><br />
<img alt="" src="http://image.flamingoeda.com/albums/userpics/febb_sd_card_3.JPG" title="SD卡" class="aligncenter" width="460" height="345" /><br />
<img alt="" src="http://image.flamingoeda.com/albums/userpics/febb_sd_card_4.JPG" title="SD卡" class="aligncenter" width="460" height="345" /></p>
<p>Arduino上使用的软件则是基于SparkFun提供的<a href="http://www.sparkfun.com/Code/FAT.zip">FAT库</a>，但根据硬件差异做了一定的修改，你可以从这里下载到<a href="http://blog.flamingoeda.com/wp-content/uploads/2009/12/FAT.zip">修改过的FAT库</a>。该库需要被解压缩到Arduino的hardware\libraries子目录中。</p>
<p>测试时使用的时FAT库里自带的示例程序：</p>
<pre>
<span style="color: #777755;">//Include all the libraries necessary for FAT32</span>
#include &lt;byteordering.h&gt;
#include &lt;fat.h&gt;
#include &lt;FAT16.h&gt;
#include &lt;fat_config.h&gt;
#include &lt;partition.h&gt;
#include &lt;partition_config.h&gt;
#include &lt;sd-reader_config.h&gt;
#include &lt;sd_raw.h&gt;
#include &lt;sd_raw_config.h&gt;

FAT TestFile;      <span style="color: #777755;">//This will be the file we manipulate in the sketch</span>
<span style="color: #996600;">char</span> buffer[512];  <span style="color: #777755;">//Data will be temporarily stored to this buffer before being written to the file</span>
<span style="color: #996600;">int</span> read_size=0;   <span style="color: #777755;">//Used as an indicator for how many characters are read from the file</span>
<span style="color: #996600;">int</span> count=0;       <span style="color: #777755;">//Miscellaneous variable</span>

<span style="color: #CC6600;">void</span> <span style="color: #993300;"><b>setup</b></span>()
{
  <span style="color: #996600;">Serial</span>.<span style="color: #996600;">begin</span>(9600);  <span style="color: #777755;">//Initiate serial communication at 9600 bps</span>

  TestFile.initialize();  <span style="color: #777755;">//Initialize the SD card and the FAT file system.</span>
  <span style="color: #996600;">Serial</span>.<span style="color: #996600;">println</span>(<span style="color: #CC0000;">"Starting..."</span>);
  TestFile.create_file(<span style="color: #CC0000;">"Sample.txt"</span>);  <span style="color: #777755;">//Create a file on the SD card named "Read_File_Test.txt"</span>
                                       <span style="color: #777755;">//NOTE: This function will return a 0 value if it was unable to create the file.</span>
  TestFile.open();  <span style="color: #777755;">//Now that the file has been created, open it so we can write to it.</span>
}

<span style="color: #CC6600;">void</span> <span style="color: #993300;"><b>loop</b></span>()
{
  TestFile.<span style="color: #996600;">write</span>(<span style="color: #CC0000;">"This is test data."</span>);  <span style="color: #777755;">//using the write function will always write to the beginning of the file. </span>
                                         <span style="color: #777755;">// Here we add some text to the file.</span>
  TestFile.close();  <span style="color: #777755;">//We are done writing to the file for now. Close it for later use.</span>

  <span style="color: #CC6600;">while</span>(1){
    TestFile.open();  <span style="color: #777755;">//Open the file. When the file is opened we will be looking at the beginning of the file.</span>
    read_size=TestFile.<span style="color: #996600;">read</span>(buffer); <span style="color: #777755;">//Read the contents of the file. This will only read the amount of data specified</span>
                                    <span style="color: #777755;">// by the size of 'buffer.'</span>

    <span style="color: #996600;">Serial</span>.<span style="color: #996600;">println</span>(read_size, <span style="color: #CC0000;">DEC</span>);  <span style="color: #777755;">//Print the number of characters read by the read function.</span>
    <span style="color: #CC6600;">for</span>(<span style="color: #996600;">int</span> i=0; i<read_size; i++)
    {
      <span style="color: #996600;">Serial</span>.<span style="color: #996600;">print</span>(buffer[i], <span style="color: #CC0000;">BYTE</span>);  <span style="color: #777755;">//Print out the contents of the buffer.</span>
    }
    <span style="color: #996600;">Serial</span>.<span style="color: #996600;">println</span>();

    sprintf(buffer, <span style="color: #CC0000;">"%d"</span>, count++); <span style="color: #777755;">//Now we'll use the buffer to write data back to the file. </span>
                                   <span style="color: #777755;">// Here's we'll only add one value to buffer, the 'count' variable. </span>
    TestFile.<span style="color: #996600;">write</span>(buffer);         <span style="color: #777755;">//Write the new buffer to the end of the file</span>
    TestFile.close();               <span style="color: #777755;">//Close the file for later use.</span>

    <span style="color: #996600;">delay</span>(1000);  <span style="color: #777755;">//Wait one second before repeating the loop.</span>
  }
}
</pre>
<p>这样Arduino在运行的时候，会不断地向SD卡模块上的Sample.txt文件中写入相应的数据，随后我们同样可以通过读卡器读出该文件中记录的内容。</p>
<p><img alt="" src="http://image.flamingoeda.com/albums/userpics/febb_sd_card_5.JPG" title="SD卡" class="aligncenter" width="460" height="345" /></p>
<p>需要注意的是，由于用来操作SD卡和文件系统的代码相对较多，目前该模块只能运行在带有ATmega328P的Arduino上面。另外，目前市场上可选的SD卡种类繁多，可能不是每种SD卡都能够被很好的兼容，目前我测试过通过的SD卡有：</p>
<ul>
<li>SanDisk 2GB SD2 Card</li>
<li>Apacer 60X 1GB SD Card</li>
</ul>
<p>测试没有通过的SD卡有：</p>
<ul>
<li>SanDisk 16MB SD Card</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.flamingoeda.com/2009/12/25/arduino-%e7%94%b5%e5%ad%90%e7%a7%af%e6%9c%a8-sd%e5%8d%a1%e5%ad%98%e5%82%a8%e6%a8%a1%e5%9d%97/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
