Home » Playaround 第一天課程

Playaround 第一天課程

第一天

瞧! 這就是 Microcontroller
Hi, Micro, 你真行!
有用資料, 好讀
Physical Computing?!
與Arduino玩耍
數位玩家: 首次與Arduino玩耍, 傻瓜LED
來點激動的:立即試: 啓動家電!


瞧! 這就是 Microcontroller

Wikipedia:
"A microcontroller (also MCU or µC) is a computer-on-a-chip, containing a processor, memory, and input/output functions. It is a microprocessor emphasizing high integration, in contrast to a general-purpose microprocessor (the kind used in a PC). In addition to the usual arithmetic and logic elements of a general purpose microprocessor, the microcontroller integrates additional elements such as read-write memory for data storage, read-only memory for program storage, EEPROM for permanent data storage, peripheral devices, and input/output interfaces. At clock speeds of as little as a few MHz or even lower, microcontrollers often operate at very low speed compared to modern day microprocessors, but this is adequate for typical applications. They consume relatively little power (milliwatts), and will generally have the ability to sleep while waiting for an interesting peripheral event such as a button press to wake them up again to do something. Power consumption while sleeping may be just nanowatts, making them ideal for low power and long lasting battery applications.

Microcontrollers are frequently used in automatically controlled products and devices, such as automobile engine control systems, remote controls, office machines, appliances, power tools, and toys. By reducing the size, cost, and power consumption compared to a design using a separate microprocessor, memory, and input/output devices, microcontrollers make it economical to electronically control many more processes."

還是不知道他在說甚麼鬼話. 簡單點來說, 就是一部超級小型的電腦. 有簡單的輸入輸出功能, 有很小的記憶, 就這樣.

你可以給microcontroller編寫程式, 讓他做一些工作.

我們在這個工作坊裡會用一款名叫Arduino的microcontroller (是開放源碼的microcontroller!) 來做點好玩的. 你大概會利用得讀取感應器的數據, 然後在電腦或microcontroller本身作出相對的反應. 你也可以控制硬件如馬達, LED等等.


 

Hi, Micro, 你真行!

那麼, microcontroller或者Arduino究竟能做個甚麼好玩出來?

瘋狂的演繹



明和電機 ツクバシリーズ



明和電機 「一番素敵な体で行こう!」



明和電機(タラッター)



Tsukuba Series

【予告編】土佐信道(明和電機)監督作品『バカロボ2007』
http://youtube.com/watch?v=h60lLL4t5v0&feature=related

 

 

一些利用Arduino作的有趣作品:

Moving Mario!!!!!!!!!! by theDemos

 

 
Sonic Body

Chatter and Listening
http://www.greenmeat.net/resources/Chatter_and_Listening.mov 

 

Customer designs with their fists
http://www.fluidforms.at/de/CassiusWhat.php

 

Light Installation

 

 
intelligent Funirture

lighting, by todbot  

midi drum , by todbot  

有人做過:

LCD

Ciruit Bending

NDS

Thermin

 

我學生的科目作品:

by Ashley

by Jason

稍後有更多的~


有用資料:
Makezine: http://www.makezine.com
Hackzine: http://www.hackszine.com
Arduino Playground: http://www.arduino.cc/playground/
Arduino 樂園: http://arduino.tw
Tinker.it : http://tinker.it
Ladyada: http://www.ladyada.net/


 

好讀:

Making Things Talk
a

Physical Computing

 

Make Magazine
a

Designing Interactions

 

 

 


Physical Computing?!

節錄雨娃老師的厲害文字:
http://www.microplayground.net/playaroundwiki/index.php/Q%26A:tw

"要上 Physical Computing 課程,是否要懂物理學?
Physical Computing 是和『實體運算互動系統』有關係,跟物理學(Physics)沒有關係好嗎?雖然你不需要懂物理學,但最好要有一點電子學常識。如果不懂電子學也沒關係,老師會教大家。"

"為什麼一定要用 Arduino 不可?
假如你要想要做卡布其諾咖啡,你通常會需要咖啡和牛奶,但你不可能種一棵咖啡樹或養一隻牛,然後再等到咖啡豆烘焙好或擠出牛奶。同樣的道理,假如你 想要從事互動設計或科技藝術,Arduino 是目前所知最簡單的方式,它就像是咖啡或牛奶,只要你稍微加點變化,就可以做出一杯好喝的意式咖啡。當然除 Arduino 之外,你還會在工作坊裡學到許多好玩的工具。"

