<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
   <channel>
      <title>四谷工作研究所</title>
      <link>http://www.artstudium.org/kousaku/</link>
      <description></description>
      <language>ja</language>
      <copyright>Copyright 2008</copyright>
      <lastBuildDate>Sat, 20 Oct 2007 14:06:05 +0900</lastBuildDate>
      <generator>http://www.sixapart.com/movabletype/</generator>
      <docs>http://blogs.law.harvard.edu/tech/rss</docs> 

            <item>
         <title>サーボを動かす方法</title>
         <description><![CDATA[<a href="http://www.artstudium.org/kousaku/2007/06/flash_1.html" target="_blank">以前</a>試したサーボを動かす方法は、20msの間に、heightとlowをつくる方法だった。
今回は、可変抵抗をセンサーにして、前回の方法も含め3つの方法で試してみる。

<h3>1 │ analogWriteコマンドを使う</h3>

<pre>
void setup(){
  pinMode(3,OUTPUT);
}
void loop(){
  int val=analogRead(0)/4; // (0～1023)/4
  analogWrite(3,val); // (0～255)
  delay(20);
}
</pre>

この方法は、
Arduino基盤にpwmと書いてあるポートにだけ可能。
分解能は、256
※サーボのメーカーによっては、動かないときがある。

<h3>2 │ Servoオブジェクトを使う</h3>

<a href="http://www.arduino.cc/playground/uploads/ComponentLib/servo.zip" target="_blank">ここ</a>からオブジェクトをダウンロードして、Arduinoのフォルダのなかのlib/targets/librariesに入れてArduinoを起動する。

<pre>
#include &lt;Servo.h&gt;
Servo servo;
void setup() {
  servo.attach(3);
}
void loop(){
  float val=analogRead(0)*180.00/1023;
  servo.write(int(val));
  delay(20);
  Servo::refresh();
}
</pre>

この方法は、
どのポートでも可能
分解能は、180
※arduinoのバージョン8以上で動作します

<h3>3 │1024の分解能をつかう</h3>

<pre>
void setup(){
  pinMode(3,OUTPUT);
}
void loop(){
  int val=analogRead(0)*2; //1023を2倍して、振幅を約2000として
  digitalWrite(3,HIGH);
  delayMicroseconds(val+500); //振幅値+最小パルス500
  digitalWrite(3,LOW);
  delayMicroseconds(20000-val-500); //20msから上記のパルス長を差し引いて、常に20ms(20000us)にサイクルに調整する。
}
</pre>

これは、<a href="http://www.artstudium.org/kousaku/2007/06/flash_1.html" target="_blank">以前</a>試した方法と同じ。

]]></description>
         <link>http://www.artstudium.org/kousaku/2007/10/post_12.html</link>
         <guid>http://www.artstudium.org/kousaku/2007/10/post_12.html</guid>
                  <category domain="http://www.sixapart.com/ns/types#category">Arduino</category>
        
        
         <pubDate>Sat, 20 Oct 2007 14:06:05 +0900</pubDate>
      </item>
            <item>
         <title>Flashから交流電源をコントロール</title>
         <description><![CDATA[<a href="http://www.artstudium.org/kousaku/2007/09/flash_5.html" target="_blank">前回のリレースイッチ</a>では、電源のON/OFFしかできませんでした。
今回扱はAC電源をコントロールして、電球の明るさをコントロールします。
<object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/giDazlA3wb8"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/giDazlA3wb8" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object>

<img alt="ac_cont01.jpg" src="http://www.artstudium.org/kousaku/images/ac_cont01.jpg" width="500" height="440" />

<a href="http://www.artstudium.org/kousaku/archive/flash_arduino_ac.zip">ソースをダウンロード</a>

<strong>必要なもの</strong>
<img alt="ac_cont_trai.jpg" src="http://www.artstudium.org/kousaku/images/ac_cont_trai.jpg" width="300" height="300" />
<a href="http://akizukidenshi.com/catalog/items2.php?q=%22I-01017%22&s=score&p=1&r=1&page=" target="_blank">トライアック</a>
<img alt="ac_cont_phototrai.jpg" src="http://www.artstudium.org/kousaku/images/ac_cont_phototrai.jpg" width="300" height="300" />
<a href="http://akizukidenshi.com/catalog/items2.php?q=%22I-01396%22&s=score&p=1&r=1&page=" target="_blank">フォトトラアック（非クロスゼロ）</a>
<img alt="ac_cont_phototcap.jpg" src="http://www.artstudium.org/kousaku/images/ac_cont_phototcap.jpg" width="300" height="300" />
<a href="http://www.sengoku.co.jp/modules/sgk_cart/search.php?toku=&cond8=and&dai=&chu=&syo=&cond9=&k3=2&list=2&pflg=n&multi=&code=2ACA-C6EU" target="_blank">フォトカプラ</a>
<img alt="ac_cont_con.jpg" src="http://www.artstudium.org/kousaku/images/ac_cont_con.jpg" width="300" height="300" />
フィルムコンデンサ
<img alt="ac_cont_trance.jpg" src="http://www.artstudium.org/kousaku/images/ac_cont_trance.jpg" width="300" height="300" />
<a href="http://www.toyoden-net.co.jp/shop/goods/goods.asp?goods=2710" target="_blank">トランス</a>
そのほか、抵抗、電球、配線、基盤など

<h3>1 | トライアックで電源の切替する</h3>

交流電力をコントロールするには、交流のサイン波をカットすることで調整します。
<img alt="ac_cont_zu3.gif" src="http://www.artstudium.org/kousaku/images/ac_cont_zu3.gif" width="455" height="167" />

リレースイッチでは、切替に時間がかかるので、
交流のトランジスターにあたるトライアックを使用します。

トライアックへの切り替えトリガーパルスを送るために、
AC100Vの電源をarduinoに直結させるのは、
危険なためフォトトライアック使って絶縁させます。
arduinoから、フォトトライアックに1msのトリガーパルスを送ることで、
トライアックに間接的にトリガーパルスを送ります。

回路右側のコンデンサーと抵抗は、高周波ノイズを取るための回路です。

<img alt="ac_cont_zu2.gif" src="http://www.artstudium.org/kousaku/images/ac_cont_zu2.gif" width="457" height="223" />

<img alt="ac_cont02.jpg" src="http://www.artstudium.org/kousaku/images/ac_cont02.jpg" width="500" height="449" />


<h3>2 | 交流の周期を読み込む</h3>

交流のサイン波を切り取るために、交流の周期を知る必要があります。

交流の周期を読み込むのに、トランスで6Vに降圧後、
フォトカプラでパルスに変換します。
フォトカプラは、交流が0Vになる地点で、パルスを送ってきます。
AC50Hzの場合、1秒間に100回パルスを送ってきます。

<img alt="ac_cont_zu4.gif" src="http://www.artstudium.org/kousaku/images/ac_cont_zu4.gif" width="431" height="273" />

<img alt="ac_cont_zu1.gif" src="http://www.artstudium.org/kousaku/images/ac_cont_zu1.gif" width="491" height="211" />

<img alt="ac_cont03.jpg" src="http://www.artstudium.org/kousaku/images/ac_cont03.jpg" width="548" height="480" />

<strong>ソフト上の処理</strong>
arduinoでパルスの割り込みには、<a href="http://www.arduino.cc/en/Reference/AttachInterrupt" target="_blank">attachInterrupt</a>を使います。
attachInterruptは最初に、setupの中で、パルス割り込み宣言します。

<pre>
attachInterrupt(0, zeroPulse, RISING);
</pre>

attachInterruptの
引数1つ目は、使うポート名（Digital2→0に対応）
引数2つ目は、割り込み関数名
引数3つ目は、パルスが立ち上がりか、立ち下がりかを選択

割り込み関数の中では、delay関数を使えないので、フラグの変化をさせています。

<pre>
void zeroPulse()
{
  zeroFlg = 1;
}
</pre>


<h3>3 | arduinoでパルスコントロール</h3>

arduinoからパルスを出すには、
フォトカプラからのパルスで割り込み後、zeroFlgが1になります。
delayMicrosecondsで、時間待ちをして、
1msのパルスをフォトトライアックに送信します。

<pre>
delayMicroseconds(delayTime);
digitalWrite(triggerPin, HIGH);
delay(1);
digitalWrite(triggerPin, LOW);
</pre>

<strong>フォトトライアックへのパルス出力待ち時間計算</strong>
arduinoは1ms以下のパルスを出すと、不安定になるので、パルスは1msとしました。
10ms-1ms=9msを、255で割ります。
9000μs ÷ 255 ≒ 35
フォトカプラからのパルスは、交流0Vになる前に57μsずれがあるので、
遅延時間は以下のようになります。

<pre>
delayTime = 57 + (255 - sum) * 39;
</pre>

それと、
出力電源が不安定なため、電力が0に近く小さい時と、
電力が大きく100%に近い時は、
上記の式を使わず、0V、100V出力にしています。

今回のarduinoでの交流のコントロールは、delay関数の不安定なことや、割り込み処理ができないために不安定なので、使う用途によって応答処理をするなど、ソースを改良する必要があります。]]></description>
         <link>http://www.artstudium.org/kousaku/2007/10/flash_4.html</link>
         <guid>http://www.artstudium.org/kousaku/2007/10/flash_4.html</guid>
                  <category domain="http://www.sixapart.com/ns/types#category">Arduino</category>
                  <category domain="http://www.sixapart.com/ns/types#category">Flash</category>
        
        
         <pubDate>Tue, 02 Oct 2007 16:37:19 +0900</pubDate>
      </item>
            <item>
         <title>電子工作入門書</title>
         <description><![CDATA[電気工作は、専門分野なので、入門書も多いですが、
理系以外の人でも、理解しやすい本を紹介。

<h3>独習 電気/電子工学 </h3>
<a href="http://www.amazon.co.jp/dp/479811328X/module-22">
<img alt="book_dokusyu.jpg" src="http://www.artstudium.org/kousaku/images/book_dokusyu.jpg" width="187" height="240" /></a>

浅く広く電気と電子の基本が、学習できます。
中学レベルの数学や、理科の知識があれば、
読めるように書かれているところもうれしい。

<h3>作る、できる/基礎入門電子工作の素 </h3>
<a href="http://www.amazon.co.jp/dp/4774130788/module-22">
<img alt="book_moto.jpg" src="http://www.artstudium.org/kousaku/images/book_moto.jpg" width="170" height="240" /></a>

<a href="http://www.picfun.com/" target="_blank">電気工作の実験室</a>でpicを紹介されている、後閑 哲也氏の工作入門書。
こちらは、浅く広く具体的なパーツをあげながら、
作り方と考え方の基本の勘所が分かりやすく書かれている。
]]></description>
         <link>http://www.artstudium.org/kousaku/2007/09/post_11.html</link>
         <guid>http://www.artstudium.org/kousaku/2007/09/post_11.html</guid>
                  <category domain="http://www.sixapart.com/ns/types#category">book</category>
        
        
         <pubDate>Wed, 26 Sep 2007 21:33:19 +0900</pubDate>
      </item>
            <item>
         <title>Flashから100Vの電球をつける</title>
         <description><![CDATA[<img alt="denki1.jpg" src="http://www.artstudium.org/kousaku/images/denki1.jpg" width="500" height="375" />

100Vの交流電源をコンセントから持ってきて、Flashから電球をつけてみる。

<strong>必要な物</strong>

リレー（<a href="http://www.omron.co.jp/ecb/products/pry/121/g2r_1_e.html" target="_blank">G2R-1-E</a>）
トランジスター（2SC1815）
抵抗（2k,220）
電球、電球ソケット、コンセント、基盤、配線など

ArduinoとFlashの仕組みは、<a href="http://www.artstudium.org/kousaku/2007/06/flashwindows.html" target="_blank">LEDをつける</a>のと同じで、残りは回路を組めばできる。

<img alt="denki2.jpg" src="http://www.artstudium.org/kousaku/images/denki2.jpg" width="300" height="300" />
<img alt="denkyu4.jpg" src="http://www.artstudium.org/kousaku/images/denkyu4.jpg" width="447" height="500" />

最初は簡単にリレーを使って、5Vの信号で、100Vの交流の切替をしようとした。
ところが、リレーとArduinoからのON/OFFの信号をつなぐと、電流量が足りなく、
トランジスターで、電流を調整する必要が出てきた。

<img alt="denkyu_zu.gif" src="http://www.artstudium.org/kousaku/images/denkyu_zu.gif" width="284" height="295" />

トランジスターで調整する電流は、抵抗値で変更する。
計算は以下のとおり。

リレーを動かすには、106mAの電流、トランジスターの増幅率100なので、
ドライブ電流 = 106mA / 100 = 1.06mA
ドライブ電流は、安全をみて、2mAとした。
NPNトランジスターなので、
<strong>抵抗 = (ON電圧 - 0.6V) ÷ (最大ベース電圧)</strong>
より
(5 - 0.6)V ÷ 2mA = 2.2kΩ
手元にある抵抗で、2kΩを使うことにした。

<img alt="denki3.jpg" src="http://www.artstudium.org/kousaku/images/denki3.jpg" width="300" height="300" />

あとは、リレーを、コンセントと接続して、電球につなげれば完成する。
この仕組みができれば、簡単にパソコンから家電の電源切替ができるようになる。]]></description>
         <link>http://www.artstudium.org/kousaku/2007/09/flash_5.html</link>
         <guid>http://www.artstudium.org/kousaku/2007/09/flash_5.html</guid>
                  <category domain="http://www.sixapart.com/ns/types#category">Arduino</category>
                  <category domain="http://www.sixapart.com/ns/types#category">Flash</category>
        
        
         <pubDate>Thu, 20 Sep 2007 01:40:50 +0900</pubDate>
      </item>
            <item>
         <title>必要な電圧の電流を作る</title>
         <description><![CDATA[Arduinoは、5Vの電源で動くが、装置によっては電圧を用意する必要がある。
電圧を、作る方法をいくつか上げてみた。

1．ACアダプタ
2．レギュレータ
3．DC-DCコンバータ
4．スイッチング電源

<h3>1．ACアダプタ</h3>

コンセントに差し込めば、回路を組まずに、すぐ使えるので、便利。
<img alt="denki_ac.jpg" src="http://www.artstudium.org/kousaku/images/denki_ac.jpg" width="500" height="400" />

<h3>2．レギュレータ</h3>

コンセントが使えなく、電池で安定した電圧が必要なときは、レギュレータを使用する。
レギュレータは、必要な電圧よりも、入力電圧を高くする必要がある。
<img alt="denki_reg.jpg" src="http://www.artstudium.org/kousaku/images/denki_reg.jpg" width="500" height="374" />
<img alt="denki_reg2.jpg" src="http://www.artstudium.org/kousaku/images/denki_reg2.jpg" width="500" height="412" />

<h3>3．DC-DCコンバータ</h3>

レギュレータは、不要な電圧を放熱することで、安定した電圧を作っていたが、長時間電池を持たせたいときなど、エネルギー効率を良くしたい時に使う。
レギュレータとは違い、小さい電圧から大きな電圧を作る昇圧も可能。
写真は、<a href="http://www.bellnix.co.jp/catalog/23BSI10-15W.pdf" target="_blank">BSI-5.0S3R0A</a>エネルギーは効率95%と高いが、
コンデンサーは、<a href="http://www.edc.sanyo.com/products/capacitor/oscon/outline.html" target="_blank">OS-CON</a>を使わないと、ノイズで動かない時があった。
<img alt="denki_dc_dc.jpg" src="http://www.artstudium.org/kousaku/images/denki_dc_dc.jpg" width="500" height="365" />
<img alt="denki_dc_dc1.jpg" src="http://www.artstudium.org/kousaku/images/denki_dc_dc1.jpg" width="500" height="375" />

<h3>4．スイッチング電源</h3>

24Vなど、大きな電圧を作るときに、ACアダプタでは間に合わないときに使う。
写真は<a href="http://www.eta.co.jp/" target="_blank">イーター電気工業</a>製B<a href="http://www.sengoku.co.jp/modules/sgk_cart/search.php?toku=&cond8=and&dai=&chu=&syo=&cond9=&k3=2&list=2&pflg=n&multi=&code=8ACG-8GF3" target="_blank">SD24SA-U</a>。
電源コネクターは別売りなので、買って作る必要がある。
<img alt="denki_sw0.jpg" src="http://www.artstudium.org/kousaku/images/denki_sw0.jpg" width="500" height="375" />
<img alt="denki_sw1.jpg" src="http://www.artstudium.org/kousaku/images/denki_sw1.jpg" width="500" height="425" />
]]></description>
         <link>http://www.artstudium.org/kousaku/2007/08/post_10.html</link>
         <guid>http://www.artstudium.org/kousaku/2007/08/post_10.html</guid>
                  <category domain="http://www.sixapart.com/ns/types#category">Arduino</category>
        
        
         <pubDate>Thu, 23 Aug 2007 16:14:23 +0900</pubDate>
      </item>
            <item>
         <title>少し大きめのモータを使う</title>
         <description><![CDATA[<img alt="L6302.jpg" src="http://www.artstudium.org/kousaku/images/L6302.jpg" width="480" height="640" />
<a href="http://www.artstudium.org/kousaku/2007/06/flash_3.html" target="_blank">以前ここ</a>で紹介したモータドライバーは、最大で2Aしか流せなかった、
もう少し大きなモータで動かしてみるために、
最大5A流せるL6203というモータドライバーを使ってみた。
<img alt="L6302_1.jpg" src="http://www.artstudium.org/kousaku/images/L6302_1.jpg" width="275" height="251" />

<strong>使う部品</strong>
モータードライバー<a href="http://www.rakuten.co.jp/tsukumo/435981/446653/" target="_blank">L6203</a><a href="http://www.st.com/stonline/products/literature/ds/1373.pdf" target="_blank">（カタログ）</a>
コンデンサー
<a href="http://www.sengoku.co.jp/modules/sgk_cart/search.php?toku=%CA%FC%C7%AE&cond8=or&dai=P%B7%BF&chu=&syo=&k3=0&pflg=n&list=2" target="_blank">放熱器</a>
モーター

<strong>モータドライバーの仕様と回路</strong>
11. ENABLE：速度調整用（今回は9に接続）
10. SENSE：動力電源用GND
 9. VREF：0.22μFのコンデンサーとつなぐ
 8. BOOT2：動力電圧安定のため0.15μFとつなぐ
 7. IN2：モータ回転方向,停止制御（今回は5に接続）
 6. GND：GND
 5. IN1：モータ回転方向,停止制御（今回は6に接続）
 4. BOOT1：動力電圧安定のため0.15μFとつなぐ
 3. OUT1：モーターに接続
 2. Vs：12V
 1. OUT2：モーターに接続
<img alt="moterL6203.gif" src="http://www.artstudium.org/kousaku/images/moterL6203.gif" width="366" height="475" />

モータードライバーのピンが、千鳥足になっているため、
ブレッドボードにつけれないので、簡単な半田付けをした。
動作は、<a href="http://www.artstudium.org/kousaku/2007/06/flash_3.html" target="_blank">ここ</a>のプログラムで確認した。

今回使ったモータは、<a href="http://www.maxonjapan.co.jp/" target="_blank">マクソン社</a>のギアヘッドと<a href="http://www.artstudium.org/kousaku/2007/06/post_7.html" target="_blank">ロータリーエンコーダ</a>付コアレスモータ。モーターにギアボックスとセンサーが一体化しているので、精度が高いものを作るときに向いている。

マクソンのモータは、ギアヘッドとエンコーダーの組み合わせを、スイスの工場で行うため、取り寄せに1ヶ月半かかった。
簡単に手に入るギアヘッド付きのモーターは、<a href="http://www.tamiya.com/japan/robocon/robo_parts/g_motor/g_motor.htm" target="_blank">タミヤ</a>のものがある。
また、<a href="http://www.sengoku.co.jp/modules/wraps/index.php/index.htm" target="_blank">千石電商</a>では、多くの種類をあつかっている。]]></description>
         <link>http://www.artstudium.org/kousaku/2007/07/post_9.html</link>
         <guid>http://www.artstudium.org/kousaku/2007/07/post_9.html</guid>
                  <category domain="http://www.sixapart.com/ns/types#category">Arduino</category>
                  <category domain="http://www.sixapart.com/ns/types#category">Flash</category>
        
        
         <pubDate>Sun, 15 Jul 2007 19:20:50 +0900</pubDate>
      </item>
            <item>
         <title>Flashから2つのモータを動かす</title>
         <description><![CDATA[<img alt="moter2.jpg" src="http://www.artstudium.org/kousaku/images/moter2.jpg" width="500" height="375" />

<a href="http://www.artstudium.org/kousaku/archive/flash_arduino_moter2.zip">ソースをダウンロード</a>

以前、<a href="http://www.artstudium.org/kousaku/2007/06/flash_3.html" target="_blank">ここ</a>で紹介した方法では、1つのモーターしか動かせなかった。

今回は、2つのモータの速度を変更するために、
Arduinoの<a href="http://www.arduino.cc/en/Reference/AnalogWrite" target="_blank">analogWrite()</a>関数を使って変更することにした。
analogWrite()は、基盤にPWMと書いてあるポートが使える。
<img alt="moter2_ar.jpg" src="http://www.artstudium.org/kousaku/images/moter2_ar.jpg" width="485" height="360" />
PWMとか書かれていないピンを使いたいときは、<a href="http://www.artstudium.org/kousaku/2007/06/flash_3.html" target="_blank">前回</a>と同じ方法で、
HIGHとLOWをコントロールする必要がある。
今回は、ポートの9と10を使うことにした。
前回と違うところは、analogWrite()は0～255までしか扱えないので、
送信するデータを3桁に変更。

データの形式は、
s(ヘッダー) + 1つ目のデータ + 2つめのデータ
とした。
<strong>
arduinoのソース</strong>

<pre>
int motor1Pin1 = 4;             // モータ1入力ピン
int motor1Pin2 = 5;             // モータ1入力ピン
int motor2Pin1 = 6;             // モータ2入力ピン
int motor2Pin2 = 7;             // モータ2入力ピン

int speedPin1 = 9;              // モータ1速度調整ピン
int speedPin2 = 10;             // モータ2速度調整ピン

int keta, sum, count;           // データ受信用
int speed1 = 0;                 // モータ1の速度
int speed2 = 0;                 // モータ2の速度
char cwFlg1 = 'c';              // モータ1の回転方向
char cwFlg2 = 'c';              // モータ3の回転方向

const int KETAMAX = 3;          // 受信桁数 

void setup() {
  pinMode(motor1Pin1, OUTPUT);
  pinMode(motor1Pin2, OUTPUT);
  pinMode(motor2Pin1, OUTPUT);
  pinMode(motor2Pin2, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  //------------------------- データ受信
  if(Serial.available()>0){      // データが来た
    int val = Serial.read();
    if(val == 's'){              // ヘッダー受信
      count = 0;                 // データカウンター初期化
    }else if(val == 'c' || val == 'n'){ // データのはじめ
      if(count == 0){cwFlg1 = val;}     // 回転方向
      else {cwFlg2 = val;}  
      count++;
      keta = KETAMAX;            // 桁数初期化
      sum = 0;
    }else{                       // 数値データ
      val -= 48;                 // アスキー→数値に変換
      for(int i=1; i < keta; i++){// 桁数を計算
        val *= 10;
      }
      sum += val;
      keta --;
      if(keta == 0){            // すべてのデータ受信終了
        if(count==1){           // モータ1の速度
          speed1 = constrain(sum, 0, 255);  // オーバーフローする値を切り捨て
        }else{                  // モータ2の速度
          speed2 = constrain(sum, 0, 255);  // オーバーフローする値を切り捨て
        }
      }
    }
  }
  
  //------------------------- モータ動作
  // 停止、回転方向をチェック
  // モータ1
  if(speed1 == 0){              // モータ停止
    digitalWrite(motor1Pin1, LOW);
    digitalWrite(motor1Pin2, LOW);
  }else if(cwFlg1 == 'c'){      // 時計回転
    digitalWrite(motor1Pin1, HIGH);
    digitalWrite(motor1Pin2, LOW);
  }else{                      // 反時計回転
    digitalWrite(motor1Pin1, LOW);
    digitalWrite(motor1Pin2, HIGH);
  }
  // モータ2
  if(speed2 == 0){             // モータ停止
    digitalWrite(motor2Pin1, LOW);
    digitalWrite(motor2Pin2, LOW);
  }else if(cwFlg2 == 'c'){     // 時計回転
    digitalWrite(motor2Pin1, HIGH);
    digitalWrite(motor2Pin2, LOW);
  }else{                      // 反時計回転
    digitalWrite(motor2Pin1, LOW);
    digitalWrite(motor2Pin2, HIGH);
  }
  
  // モータの速度調整
  analogWrite(speedPin1, speed1);
  analogWrite(speedPin2, speed2);
}
</pre>
]]></description>
         <link>http://www.artstudium.org/kousaku/2007/07/flash2.html</link>
         <guid>http://www.artstudium.org/kousaku/2007/07/flash2.html</guid>
                  <category domain="http://www.sixapart.com/ns/types#category">Arduino</category>
                  <category domain="http://www.sixapart.com/ns/types#category">Flash</category>
        
        
         <pubDate>Sun, 15 Jul 2007 17:22:32 +0900</pubDate>
      </item>
            <item>
         <title>Flashとセンサーをつなぐ（mac）</title>
         <description><![CDATA[<a href="http://www.artstudium.org/kousaku/2007/06/flashwindows_1.html" target="_blank">ここと同じ</a>もので、mac上でも動かしてみた。

<a href="http://www.artstudium.org/kousaku/archive/mac_sensor.zip">ファイルをダウンロード zip</a>

<strong>設定方法</strong>
1.ダウンロードしたフォルダのserproxy-mac/serproxy.cfgファイルに、
シリアルUSBポートのの設定を書き込む。
例：serial_device1=/dev/cu.usbserial-A4001d32
設定の調べ方は、パソコンにarduinoを接続させて、Processingの<a href="http://processing.org/reference/libraries/serial/Serial_list_.html" target="_blank">list()</a>コマンドでポートの一覧を表示させる。リストの中から/dev/cu.usbserial-から始まるものを選び、/dev/cu.usbserial-A4001d32の部分を自分の環境に置き換える

2.serproxy-macフォルダのserproxyを起動する
（serproxyは、シリアル通信とxmlSocketをつなぐ変換するアプリケーション）

3.flashで、comポートは、5331にしてパブリッシュする

うまく、つながれば、グラフが描けるとおもいます。
<img alt="sens_mac.jpg" src="http://www.artstudium.org/kousaku/images/sens_mac.jpg" width="500" height="387" />

Arduinoのwindows用サンプルは、serproxyを起動すれば、
windowsと同じように動きます。]]></description>
         <link>http://www.artstudium.org/kousaku/2007/06/flashmac.html</link>
         <guid>http://www.artstudium.org/kousaku/2007/06/flashmac.html</guid>
                  <category domain="http://www.sixapart.com/ns/types#category">Arduino</category>
                  <category domain="http://www.sixapart.com/ns/types#category">Flash</category>
        
        
         <pubDate>Fri, 29 Jun 2007 17:26:59 +0900</pubDate>
      </item>
            <item>
         <title>GPSをつないでみる</title>
         <description><![CDATA[小型ＧＰＳモジュールを使ってみる。

<img alt="gps.jpg" src="http://www.artstudium.org/kousaku/images/gps.jpg" width="550" height="413" />

<a href="http://strawberry-linux.com/" target="_blank">高感度小型ＧＰＳモジュール（３．３Ｖ～５Ｖ）</a> 
<img alt="gps1.jpg" src="http://www.artstudium.org/kousaku/images/gps1.jpg" width="400" height="325" />
３０ｍｍのサイズの中にアンテナや、LSIが収まっている。
3.3Vでデータを送ってくるので、
<a href="http://strawberry-linux.com/" target="_blank">ＵＳＢ→シリアル変換モジュールキット「ＦＴ２３２ＲＸ」</a>
<img alt="gps2.jpg" src="http://www.artstudium.org/kousaku/images/gps2.jpg" width="400" height="283" />
も購入して、3.3Vで、USB接続できる環境も作った

ＧＰＳのデータは、1秒間隔で、
<a href="http://bg66.soc.i.kyoto-u.ac.jp/forestgps/nmea.html" target="_blank">NMEA-0183フォーマット</a>
で送られてくる。

このモジュールは、室内では、衛星の電波が受信できないらしく、
野外に出て、受信できた。
受信したデータは、以下のようなものだった。

<pre>
$GPGSA,A,3,11,19,25,27,,,,,,,,,08.6,04.1,07.5*01
$GPGSV,2,1,07,11,57,230,40,16,08,130,00,19,60,029,45,25,35,236,39*7F
$GPGSV,2,2,07,27,37,266,38,01,,,29,08,,,37,,,,*40
$GPRMC,150947,A,3541.1627,N,13943.7758,E,002.7,235.5,170607,,,A*7D
$GPGGA,150948,3541.1627,N,13943.7758,E,1,04,04.1,00072.5,M,039.1,M,,*49
</pre>]]></description>
         <link>http://www.artstudium.org/kousaku/2007/06/gps.html</link>
         <guid>http://www.artstudium.org/kousaku/2007/06/gps.html</guid>
                  <category domain="http://www.sixapart.com/ns/types#category">工作</category>
        
        
         <pubDate>Wed, 20 Jun 2007 01:09:50 +0900</pubDate>
      </item>
            <item>
         <title>Flashで、温度センサーを使う</title>
         <description><![CDATA[今回は、LM35温度センサICをつかう。
<img alt="ondo.jpg" src="http://www.artstudium.org/kousaku/images/ondo.jpg" width="550" height="413" />

<img alt="ondo_1.jpg" src="http://www.artstudium.org/kousaku/images/ondo_1.jpg" width="400" height="321" />

LM35の特徴は、
温度係数はリニアで＋ 10.0mV/ ℃
気温、28度のとき、28X0.01=0.28Vになる。
数値が細かいので、オペアンプで値を増幅する必要がある。

通常のオペアンプは、5V電源を使ったとき、出力が最大4Vになるが、
今回のオペアンプは、Rail to Rail機能のあるLMC6032を使って、
最大5Vまで出力させる。
<img alt="ondo_2.jpg" src="http://www.artstudium.org/kousaku/images/ondo_2.jpg" width="400" height="357" />

増幅率は、2つの抵抗の比率で変えることができる。
OUT＝IN×(1＋R1/R2)
<img alt="onndo_z.gif" src="http://www.artstudium.org/kousaku/images/onndo_z.gif" width="249" height="188" />

今回は、気温40度程度まで計れればいいので、
5/(40X0.01) = 12.5倍程度の増幅率でいいことになる。
手元にある部に品で、R1=10kΩ、R2=1kΩを選び、11倍の増幅率になるようにした。

Arduinoのソースは<a href="http://www.artstudium.org/kousaku/2007/06/flashwindows_1.html" target="_blank">ここ</a>と同じ

<strong>Flashのソース</strong>
受信して、少数を表示できるように計算した。

<pre>
import Arduino;

// 環境に合わせて、ポートを設定する。
// COM1:5331、COM2:5332、COM3:5333、COM4:5334、COM5:5335、COM6:5336
var port:Number = 5333;

var arduino:Arduino = new Arduino(port);

listenObj = new Object();

// データを受信
listenObj.onReceiveData = function(evtObj:Object){
	var msg = evtObj.data;
	var temperature = Math.floor(Number(msg)*5/(1024*11*0.01)*10);	// 少数計算のため10をかけている
	temperature /= 10;								// 後から、10を割って小数一桁を計算する
	box.text = temperature ;		// テキストボックスに表示
}

// リスナー登録
arduino.addEventListener("onReceiveData", listenObj);
</pre>
]]></description>
         <link>http://www.artstudium.org/kousaku/2007/06/flash_2.html</link>
         <guid>http://www.artstudium.org/kousaku/2007/06/flash_2.html</guid>
                  <category domain="http://www.sixapart.com/ns/types#category">Arduino</category>
                  <category domain="http://www.sixapart.com/ns/types#category">Flash</category>
        
        
         <pubDate>Wed, 20 Jun 2007 00:26:44 +0900</pubDate>
      </item>
            <item>
         <title>WiPort─ネットワークで、基盤にアクセスする（windows）</title>
         <description><![CDATA[無線LANで、パソコンから基盤にアクセスできるWiPortを使ってみる。
<img alt="wiport_1.jpg" src="http://www.artstudium.org/kousaku/images/wiport_1.jpg" width="550" height="380" />
WiPortは、小型で無線LANに接続できる小型ディバイス
<img alt="wiport_2.jpg" src="http://www.artstudium.org/kousaku/images/wiport_2.jpg" width="350" height="287" />
無線LAN越しに基盤と、パソコンをシリアル接続で通信できます。
<img alt="wiport.jpg" src="http://www.artstudium.org/kousaku/images/wiport.jpg" width="550" height="158" />

<strong>用意するもの</strong>
<a href="http://www.wakamatsu-net.com/biz/" target="_blank">WiPort</a>
<a href="http://www.wakamatsu-net.com/biz/" target="_blank">基盤コネクタ</a>
3.3Vレギュレータ
ADM3202AN（RSS232C<->TTL変換）

<strong>
設定方法</strong>
1.<a href="http://www.wakamatsu-net.com/biz/" target="_blank">若松通商で売っている基盤</a>に、コネクタを半田付け後、WiPortと接続させる。

2.WiPortの設定を、シリアル接続で変更する。
<img alt="wiport_3.jpg" src="http://www.artstudium.org/kousaku/images/wiport_3.jpg" width="550" height="395" />
2-1.WiPortのシリアルを、ADM3202ANで変換して、パソコンのシリアルと接続する。
WiPortのシリアルは2つあるが、つなぐのは16（TXD0）と17（RXD0）。
2-2.3.3Vの電源に2（Power）、11,12,23,24（GND）を接続。
2-3.シリアルの設定は、9600bps , 8ビット , パリなし , ストップビット1 , フロー制御なし
2-4.WiPortの電源を入れて、1秒以内にxxxを入力する。
2-5.うまくいくと、下の画面が表示される。
<img alt="wiport_s1.jpg" src="http://www.artstudium.org/kousaku/images/wiport_s1.jpg" width="264" height="65" />
2-6.その後、4秒以内にEnterを押すと設定が表示される。
<img alt="wiport_s2.jpg" src="http://www.artstudium.org/kousaku/images/wiport_s2.jpg" width="404" height="195" />
2-7.IPアドレスや無線LAN環境の設定をします。（1と4を設定しました）
<a href="http://www.co-nss.co.jp/download/manual/SetupMenu.pdf" target="_blank">詳細はここを参照</a>

3.設定がうまくできると、ブラウザーからWiPortにアクセスができるようになります。
<img alt="wiport_s3.jpg" src="http://www.artstudium.org/kousaku/images/wiport_s3.jpg" width="450" height="272" />

4.パソコンでシリアル接続できるように、<a href="http://www.lantronix.com/device-networking/utilities-tools/" target="_blank">Com Port Redirector</a>をインストールする。

5.Com Port Redirectorで、WiPortのアドレスと、
パソコンのシリアルポートを関連付けする。
<a href="http://www.co-nss.co.jp/download/manual/ComPort_SetUp.pdf" target="_blank">詳細はこれを参照。</a>

6.WiPortからADM3202ANをはずし、Arduinoと、接続する。
Arduino TX -> WiPort RXD0
Arduino RX -> WiPort TXD0

7.WiPortの電源を入れて、パソコンでシリアル通信をすれば、ネットワーク経由でアクセスできることが確認できる。]]></description>
         <link>http://www.artstudium.org/kousaku/2007/06/wiport.html</link>
         <guid>http://www.artstudium.org/kousaku/2007/06/wiport.html</guid>
                  <category domain="http://www.sixapart.com/ns/types#category">Arduino</category>
        
        
         <pubDate>Sun, 17 Jun 2007 22:17:03 +0900</pubDate>
      </item>
            <item>
         <title>Bluetoothで、Flashに接続するスイッチを作る</title>
         <description><![CDATA[今までは、USBケーブルでパソコンに接続していたが、
ワイヤレス通信ができるBluetoothで、パソコン上のFlashに接続させる。
<img alt="blue.jpg" src="http://www.artstudium.org/kousaku/images/blue.jpg" width="550" height="449" />
今回は、トグルスイッチの変わりに<a href="http://www.sengoku.co.jp/modules/sgk_cart/search.php?toku=&cond8=and&dai=&chu=&syo=&cond9=&k3=2&list=2&pflg=n&multi=&code=5A6R-CNDM" target="_blank">フットスイッチ</a>で、
ワイヤレスにFlashをコントロールできるものを作った。

<strong>使用するパーツ</strong>
<a href="http://www.sparkfun.com/commerce/product_info.php?products_id=582" target="_blank">Bluetooth</a>

電池で起動するときは、ジャンパーピンをEXTに切り替える。
<img alt="bluej.jpg" src="http://www.artstudium.org/kousaku/images/bluej.jpg" width="350" height="388" />

<img alt="blue_k.jpg" src="http://www.artstudium.org/kousaku/images/blue_k.jpg" width="300" height="219" />

Bluetoothの接続方法は、
Arduino基盤のRX→BluetoothのTX-O
Arduino基盤のTX→BluetoothのRX-I
に接続する。
それから、PWRとGNDを接続する。
<img alt="blue2.jpg" src="http://www.artstudium.org/kousaku/images/blue2.jpg" width="550" height="413" />

電気が通ると、Bluetoothの緑色のLEDが点滅する。
<img alt="blue3.jpg" src="http://www.artstudium.org/kousaku/images/blue3.jpg" width="300" height="210" />

パソコンとの接続後は、赤く点灯する。
<img alt="bluer.jpg" src="http://www.artstudium.org/kousaku/images/bluer.jpg" width="300" height="200" />

Flashとの接続は、<a href="http://www.artstudium.org/kousaku/2007/06/flashwindows.html" target="_blank">Flashで電子工作</a>と同じです。]]></description>
         <link>http://www.artstudium.org/kousaku/2007/06/bluetooth.html</link>
         <guid>http://www.artstudium.org/kousaku/2007/06/bluetooth.html</guid>
                  <category domain="http://www.sixapart.com/ns/types#category">Arduino</category>
                  <category domain="http://www.sixapart.com/ns/types#category">Flash</category>
        
        
         <pubDate>Thu, 14 Jun 2007 00:32:34 +0900</pubDate>
      </item>
            <item>
         <title>フォトインタラプタを使う2</title>
         <description><![CDATA[<img alt="7414.jpg" src="http://www.artstudium.org/kousaku/images/7414.jpg" width="550" height="413" />
<a href="http://www.artstudium.org/kousaku/2007/06/post_8.html" target="_blank">前回</a>フォトインタラプタを使いましたが、緩やかに、HIGHとLOWが変化して、
高速で変化するときに、対応ができませんでした。

今回は、論理回路、74HC14を使って、HIGHとLOWをはっきり出力させます。
<img alt="7414_z3.jpg" src="http://www.artstudium.org/kousaku/images/7414_z3.jpg" width="209" height="181" />
74HC14には2つの機能があります。
1.<strong>論理反転</strong>・・・HIGHをLOW、LOWをHIGHに変換する。
2.<strong>ヒステシス</strong>・・・入力時の立ち上がりと、立下りで、HIGHとLOWの切り替え値を変え、ノイズの影響を受けにくくする。
<img alt="7414_z2.jpg" src="http://www.artstudium.org/kousaku/images/7414_z2.jpg" width="331" height="299" />
<a href="http://www.semicon.toshiba.co.jp/docs/datasheet/ja/LogicIC/TC74HC14AF_TC74HC14AP_ja_datasheet_060201.pdf" target="_blank">データシート</a>から、しきい値は
HIGHのとき2.7V
LOWのとき1.6V
となっている。

74HC14は、使わない入力はGNDに接続しておく。
]]></description>
         <link>http://www.artstudium.org/kousaku/2007/06/2_1.html</link>
         <guid>http://www.artstudium.org/kousaku/2007/06/2_1.html</guid>
                  <category domain="http://www.sixapart.com/ns/types#category">Arduino</category>
        
        
         <pubDate>Wed, 13 Jun 2007 16:46:48 +0900</pubDate>
      </item>
            <item>
         <title>フォトインタラプタを使う</title>
         <description><![CDATA[<img alt="photointer.jpg" src="http://www.artstudium.org/kousaku/images/photointer.jpg" width="550" height="413" />
<a href="http://akizukidenshi.com/catalog/items2.php?q=%A3%D2%A3%D0%A3%C9%A1%DD%A3%B3%A3%B5%A3%B2&s=score&p=1&r=1&page=#P-01471" target="_blank">フォトインタラプタ ＲＰＩ−３５２</a>

発光部の最大電流が、50mA。
発光部のダイオードにつなぐ、抵抗を計算すると、
5V/0.05=100Ω
となる。
100Ω以上なら問題ないので、330Ωをつないだ
<img alt="photointer_z.gif" src="http://www.artstudium.org/kousaku/images/photointer_z.gif" width="204" height="158" />

<a href="http://www.artstudium.org/kousaku/2007/06/post_3.html" target="_blank">ソース</a>は、スイッチと同じ。

]]></description>
         <link>http://www.artstudium.org/kousaku/2007/06/post_8.html</link>
         <guid>http://www.artstudium.org/kousaku/2007/06/post_8.html</guid>
                  <category domain="http://www.sixapart.com/ns/types#category">Arduino</category>
        
        
         <pubDate>Tue, 12 Jun 2007 16:41:02 +0900</pubDate>
      </item>
            <item>
         <title>Flashからモータを動かす</title>
         <description><![CDATA[モータを基盤とは別の外部電源を使って、動かしてみる。
<img alt="moter.jpg" src="http://www.artstudium.org/kousaku/images/moter.jpg" width="500" height="766" />

<a href="http://www.artstudium.org/kousaku/archive/flash_arduino_moter.zip">ソースをダウンロード</a>

<strong>使う部品</strong>
モータドライバ <a href="http://www.rakuten.co.jp/tsukumo/435981/446653/" target="_blank">TA7291P</a> <a href="http://www.semicon.toshiba.co.jp/docs/datasheet/ja/LinearIC/TA7291F_TA7291SG_ja_datasheet_060123.pdf" target="_blank">（カタログ）</a>
マブチモータ　<a href="http://www.mabuchi-motor.co.jp/cgi-bin/catalog/catalog.cgi?CAT_ID=fa_130ra" target="_blank">FA-130RA </a>

<img alt="moter_d.jpg" src="http://www.artstudium.org/kousaku/images/moter_d.jpg" width="550" height="435" />
モータドライバは、外部電源を使えるだけでなく、
モータの回転方向と速度を調整してくれる。

ピンは、左から以下の機能がある。

1.  GND
2.  モーターに接続
3.  接続しない
4.  速度調整のためのPWM（今回は9に接続）
5.  モータ回転方向,停止制御 （今回は5に接続）
6.  モータ回転方向,停止制御（今回は6に接続）
7.  5V
8.  モーター電源（今回は、ACアダプターの5Vに接続）
9.  接続しない
10. モーターに接続

<strong>arduinoのソース</strong>（<a href="http://www.artstudium.org/kousaku/2007/06/flash_1.html" target="_blank">サーボ</a>を流用）

<pre>
int motorPin1 = 5;            // モータ入力ピン
int motorPin2 = 6;            // モータ入力ピン
int speedPin = 9;             // 速度調整ピン

int keta, sum;                // データ受信用
int pulse = 0;               // PWMのHIGHの値
char cwFlg = 'c';             // モータ回転方向

const int KETAMAX = 4;        // 受信桁数
 
void setup() {
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(speedPin, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  if(Serial.available()>0){       // データが来た
    int val = Serial.read();
    if(val == 'c' || val == 'n'){ // データのはじめ
      cwFlg = val;                // 回転方向
      iniKeta();
    }else{                  // 数値データ
      val -= 48;            // アスキー→数値に変換
      for(int i=1; i < keta; i++){  // 桁数を計算
        val *= 10;
      }
      sum += val;
      keta --;
      if(keta == 0){        // すべてのデータ受信終了
        pulse = constrain(sum, 0, 10000);  // オーバーフローする値を切り捨て
      }
    }
  }
  
  if(pulse == 0){           // モーター停止
    digitalWrite(motorPin1, LOW);
    digitalWrite(motorPin2, LOW);
  }else if(cwFlg == 'c'){   // 時計回転
    digitalWrite(motorPin1, HIGH);
    digitalWrite(motorPin2, LOW);
  }else{                    // 反時計回転
    digitalWrite(motorPin1, LOW);
    digitalWrite(motorPin2, HIGH);
  }
  
  // PWMで出力調整
  digitalWrite(speedPin, HIGH);
  delayMicroseconds(pulse);
  digitalWrite(speedPin, LOW);
  delay(10);
}

// 最初の桁に戻る
void iniKeta(){
  keta = KETAMAX;
  sum = 0;
}
</pre>

サーボと違うところは、データの最初で、モータの回転方向を決めている。
<pre>
if(val == 'c' || val == 'n'){ // データのはじめ
  cwFlg = val;                // 回転方向
</pre>

モータードライバーの8番ピンは、5V以上必要なので、乾電池で動かすときは、注意する必要がある。]]></description>
         <link>http://www.artstudium.org/kousaku/2007/06/flash_3.html</link>
         <guid>http://www.artstudium.org/kousaku/2007/06/flash_3.html</guid>
                  <category domain="http://www.sixapart.com/ns/types#category">Arduino</category>
                  <category domain="http://www.sixapart.com/ns/types#category">Flash</category>
        
        
         <pubDate>Mon, 11 Jun 2007 20:44:43 +0900</pubDate>
      </item>
      
   </channel>
</rss>
