<?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/tag/%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>电子积木 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>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>
