Download - Arduino Workshop 2011.05.31
2011年5月31日17:00~18:30/スタジオ1ミーティングルーム
小林 茂(情報科学芸術大学院大学[IAMAS]スタジオ1・非常勤講師)
IAMASユビキタスインタラクション研究領域フィジカルコンピューティングワークショップ
配布物一覧
• Arduinoボード(Arduino Duemilanove):1個• USBケーブル:1本• ブレッドボード:1個• ジャンパワイヤ:適量• LED:2個• タクトスイッチ:1個• 抵抗器(330Ω:橙橙茶金):1個• 抵抗器(10kΩ:茶黒橙金):1個• 可変抵抗器:1個
Arduinoとは?
• フィジカルコンピューティングのためのツールキット• 電子回路をプロトタイピングするためのオープンソースのプラットフォームで、柔軟で簡単に使えるハードウェアとソフトウェアで構成
• アーティスト、デザイナ、ホビイスト、そしてインタラクティブなオブジェクトや環境をつくることに興味がある全ての人が対象
Arduinoを構成する3つの要素
• Arduinoボード• ATMega328P(16MHz)を搭載• USB• オープンソース(さまざまなバリエーションと互換機)• Arduino IDE• Windows、Mac OS X、Linux上で動作• オープンソース• デバッガはない• Arduino言語• C/C++をベースにしたプログラミング言語
Arduinoの流儀
デザインについて語ることよりも作ることのほうがArduino の哲学に適っています。良いプロトタイプを作るために、より速く、よりパワフルな手法を探索し続けることが重要です。自分の手を使って考えながら、いろいろなテクニックを試し、発展させましょう。
Massimo Banzi(「Arduinoをはじめよう」著者)
Massimo Banzi著「Arduinoをはじめよう」003ページより引用
Arduinoの流儀
• プロトタイピング• いじくりまわす• パッチング• サーキットベンディング• キーボードハック• ジャンク大好き!• オモチャをハック• コラボレーション
Massimo Banzi著「Arduinoをはじめよう」004~014ページより引用
Arduino IDE
Verifyスケッチがコンパイルできるか確認する
New新しいスケッチを生成する
Openサンプルや既存のスケッチを開く
Save現在開いているスケッチを保存する
Uploadスケッチを Arduino ボードにアップロードする
Serial Monitorシリアルモニタを開く
Stopシリアルモニタが動作中であれば停止する
ツールバー
タ ブ
テキストエディタ
メッセージエリア
テキストエリア
電子回路の基礎知識
• 基本用語• 電圧:2点間の電位差、単位はV(ボルト)• 電流:流れる電気の量、単位はA(アンペア)• 抵抗:電気の流れにくさ、単位はΩ(オーム)• 最初は水の流れに例えて理解することができる• 電圧→水圧• 電流→水流
オームの法則を用いて抵抗値を計算E(電圧) = I(電流) × R(抵抗)☜オームの法則を式で表したもの
電源電圧 - LEDにかかる電圧 = LEDに流れる電流 × 抵抗↓抵抗を求めるために変形抵抗 = (電源電圧 - LEDにかかる電圧)÷ LEDに流れる電流↓単位を揃えて実際の値を代入抵抗 = (5 - 1.8)÷ 0.01 = 3.2 ÷ 0.01 =320↓最も近い値の抵抗器を選択する330Ω
※LEDに流れる電流を制限する方法は抵抗器だけではない
ArduinoでHello World!void setup() { // initialize the digital pin as an output. // Pin 13 has an LED connected on most Arduino boards: pinMode(13, OUTPUT);}
void loop() { digitalWrite(13, HIGH); // set the LED on delay(1000); // wait for a second digitalWrite(13, LOW); // set the LED off delay(1000); // wait for a second}
点滅の間隔を変えてみようvoid setup() { // initialize the digital pin as an output. // Pin 13 has an LED connected on most Arduino boards: pinMode(13, OUTPUT);}
void loop() { digitalWrite(13, HIGH); // set the LED on delay(1000); // wait for a second digitalWrite(13, LOW); // set the LED off delay(1000); // wait for a second}
アナログ出力(PWM):1.Basics/Fadeint brightness = 0;int fadeAmount = 5;
void setup() { pinMode(9, OUTPUT);}
void loop() { // set the brightness of pin 9: analogWrite(9, brightness);
brightness = brightness + fadeAmount;
if (brightness == 0 || brightness == 255) { fadeAmount = -fadeAmount ; }
delay(30); }
デジタル入力:2.Digital/Buttonconst int buttonPin = 2;const int ledPin = 13;
int buttonState = 0;
void setup() { pinMode(ledPin, OUTPUT); pinMode(buttonPin, INPUT); }
void loop(){ // read the state of the pushbutton value: buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) { digitalWrite(ledPin, HIGH); } else { digitalWrite(ledPin, LOW); }}
アナログ入力:自分でコードを書いてみるconst int sensorPin = A0;const int ledPin = 9;
void setup() { pinMode(ledPin, OUTPUT); }
void loop() { // read the value from the sensor: int sensorValue = analogRead(sensorPin);
// scale from 0-1023 to 0-255 int intensity = map(sensorValue, 0, 1023, 0, 255);
// sets the value analogWrite(ledPin, intensity);}
PC連携:4.Communication/Dimmer1. ウェブブラウザで次のURLにアクセスhttp://processing.org/download/
2. 使用しているプラットフォームに対応したパッケージをダウンロード
3. デスクトップなどに展開して起動
PC連携:4.Communication/Dimmerconst int ledPin = 9;
void setup() { // initialize the serial communication: Serial.begin(9600);
pinMode(ledPin, OUTPUT);}
void loop() { byte brightness;
// check if data has been sent from the computer: if (Serial.available()) { // read the most recent byte (0-255) brightness = Serial.read();
// set the brightness of the LED: analogWrite(ledPin, brightness); }}
PC連携:4.Communication/Dimmerimport processing.serial.*;
Serial port;
void setup() { size(256, 150);
// Print available serial ports println(Serial.list());
port = new Serial(this, "COM1", 9600);}
void draw() { // draw a gradient from black to white ...
// send the current X-position of the mouse port.write(mouseX);}
さらに詳しく知りたい時は?
• Arduino公式ウェブサイトhttp://arduino.cc/
• Prototyping Labのサンプルhttp://prototypinglab.com/
• Googleで検索• 書籍で調べる