"什麼又是感應器(sensor)?
對於個人電腦主機來說,它的實際意義就像滑鼠和鍵盤。平時我們透過點擊滑鼠讓動畫播放,同樣的我們也可以透過吹一口氣,開或關燈讓動畫播放,而要使 用後面兩種神奇的播放方式就要用到感應器。感應器有很多種,濕度感應器用來感受環境濕度變化,超音波感應器可以感受距離遠近,壓力感應器反應力道變化,還 有紅外線感應器或光敏電阻等,使用不同的感應器可以得到各種好玩的互動方式。"

"有沒有這麼累一定要寫程式?
有人認為寫程式是工程師的事情,只要告訴他們自己要什麼就好了。也有人對寫程式很排斥。對於初階者來說,還有另一種折衷的理解角度,就像 Processing Creative Coding and Computational Art 這本書說的:把程式碼視為一種藝術形式而非純技術工具。也許有些程式碼看起來超出我們的理解範圍,但不用擔心,嘗試運行它看看就可以。大多時候藝術家們都 在嘗試屬於自己的創作方式,這種摸索和嘗試讓藝術家們能得到意想不到的靈感,而寫程式也能讓我們獲得相同的靈感。"


 

與Arduino玩耍

現在來輕輕的介紹Arduino

-


(image source from http://www.auduino.cc)

(Information from http://www.auduino.cc)

There are different version of Arduino. The one we are using

made with Atmel ATmega8 ( datasheet ).

-

(Information from http://www.auduino.cc)

 

USB boards with the new FTDI232R usb interface

Serial board that has a USB port to communicate with a computer

-

 

(image source from http://www.auduino.cc)

It’s a basic board that uses RS232 as an interface to a computer for programming or communication.

This is a miniature Arduino board with a tiny processor that has twice the memory of the one on normal Arduino boards. Can only be powered with up to 9 volts; don’t give it any more voltage or plug it in backwards – it’ll die.

You can make you own Arduino:
http://itp.nyu.edu/physcomp/Tutorials/ArduinoBreadboard

Prototype Shield
You can do your prototype with prototype board, of course. There are some phototype shield for prototyping, the one we are going to use is the product collobrated betweem SparkFun and ITP: http://www.sparkfun.com/commerce/product_info.php?products_id=7914#

 

-

(image source from http://www.sparkfun.com)

Also, you can make one by yourself with low cost:

 

-

1) http://www.tigoe.net/pcomp/code/archives/arduino/000729.shtml (you can even download the eagle file to develop the shield)

 

-

(image source from http://todbot.com)
2) http://todbot.com/blog/2006/07/11/arduino-breadboard-shield/ (US$10 method!)

 

Different type of Shield
You can also find someone made some cool shield for Arduino:
http://www.arduino.cc/en/Main/ArduinoShields


 

來! 來最愚蠢的測試!
(往往最愚蠢的測試, 可能是最擾人的. 因為出問題時, 簡單得不知道問題差到哪去)

We have Hello World as our first try in programming. In microcontroller, we have no Hello World, instead, we have blinking LED (閃亮 LED).

Put your LED into Pin 13 and GND, Arduino has already 1K resistor in pin 13!

Program the Arduino
Open the Arduino IDE. Connect Arduino to the computer via USB.

As mentioned before, Arduino is a USB Serial Port, its communication port is COM port. If you work it out at home, find the com port out in the device manager.

-

 

 

Now select the serial port we are going to use

-

 

This is the driver we have setup in the computer in the lab before. The drive is FTDI.

Now, write you program in Arduino IDE and upload it to the board. The following is the program

int ledPin = 13;             
void setup(){
   pinMode(ledPin, OUTPUT);
}
void loop(){
   digitalWrite(ledPin, HIGH);
   delay(1000);
   digitalWrite(ledPin, LOW);
   delay(1000);
}

Upload it to Arduino

-

 
-

 

閃亮 LED!


 

數位玩家: 首次與Arduino玩耍, 傻瓜LED

先來了解數位是甚麼:

  • Only 1 or 0, HIGH or LOW: Digital
 

簡單來說, 以你們剛剛看到的LED來做說明: LED只有亮和不亮, 沒有半亮. (當然稍後你能把它變半亮)

然後, 剛剛的測試….對! 你跟本不知道自己在做甚麼

來看看那堆怪獸碼在幹甚麼

int ledPin = 13;             
void setup(){
   pinMode(ledPin, OUTPUT);
}
void loop(){
   digitalWrite(ledPin, HIGH);
   delay(1000);
   digitalWrite(ledPin, LOW);
   delay(1000);
}

來逐一了解:

digitalWrite : You are giving the pin HIGH or LOW, thus, giving power on or off. In Digital write, HIGH is going to give power on and LOW is off.

The Blinking exercise is just simply light up the LED by sending HIGH to the pin, and off by sending LOW to the pin. In between, there is a code delay(1000).

delay(1000) : delay the operation in 1000 millisecond. Just like what we learnt in Lejos: sleep.

You can also find pinMode in the code

pinMode(int, mode) : you need to tell Arduino whether the pin is in INPUT or OUTPUT mode.

 

自己來: 你能否改變他們閃的速度?


 

加入數位輸入

剛剛的就只有輸出, 哪有互動的份兒.
接下來我們就加入最簡單的輸入: 開關 (switch)

正如之前解釋何謂數位: 只有全開和不開.
我們平常的開關按鈕, 大部份就是全開和不開.

現在我們就試試如何讀取開關按鈕的狀態.

有兩個加開關按鈕的方法:

Positive Logic

 
  • Digital inputs : between 0 and 5 volts
  • Resistor pull-down input to ground (0 volts)
  • Pressing the switch sets input to 5 volts
  • So : Press is HIGH, Release is LOW

Inverted Logic

 
  • Resistor this time pull-up input to 5 volts
  • Swtich sets input to 0 volts
  • But now the whole thing is inverted: Press is LOW, Release is HIGH

兩個接駁方法很不同啊.

其實開關按鈕最後只是決定讓不讓電流通過.

正常來說, 按下去就是讓電流通過, 即我們平常的開燈. 放手就是不讓電流通過, 即是關燈.

上面Positive Logic, 看其名就知道是"正常". 所以若跟據這個圖:

 

有電流時應該是HIGH, 即1. 所以如果我們讀取開關按鈕時得到 1 (在positive logic上), 即是說開關按鈕被按下. 如果讀得是 0, 即開關按鈕沒有被按下.

 

但是, 程式怎樣編:

int switchPin = 2; //設定digital pin的號碼
int LedPin1 = 3;   //設定digital pin的號碼
int LedPin2 = 4;    //設定digital pin的號碼
int switchState = 0;   //用來記下開關按鈕狀態
void setup() {
   pinMode(switchPin, INPUT);//設定digital pin形式(輸入/輸出)
   pinMode(LedPin1, OUTPUT); //設定digital pin形式(輸入/輸出)
   pinMode(LedPin2, OUTPUT);//設定digital pin形式(輸入/輸出)
}
void loop() {
   switchState = digitalRead(switchPin);//讀取開關按鈕狀態
   if (switchState == 1) { //如果是被按下
     digitalWrite(LedPin1, HIGH); //LedPin1 亮
     digitalWrite(LedPin2, LOW); //LedPin2 不亮
   }
   else { //如果不是被按下
     digitalWrite(LedPin1, LOW); //LedPin1 不亮
     digitalWrite(LedPin2, HIGH); //LedPin2 亮
   }
}

 

好問題一條:

為什麼連LED到13 pin時不用電阻, 其他的要?

基本上如果我們透過digitalWrite給電時, 電會超過3V. 但一顆超普通的LED絕對不能承受3V的電流量. 於是我們就要加上電阻, 讓電流減低. 除了PIN 13本身內置220ohm電阻外, 其他pin是沒有的.

 


 

小玩意: tilt switch

這個tilt switch的原理跟開關按鈕是一樣的, 只是它不是按.
開關的方法是搖動!

給你一點時間, 用同樣的程式, 但換上不同的按鈕, 試試效果變成怎樣


 

 

來點激動的:
立即試: 啓動家電!

太悶了吧! 就是知道學習phsyical computing的開頭有夠悶.
我們來個好玩的.

但, 怎樣去透過Arduino控制或只不過是啓動家電?

當然, 我不會在你們的第一天就來得這麼激動.
由於時間的關係, 我已經幫你們準備好簡單好玩的~

Relay box: 繼電箱
這只是我給他起的名字, 其實是利用繼電器組成的小玩意.
關於繼電器, 我們稍後再談.
簡單來說, 這個繼電箱就是讓你可以透過Arduino控制我們平常家庭電器的電源開關.

好的, 先來給你們看看video

 

帥!

這次輪你們! 原理是超簡單:

還記得之前我們我們玩LED時, 我們想亮LED的時候就是作這個

digitalWrite(ledPin1, HIGH)

然後連到 ledPin1的led就會亮起來. 這個我自家製的繼電箱有兩根線, 原理正正跟要亮起 led 一樣: 如果你給他HIGH, 繼電箱就讓電流流通, 否則就不流.

究竟, 你可以用這個繼電器做甚麼? 來用你的創意吧!

(如果只利用今天學過的, 可否變成一台要不停按鈕才能充電的充電台?!!!!)


 

 

2 Comments »

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.