<?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中国</title>
	<atom:link href="http://blog.flamingoeda.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.flamingoeda.com</link>
	<description>Flamingo EDA</description>
	<lastBuildDate>Thu, 11 Mar 2010 05:05:30 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>FlamingoEDA 开通新浪微博</title>
		<link>http://blog.flamingoeda.com/2010/03/11/flamingoeda-%e5%bc%80%e9%80%9a%e6%96%b0%e6%b5%aa%e5%be%ae%e5%8d%9a/</link>
		<comments>http://blog.flamingoeda.com/2010/03/11/flamingoeda-%e5%bc%80%e9%80%9a%e6%96%b0%e6%b5%aa%e5%be%ae%e5%8d%9a/#comments</comments>
		<pubDate>Thu, 11 Mar 2010 05:03:30 +0000</pubDate>
		<dc:creator>flamingoeda</dc:creator>
				<category><![CDATA[FlamingoEDA]]></category>

		<guid isPermaLink="false">http://blog.flamingoeda.com/?p=586</guid>
		<description><![CDATA[嫌博客更新太慢的观众不妨去跟踪一下我们在新浪上的微博。
下面两个地址都可以访问：
http://t.sina.com.cn/1704547397
http://t.flamingoeda.com
]]></description>
			<content:encoded><![CDATA[<p>嫌博客更新太慢的观众不妨去跟踪一下我们在新浪上的微博。</p>
<p>下面两个地址都可以访问：<br />
<a href="http://t.sina.com.cn/1704547397">http://t.sina.com.cn/1704547397</a><br />
<a href="http://t.flamingoeda.com">http://t.flamingoeda.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.flamingoeda.com/2010/03/11/flamingoeda-%e5%bc%80%e9%80%9a%e6%96%b0%e6%b5%aa%e5%be%ae%e5%8d%9a/feed/</wfw:commentRss>
		<slash:comments>0</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 / ");
&#160;&#160;Serial.print(temp_f, DEC);
&#160;&#160;Serial.print("F. Humidity: ");
&#160;&#160;Serial.print(humidity);
&#160;&#160;Serial.println("%");

&#160;&#160;delay(2000);
}

下图是相应输出结果：

]]></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);
&#160;&#160;&#160;&#160;delay(500);
&#160;&#160;}
&#160;&#160;
&#160;&#160;for (i = 0; i < 100; i ++) {
&#160;&#160;&#160;&#160;digitalWrite(s2Pin, HIGH);
&#160;&#160;&#160;&#160;delay(50);
&#160;&#160;&#160;&#160;digitalWrite(s2Pin, LOW);
&#160;&#160;&#160;&#160;delay(50);
&#160;&#160;}
}

下面是拍摄的视频效果：
]]></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 before being written to the file
int read_size=0;   //Used as an indicator [...]]]></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>
		<item>
		<title>电子积木 触摸传感器 触摸按钮</title>
		<link>http://blog.flamingoeda.com/2009/12/10/%e7%94%b5%e5%ad%90%e7%a7%af%e6%9c%a8-%e8%a7%a6%e6%91%b8%e4%bc%a0%e6%84%9f%e5%99%a8-%e8%a7%a6%e6%91%b8%e6%8c%89%e9%92%ae/</link>
		<comments>http://blog.flamingoeda.com/2009/12/10/%e7%94%b5%e5%ad%90%e7%a7%af%e6%9c%a8-%e8%a7%a6%e6%91%b8%e4%bc%a0%e6%84%9f%e5%99%a8-%e8%a7%a6%e6%91%b8%e6%8c%89%e9%92%ae/#comments</comments>
		<pubDate>Wed, 09 Dec 2009 16:43:05 +0000</pubDate>
		<dc:creator>flamingoeda</dc:creator>
				<category><![CDATA[电子积木]]></category>
		<category><![CDATA[传感器]]></category>
		<category><![CDATA[触摸]]></category>

		<guid isPermaLink="false">http://blog.flamingoeda.com/?p=546</guid>
		<description><![CDATA[触摸开关去年曾经做过一个版本，当时使用的是一个胶封的芯片，体积比较大，而且一致性也不是很好，并且触摸部分的金属片是附加在按钮上的，制作起来比较复杂。这次做的触摸按钮解决了这两个问题，采用集成了了触摸芯片，并且直接在按钮上设置了一块触摸的区域，中间的焊盘可以很方便地连接其他的金属块，以方便实际中的使用：


连接方法仍然是通过传感器连接线，与传感器扩展板连接起来即可使用Arduino来进行处理了。

触摸按钮属于数字模块，在处理方式上同普通的按钮并没有什么区别，下面是实验时用到的代码：

int ledPin = 13;
int switchPin = 7;
int value = 0; 

void setup() {
&#160;&#160;pinMode(switchPin, INPUT);
&#160;&#160;pinMode(ledPin, OUTPUT);
&#160;&#160;Serial.begin(9600);
}

void loop() {
&#160;&#160;value&#160;=&#160;digitalRead(switchPin);
&#160;&#160;if (HIGH == value) {
&#160;&#160;&#160;&#160;digitalWrite(ledPin, HIGH);
&#160;&#160;}&#160;else {
&#160;&#160;&#160;&#160;digitalWrite(ledPin, LOW);
&#160;&#160;}
}

这个触摸按钮上的O1和O2两个跳线用来设置触摸传感器的工作模式，该传感器一共有4个工作模式，其中如下两种是最常使用的：

O1和O2都置高（H）：当人体触摸到金属片时输出低电压，当人体离开金属片时输出高电压，接触时间不能超过10秒
O1和O2都置低（L）：当人体触摸到金属片时输出低电压，当人体再次触摸到金属片时输出高电压，相当于一个翻转开关


]]></description>
			<content:encoded><![CDATA[<p>触摸开关去年曾经做过一个版本，当时使用的是一个胶封的芯片，体积比较大，而且一致性也不是很好，并且触摸部分的金属片是附加在按钮上的，制作起来比较复杂。这次做的触摸按钮解决了这两个问题，采用集成了了触摸芯片，并且直接在按钮上设置了一块触摸的区域，中间的焊盘可以很方便地连接其他的金属块，以方便实际中的使用：</p>
<p><img alt="" src="http://image.flamingoeda.com/albums/userpics/febb_touch_switch_1.JPG" title="触摸按钮" class="aligncenter" width="460" height="345" /><br />
<img alt="" src="http://image.flamingoeda.com/albums/userpics/febb_touch_switch_2.JPG" title="触摸按钮" class="aligncenter" width="460" height="345" /></p>
<p>连接方法仍然是通过传感器连接线，与传感器扩展板连接起来即可使用Arduino来进行处理了。<br />
<img alt="" src="http://image.flamingoeda.com/albums/userpics/febb_touch_switch_3.JPG" title="触摸按钮" class="aligncenter" width="460" height="345" /></p>
<p>触摸按钮属于数字模块，在处理方式上同普通的按钮并没有什么区别，下面是实验时用到的代码：</p>
<pre>
<span style="color: #CC6600;">int</span> ledPin = 13;
<span style="color: #CC6600;">int</span> switchPin = 7;
<span style="color: #CC6600;">int</span> value = 0; 

<span style="color: #CC6600;">void</span> <span style="color: #CC6600;"><b>setup</b></span>() {
&nbsp;&nbsp;<span style="color: #CC6600;">pinMode</span>(switchPin, <span style="color: #006699;">INPUT</span>);
&nbsp;&nbsp;<span style="color: #CC6600;">pinMode</span>(ledPin, <span style="color: #006699;">OUTPUT</span>);
&nbsp;&nbsp;<span style="color: #CC6600;">Serial</span>.<span style="color: #CC6600;">begin</span>(9600);
}

<span style="color: #CC6600;">void</span> <span style="color: #CC6600;"><b>loop</b></span>() {
&nbsp;&nbsp;value&nbsp;=&nbsp;<span style="color: #CC6600;">digitalRead</span>(switchPin);
&nbsp;&nbsp;<span style="color: #CC6600;">if</span> (<span style="color: #006699;">HIGH</span> == value) {
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #CC6600;">digitalWrite</span>(ledPin, <span style="color: #006699;">HIGH</span>);
&nbsp;&nbsp;}&nbsp;<span style="color: #CC6600;">else</span> {
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #CC6600;">digitalWrite</span>(ledPin, <span style="color: #006699;">LOW</span>);
&nbsp;&nbsp;}
}
</pre>
<p>这个触摸按钮上的O1和O2两个跳线用来设置触摸传感器的工作模式，该传感器一共有4个工作模式，其中如下两种是最常使用的：</p>
<ul>
<li>O1和O2都置高（H）：当人体触摸到金属片时输出低电压，当人体离开金属片时输出高电压，接触时间不能超过10秒</li>
<li>O1和O2都置低（L）：当人体触摸到金属片时输出低电压，当人体再次触摸到金属片时输出高电压，相当于一个翻转开关</li>
<ul>
<p><img alt="" src="http://image.flamingoeda.com/albums/userpics/febb_touch_switch_4.JPG" title="触摸按钮" class="aligncenter" width="460" height="345" /></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.flamingoeda.com/2009/12/10/%e7%94%b5%e5%ad%90%e7%a7%af%e6%9c%a8-%e8%a7%a6%e6%91%b8%e4%bc%a0%e6%84%9f%e5%99%a8-%e8%a7%a6%e6%91%b8%e6%8c%89%e9%92%ae/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>电子积木 60行程 滑动电位器</title>
		<link>http://blog.flamingoeda.com/2009/12/05/%e7%94%b5%e5%ad%90%e7%a7%af%e6%9c%a8-60%e8%a1%8c%e7%a8%8b-%e6%bb%91%e5%8a%a8%e7%94%b5%e4%bd%8d%e5%99%a8/</link>
		<comments>http://blog.flamingoeda.com/2009/12/05/%e7%94%b5%e5%ad%90%e7%a7%af%e6%9c%a8-60%e8%a1%8c%e7%a8%8b-%e6%bb%91%e5%8a%a8%e7%94%b5%e4%bd%8d%e5%99%a8/#comments</comments>
		<pubDate>Sat, 05 Dec 2009 14:26:29 +0000</pubDate>
		<dc:creator>flamingoeda</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[电子积木]]></category>

		<guid isPermaLink="false">http://blog.flamingoeda.com/?p=543</guid>
		<description><![CDATA[滑动电位器在类似于音量调节和参数调整这样的场所经常被使用到，其滑块能够滑动的距离称为行程，60行程即代表能够滑动60mm，是最常使用的一种行程大小。这个电子积木选用的就是60行程的滑动电位器：


使用上与其它基于电位器的电子积木一样，只需要用通用传感器连接线或者模拟传感器连接线，将其连接到某个模拟输入接口，如A5上：

然后再借助Arduino读出其值就可以，如下面的示例代码所示：

int sensorPin = 5;
int value = 0;

void setup() {
&#160;&#160;Serial.begin(9600);
}

void loop() {
&#160;&#160;value&#160;=&#160;analogRead(sensorPin);
&#160;&#160;Serial.println(value, DEC);
}

这样当滑块位于滑动电位器上的不同位置时，读出来的值会在0到1023间变连续变化。
]]></description>
			<content:encoded><![CDATA[<p>滑动电位器在类似于音量调节和参数调整这样的场所经常被使用到，其滑块能够滑动的距离称为行程，60行程即代表能够滑动60mm，是最常使用的一种行程大小。这个电子积木选用的就是60行程的滑动电位器：</p>
<p><img class="aligncenter" title="滑动电位器" src="http://image.flamingoeda.com/albums/userpics/febb_slide60_1.JPG" alt="" width="460" height="345" /></p>
<p><img class="aligncenter" title="滑动电位器" src="http://image.flamingoeda.com/albums/userpics/febb_slide60_2.JPG" alt="" width="460" height="345" /></p>
<p>使用上与其它基于电位器的电子积木一样，只需要用通用传感器连接线或者模拟传感器连接线，将其连接到某个模拟输入接口，如A5上：</p>
<p><img class="aligncenter" title="滑动电位器" src="http://image.flamingoeda.com/albums/userpics/febb_slide60_3.JPG" alt="" width="460" height="345" /></p>
<p>然后再借助Arduino读出其值就可以，如下面的示例代码所示：</p>
<pre>
<span style="color: #CC6600;">int</span> sensorPin = 5;
<span style="color: #CC6600;">int</span> value = 0;

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

<span style="color: #CC6600;">void</span> <span style="color: #CC6600;"><b>loop</b></span>() {
&nbsp;&nbsp;value&nbsp;=&nbsp;<span style="color: #CC6600;">analogRead</span>(sensorPin);
&nbsp;&nbsp;<span style="color: #CC6600;">Serial</span>.<span style="color: #CC6600;">println</span>(value, <span style="color: #006699;">DEC</span>);
}
</pre>
<p>这样当滑块位于滑动电位器上的不同位置时，读出来的值会在0到1023间变连续变化。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.flamingoeda.com/2009/12/05/%e7%94%b5%e5%ad%90%e7%a7%af%e6%9c%a8-60%e8%a1%8c%e7%a8%8b-%e6%bb%91%e5%8a%a8%e7%94%b5%e4%bd%8d%e5%99%a8/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>电子积木 串口适配器 MAX232</title>
		<link>http://blog.flamingoeda.com/2009/12/04/%e7%94%b5%e5%ad%90%e7%a7%af%e6%9c%a8-%e4%b8%b2%e5%8f%a3%e9%80%82%e9%85%8d%e5%99%a8-max232/</link>
		<comments>http://blog.flamingoeda.com/2009/12/04/%e7%94%b5%e5%ad%90%e7%a7%af%e6%9c%a8-%e4%b8%b2%e5%8f%a3%e9%80%82%e9%85%8d%e5%99%a8-max232/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 16:04:08 +0000</pubDate>
		<dc:creator>flamingoeda</dc:creator>
				<category><![CDATA[电子积木]]></category>

		<guid isPermaLink="false">http://blog.arduino.cn/?p=493</guid>
		<description><![CDATA[电子设备或者模块在需要同外界进行通信时，经常采用串行通信的方式，即逐位传输一系列二进制编码数据。基于单片机的电子设备的串口有很大一部分使用的是 TTL电平标准，它的逻辑1电平是5V，逻辑0电平是0V；而我们常用的PC机串行口所使用的却是RS-232C电平标准，它的逻辑1电平是 -3V~-12V，逻辑0电平是+3V~+12V。由于两者的电平范围相差很远，因此必须在RS-232C和TTL电路之间进行电平和逻辑关系的变换之 后，才能在PC机和这类电子设备间实现串行通信。一般来讲，实现这种变换的电路可以用分立元件搭建，也可以使用MAX232这样的集成电路芯片。

我们开发的电子积木串口适配器，就是采用了MAX232芯片的电平转换模块，可以很方便地在Arduino和PC间建立起串口通信。由于Arduino自带的是USB转串口的方案，实际使用时如果觉得复杂或是稳定性不够，可以考虑这一串品适配器，由于缺少了USB转串口这一中间环节，通信方式更加直接。不过目前该模块还只能用在Arduino MEGA上，并且只能用在串口COM1, COM2, COM3上，原因可能是COM0是直接同USB转串口芯片连接的，它与MAX232之间似乎不是很兼容。
基于串口的电子积木使用的都是4芯的IIC/COM连接线，利用它可以将串口适配器非常方便地连接到Arduino MEGA专用传感器扩展板上，从而完成同Arduino的通信：

最后再用一根串口线连接PC和串口适配器，硬件部分的连接就完成了：

至于软件部分，在PC端我们可以借用SSCOM这样的串口调试工具，而Arduino这端则使用如下的测试代码：
int val = 0;

void setup()
{
  Serial1.begin(9600);
}

void loop()
{
  val = Serial1.read();
  if (-1 != val) {
   if ('A' == val &#124;&#124; 'a' == val) {
     Serial1.println("Hello from Arduino!");
   }
  }
}
将上述代码下载到Arduino中执行后，Arduino会一直等待从PC端过来的命令，如果按受到字符A，则向PC端发送&#8221;Hello from Arduino!&#8221;这一字符串：

]]></description>
			<content:encoded><![CDATA[<p>电子设备或者模块在需要同外界进行通信时，经常采用串行通信的方式，即逐位传输一系列二进制编码数据。基于单片机的电子设备的串口有很大一部分使用的是 TTL电平标准，它的逻辑1电平是5V，逻辑0电平是0V；而我们常用的PC机串行口所使用的却是RS-232C电平标准，它的逻辑1电平是 -3V~-12V，逻辑0电平是+3V~+12V。由于两者的电平范围相差很远，因此必须在RS-232C和TTL电路之间进行电平和逻辑关系的变换之 后，才能在PC机和这类电子设备间实现串行通信。一般来讲，实现这种变换的电路可以用分立元件搭建，也可以使用MAX232这样的集成电路芯片。</p>
<p><img class="aligncenter" title="MAX232" src="http://image.flamingoeda.com/albums/userpics/MAX232_1.JPG" alt="" width="460" height="345" /></p>
<p>我们开发的电子积木串口适配器，就是采用了MAX232芯片的电平转换模块，可以很方便地在Arduino和PC间建立起串口通信。由于Arduino自带的是USB转串口的方案，实际使用时如果觉得复杂或是稳定性不够，可以考虑这一串品适配器，由于缺少了USB转串口这一中间环节，通信方式更加直接。不过目前该模块还只能用在Arduino MEGA上，并且只能用在串口COM1, COM2, COM3上，原因可能是COM0是直接同USB转串口芯片连接的，它与MAX232之间似乎不是很兼容。</p>
<p>基于串口的电子积木使用的都是4芯的IIC/COM连接线，利用它可以将串口适配器非常方便地连接到Arduino MEGA专用传感器扩展板上，从而完成同Arduino的通信：</p>
<p><img class="aligncenter" title="MAX232" src="http://image.flamingoeda.com/albums/userpics/MAX232_2.JPG" alt="" width="460" height="345" /></p>
<p>最后再用一根串口线连接PC和串口适配器，硬件部分的连接就完成了：</p>
<p><img class="aligncenter" title="MAX232" src="http://image.flamingoeda.com/albums/userpics/MAX232_3.JPG" alt="" width="460" height="345" /></p>
<p>至于软件部分，在PC端我们可以借用SSCOM这样的串口调试工具，而Arduino这端则使用如下的测试代码：</p>
<pre><span style="color: #996600;">int</span> val = 0;

<span style="color: #CC6600;">void</span> <span style="color: #993300;"><strong>setup</strong></span>()
{
  Serial1.<span style="color: #996600;">begin</span>(9600);
}

<span style="color: #CC6600;">void</span> <span style="color: #993300;"><strong>loop</strong></span>()
{
  val = Serial1.<span style="color: #996600;">read</span>();
  <span style="color: #CC6600;">if</span> (-1 != val) {
   <span style="color: #CC6600;">if</span> (<span style="color: #CC0000;">'A'</span> == val || <span style="color: #CC0000;">'a'</span> == val) {
     Serial1.<span style="color: #996600;">println</span>(<span style="color: #CC0000;">"Hello from Arduino!"</span>);
   }
  }
}</pre>
<p>将上述代码下载到Arduino中执行后，Arduino会一直等待从PC端过来的命令，如果按受到字符A，则向PC端发送&#8221;Hello from Arduino!&#8221;这一字符串：<br />
<img class="aligncenter size-full wp-image-540" title="max232_sscom" src="http://blog.flamingoeda.com/wp-content/uploads/2009/12/max232_sscom.jpg" alt="max232_sscom" width="460" height="291" /></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.flamingoeda.com/2009/12/04/%e7%94%b5%e5%ad%90%e7%a7%af%e6%9c%a8-%e4%b8%b2%e5%8f%a3%e9%80%82%e9%85%8d%e5%99%a8-max232/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>电子积木 串行液晶显示屏 字符型 1602 LCD</title>
		<link>http://blog.flamingoeda.com/2009/11/29/%e7%94%b5%e5%ad%90%e7%a7%af%e6%9c%a8-%e4%b8%b2%e8%a1%8c%e6%b6%b2%e6%99%b6%e6%98%be%e7%a4%ba%e5%b1%8f-%e5%ad%97%e7%ac%a6%e5%9e%8b-1602-lcd/</link>
		<comments>http://blog.flamingoeda.com/2009/11/29/%e7%94%b5%e5%ad%90%e7%a7%af%e6%9c%a8-%e4%b8%b2%e8%a1%8c%e6%b6%b2%e6%99%b6%e6%98%be%e7%a4%ba%e5%b1%8f-%e5%ad%97%e7%ac%a6%e5%9e%8b-1602-lcd/#comments</comments>
		<pubDate>Sun, 29 Nov 2009 15:09:19 +0000</pubDate>
		<dc:creator>flamingoeda</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[电子积木]]></category>

		<guid isPermaLink="false">http://blog.flamingoeda.com/?p=535</guid>
		<description><![CDATA[1602字符型液晶显示屏是电子制作中经常用到的一个模拟，它可以用来显示两排字符，每排16个字符：

不过，要控制这样一个常用的模块，其实也不是那么容易。首先，我们要按照其4线或者8线的工作模式，占用相应的Arduino引脚，但这样其实占用了较多的数字I/O引脚，特别是8线的连接方式。再次，虽然有相应的库可以支持，但要将其调试通过，并在Arduino上成功运行起来，相应也会遇到不少的问题。最后，控制液晶的代码需要占用相应的存储空间，这对于本来就不富裕的16K存储空间的Arduino来讲，无疑就是雪上加霜。
为了解决这些问题，我们设计了这款基于1602字符型LCD的串行液晶显示屏，与之前的做法相比，优点是很明显的：

采用串口进行控制，硬件连线降到最少；
不占用Arduino的存储空间；
成功验证的代码，将调试时间降到最低。


与传感器扩展板和专用连接线配合，可以非常容易地与Arduino连接上：

为了演示其功能，我在传感器扩展板上还接了一个按钮模块，当按钮按下时，Arduino会通过串口向液晶屏发送相应的命令进行控制。该模块上电时的效果如图所示

在Arduino里运行的代码为：

int switchPin = 7;
int value = 0;

void setup() {
&#160;&#160;Serial.begin(9600);
&#160;&#160;pinMode(switchPin, INPUT);
}

void loop() {
&#160;&#160;if (HIGH == digitalRead(switchPin)){
&#160;&#160;&#160;&#160;Serial.print("$CLEAR\r\n");
&#160;&#160;&#160;&#160;Serial.print("$GO 1 1\r\n");
&#160;&#160;&#160;&#160;Serial.print("$PRINT Flamingo  EDA\r\n");
&#160;&#160;&#160;&#160;Serial.print("$GO 2 4\r\n");
&#160;&#160;&#160;&#160;Serial.print("$PRINT Hello World!\r\n");
&#160;&#160;&#160;&#160;Serial.print("$CURSOR 1 1\r\n");
&#160;&#160;}
}

对照代码你可以看出，所有对该液晶屏进行控制的串口命令都以字符&#8221;$&#8221;开始，以回车按行&#8221;\r\n&#8221;结束，两者之间是相应的命令和参数，不同的命令具有不同的参数。

GO 光标移动
PRINT 在当前光标位置上显示字符串
CLEAR 清屏
HOME 将光标移回到屏幕左上角的初始位置
CURSOR 设置光标效果，第一个参数为是否显示光标（1和0），第二个参数为是否闪烁（1和0）

当Arduino检测到按钮按下时，会向连接在串口上的串行液晶显示屏发送相应的控制命令，效果如下图所示：

]]></description>
			<content:encoded><![CDATA[<p>1602字符型液晶显示屏是电子制作中经常用到的一个模拟，它可以用来显示两排字符，每排16个字符：</p>
<p><img class="aligncenter" title="1602" src="http://image.flamingoeda.com/albums/userpics/serial_lcd_1602_1.jpg" alt="" width="460" height="345" /></p>
<p>不过，要控制这样一个常用的模块，其实也不是那么容易。首先，我们要按照其4线或者8线的工作模式，占用相应的Arduino引脚，但这样其实占用了较多的数字I/O引脚，特别是8线的连接方式。再次，虽然有相应的库可以支持，但要将其调试通过，并在Arduino上成功运行起来，相应也会遇到不少的问题。最后，控制液晶的代码需要占用相应的存储空间，这对于本来就不富裕的16K存储空间的Arduino来讲，无疑就是雪上加霜。</p>
<p>为了解决这些问题，我们设计了这款基于1602字符型LCD的串行液晶显示屏，与之前的做法相比，优点是很明显的：</p>
<ul>
<li>采用串口进行控制，硬件连线降到最少；</li>
<li>不占用Arduino的存储空间；</li>
<li>成功验证的代码，将调试时间降到最低。</li>
</ul>
<p><img class="aligncenter" title="1602" src="http://image.flamingoeda.com/albums/userpics/serial_lcd_1602_2.jpg" alt="" width="460" height="345" /></p>
<p>与传感器扩展板和专用连接线配合，可以非常容易地与Arduino连接上：</p>
<p><img class="aligncenter" title="1602" src="http://image.flamingoeda.com/albums/userpics/serial_lcd_1602_3.jpg" alt="" width="460" height="345" /></p>
<p>为了演示其功能，我在传感器扩展板上还接了一个按钮模块，当按钮按下时，Arduino会通过串口向液晶屏发送相应的命令进行控制。该模块上电时的效果如图所示</p>
<p><img class="aligncenter" title="1602" src="http://image.flamingoeda.com/albums/userpics/serial_lcd_1602_4.jpg" alt="" width="460" height="345" /></p>
<p>在Arduino里运行的代码为：</p>
<pre>
<span style="color: #CC6600;">int</span> switchPin = 7;
<span style="color: #CC6600;">int</span> value = 0;

<span style="color: #CC6600;">void</span> <span style="color: #CC6600;"><b>setup</b></span>() {
&nbsp;&nbsp;<span style="color: #CC6600;">Serial</span>.<span style="color: #CC6600;">begin</span>(9600);
&nbsp;&nbsp;<span style="color: #CC6600;">pinMode</span>(switchPin, <span style="color: #006699;">INPUT</span>);
}

<span style="color: #CC6600;">void</span> <span style="color: #CC6600;"><b>loop</b></span>() {
&nbsp;&nbsp;<span style="color: #CC6600;">if</span> (<span style="color: #006699;">HIGH</span> == <span style="color: #CC6600;">digitalRead</span>(switchPin)){
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #CC6600;">Serial</span>.<span style="color: #CC6600;">print</span>(<span style="color: #006699;">"$CLEAR\r\n"</span>);
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #CC6600;">Serial</span>.<span style="color: #CC6600;">print</span>(<span style="color: #006699;">"$GO 1 1\r\n"</span>);
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #CC6600;">Serial</span>.<span style="color: #CC6600;">print</span>(<span style="color: #006699;">"$PRINT Flamingo  EDA\r\n"</span>);
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #CC6600;">Serial</span>.<span style="color: #CC6600;">print</span>(<span style="color: #006699;">"$GO 2 4\r\n"</span>);
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #CC6600;">Serial</span>.<span style="color: #CC6600;">print</span>(<span style="color: #006699;">"$PRINT Hello World!\r\n"</span>);
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #CC6600;">Serial</span>.<span style="color: #CC6600;">print</span>(<span style="color: #006699;">"$CURSOR 1 1\r\n"</span>);
&nbsp;&nbsp;}
}
</pre>
<p>对照代码你可以看出，所有对该液晶屏进行控制的串口命令都以字符&#8221;$&#8221;开始，以回车按行&#8221;\r\n&#8221;结束，两者之间是相应的命令和参数，不同的命令具有不同的参数。</p>
<ol>
<li>GO 光标移动</li>
<li>PRINT 在当前光标位置上显示字符串</li>
<li>CLEAR 清屏</li>
<li>HOME 将光标移回到屏幕左上角的初始位置</li>
<li>CURSOR 设置光标效果，第一个参数为是否显示光标（1和0），第二个参数为是否闪烁（1和0）</li>
</ol>
<p>当Arduino检测到按钮按下时，会向连接在串口上的串行液晶显示屏发送相应的控制命令，效果如下图所示：</p>
<p><img class="aligncenter" title="1602" src="http://image.flamingoeda.com/albums/userpics/serial_lcd_1602_5.jpg" alt="" width="460" height="345" /></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.flamingoeda.com/2009/11/29/%e7%94%b5%e5%ad%90%e7%a7%af%e6%9c%a8-%e4%b8%b2%e8%a1%8c%e6%b6%b2%e6%99%b6%e6%98%be%e7%a4%ba%e5%b1%8f-%e5%ad%97%e7%ac%a6%e5%9e%8b-1602-lcd/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>电子积木 控制杆 JoyStick</title>
		<link>http://blog.flamingoeda.com/2009/11/15/%e7%94%b5%e5%ad%90%e7%a7%af%e6%9c%a8-%e6%8e%a7%e5%88%b6%e6%9d%86-joystick/</link>
		<comments>http://blog.flamingoeda.com/2009/11/15/%e7%94%b5%e5%ad%90%e7%a7%af%e6%9c%a8-%e6%8e%a7%e5%88%b6%e6%9d%86-joystick/#comments</comments>
		<pubDate>Sun, 15 Nov 2009 08:46:37 +0000</pubDate>
		<dc:creator>flamingoeda</dc:creator>
				<category><![CDATA[电子积木]]></category>
		<category><![CDATA[joystick]]></category>

		<guid isPermaLink="false">http://blog.flamingoeda.com/?p=522</guid>
		<description><![CDATA[但凡玩过点游戏的对这个控制杆肯定不陌生，它可以用来对控制物体在二维平面内（X和Y方向）的运动，不知道加上Arduino后又能够变换出什么样的不同创意来。

从原理上来讲，这个控制杆可以看成由两个电位器和一个按钮组成：

其中两个电位器的输入值分别用来表示用户在X和Y轴上的偏移量，其类型为模拟量；而按钮则用来表示用户是否在Z轴上按下，其类型为数字量。因此该控制杆一共有三个输入接口，分别用来连接X、Y和Z：

具体使用的时候，可以和Arduino传感器扩展板结合起来，用相应的连接线与Arduino上对应的引脚连接起来。在下面的例子中，X和Y轴分别连接在模拟输入端口A0和A1上，而Z轴则连接在数字I/O的7号引脚上：

相应的代码如下所示：

int sensorPin = 5;
int value = 0;

void setup() {
  pinMode(7, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  value = analogRead(0);
  Serial.print("X:");
  Serial.print(value, DEC);

  value = analogRead(1);
  Serial.print(" &#124; Y:");
  Serial.print(value, DEC);

  value = digitalRead(7);
  Serial.print(" &#124; Z: ");
  Serial.println(value, DEC);

  delay(100);
}

好了，刚始玩吧;-)
]]></description>
			<content:encoded><![CDATA[<p>但凡玩过点游戏的对这个控制杆肯定不陌生，它可以用来对控制物体在二维平面内（X和Y方向）的运动，不知道加上Arduino后又能够变换出什么样的不同创意来。</p>
<p><img alt="" src="http://image.flamingoeda.com/albums/userpics/joystick.jpg" title="JoyStick" class="aligncenter" width="460" height="345" /></p>
<p>从原理上来讲，这个控制杆可以看成由两个电位器和一个按钮组成：</p>
<p><img alt="" src="http://image.flamingoeda.com/albums/userpics/joystick_1.jpg" title="JoyStick" class="aligncenter" width="460" height="345" /></p>
<p>其中两个电位器的输入值分别用来表示用户在X和Y轴上的偏移量，其类型为模拟量；而按钮则用来表示用户是否在Z轴上按下，其类型为数字量。因此该控制杆一共有三个输入接口，分别用来连接X、Y和Z：</p>
<p><img alt="" src="http://image.flamingoeda.com/albums/userpics/joystick_3.jpg" title="JoyStick" class="aligncenter" width="460" height="345" /></p>
<p>具体使用的时候，可以和Arduino传感器扩展板结合起来，用相应的连接线与Arduino上对应的引脚连接起来。在下面的例子中，X和Y轴分别连接在模拟输入端口A0和A1上，而Z轴则连接在数字I/O的7号引脚上：</p>
<p><img alt="" src="http://image.flamingoeda.com/albums/userpics/joystick_4.jpg" title="JoyStick" class="aligncenter" width="460" height="345" /></p>
<p>相应的代码如下所示：</p>
<pre>
<span style="color: #996600;">int</span> sensorPin = 5;
<span style="color: #996600;">int</span> value = 0;

<span style="color: #CC6600;">void</span> <span style="color: #993300;"><b>setup</b></span>() {
  <span style="color: #996600;">pinMode</span>(7, <span style="color: #CC0000;">OUTPUT</span>);
  <span style="color: #996600;">Serial</span>.<span style="color: #996600;">begin</span>(9600);
}

<span style="color: #CC6600;">void</span> <span style="color: #993300;"><b>loop</b></span>() {
  value = <span style="color: #996600;">analogRead</span>(0);
  <span style="color: #996600;">Serial</span>.<span style="color: #996600;">print</span>(<span style="color: #CC0000;">"X:"</span>);
  <span style="color: #996600;">Serial</span>.<span style="color: #996600;">print</span>(value, <span style="color: #CC0000;">DEC</span>);

  value = <span style="color: #996600;">analogRead</span>(1);
  <span style="color: #996600;">Serial</span>.<span style="color: #996600;">print</span>(<span style="color: #CC0000;">" | Y:"</span>);
  <span style="color: #996600;">Serial</span>.<span style="color: #996600;">print</span>(value, <span style="color: #CC0000;">DEC</span>);

  value = <span style="color: #996600;">digitalRead</span>(7);
  <span style="color: #996600;">Serial</span>.<span style="color: #996600;">print</span>(<span style="color: #CC0000;">" | Z: "</span>);
  <span style="color: #996600;">Serial</span>.<span style="color: #996600;">println</span>(value, <span style="color: #CC0000;">DEC</span>);

  <span style="color: #996600;">delay</span>(100);
}
</pre>
<p>好了，刚始玩吧;-)</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.flamingoeda.com/2009/11/15/%e7%94%b5%e5%ad%90%e7%a7%af%e6%9c%a8-%e6%8e%a7%e5%88%b6%e6%9d%86-joystick/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
