mao arduino

69
阿爾杜伊諾 Arduino: Lv. 1 CęąĤó 2014.5.2 Mutienliao.com ¸huCğĝ·Œ3P MAO Sunday, May 4, 14

Upload: mao-wu

Post on 31-Aug-2014

516 views

Category:

Technology


2 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Mao arduino

阿爾杜伊諾Arduino: Lv. 1

�CęąĤó 2014.5.2

Mutienliao.com ¸hu�Cğĝ·Œ3P

MAO

Sunday, May 4, 14

Page 2: Mao arduino

Sunday, May 4, 14

Page 3: Mao arduino

Sunday, May 4, 14

Page 4: Mao arduino

ArduinoIntroduction

Sunday, May 4, 14

Page 5: Mao arduino

What is Arduino?

Sunday, May 4, 14

Page 6: Mao arduino

Arduino Hardware Arduino Software ŭ Open Source

Physical Computing Platform & Groupŭ

Sunday, May 4, 14

Page 7: Mao arduino

• ª�Ķ6Ķ1414ü ű Digital Pins 0-13

• Digital Pins 0-1/Serial In/Out - TX/RX

- Ē�¶â;Serial portĎŗĊ÷-ĶŪ�ħ: â Pin 0,1.

• ŠÉĶ146ü ű Analog Input Pins A0-A5

• ŠÉĶ6 Analog Output * (Digital Pins 3,5,6,9,10,11)

• Reset �ʼn- S1

• ŞeŗÔĶ1

• NĺŁJumper7¢ãUSB#ŗ�DCŗÔĶ1 (Duemilanove�ČC7¢)

• USBN ó�ãŗĊõĶ1;»�ç²ÜŪ�ĉRŲ#þŗ • ŗÔ#�Vin, 5V, 3.3V (Diecimila�ç»n �·)

Sunday, May 4, 14

Page 8: Mao arduino

各式各樣的Arduino........族繁不及備載

Sunday, May 4, 14

Page 9: Mao arduino

Digital Out Digital In Analog In Analog Out Communication

Sunday, May 4, 14

Page 10: Mao arduino

Digital Out

Sunday, May 4, 14

Page 11: Mao arduino

Analog Out

Sunday, May 4, 14

Page 12: Mao arduino

Digital In

Sunday, May 4, 14

Page 13: Mao arduino

Analog In

Sunday, May 4, 14

Page 14: Mao arduino

Communication

Sunday, May 4, 14

Page 15: Mao arduino

Digital In Digital Out

Analog In Analog Out

Communication

Emotion Experience

Sunday, May 4, 14

Page 16: Mao arduino

Getting started w/ Arduino on your Computer

Sunday, May 4, 14

Page 17: Mao arduino

1 | Get an Arduino & USB cable

Sunday, May 4, 14

Page 18: Mao arduino

| Prepare to test Arduino board

- aėArduinoó�

- ōYLED Blinkø"ÂFile > Examples > Basic > Blink

Sunday, May 4, 14

Page 19: Mao arduino

| Set up your board

• ń¤�� âç»n: Tools > Board

[ Mac OS X ]

[ Mac OS X ]

• ń¤Arduino�_çserial port: Tools > Serila Port

Macçݹè¶�/dev/tty.usbserial- ōś*

[ Windows ]

[ Windows ]

Sunday, May 4, 14

Page 20: Mao arduino

| Upload the program

Ătó�

Vertify

Update to board*

* Arduino NG ç âćŪ\Öď»nË·ČCReset?ĉŪ_�Updateʼn>Ū�ř0��Arudino »n�çResetʼnŪ 5_�*��C�çß��Ū�ĕ_¦ōResetʼn�ŪŢ���UpdateʼnŪ�ĉÆî�-ó�ũ

TX/RXçLEDß�Ù¶�ŋŌÛ

ä-Ķýº�Ū÷ù2~3òŪPin13çpinċ¶ŌÛ(\Ö�'�-çó�)

• ōY File > Examples > Basic > Blink

• Ġĕ�ØOŅçÐóŪvó��-;»n�G

• Ē�?....»n�çÙ¶Èŕ�ò��Äũ

Sunday, May 4, 14

Page 21: Mao arduino

# | Troubleshooting

ĒË�-�?Ū;�¶±�ŧXŝBŰ

• ý�±Sń¤Æîç»nĎSerial portŪŇ­ğr�Äũ

• ĢÍ·XŝŪ%ÆĢÍ�zN� ũ

• Serial Port ÆĘ�â�Ūŏ�5�Æ_âÇSerila portçó�

• »n�çŗÔJump·Ë·ğrÆîŪ·Æ~#ŗūDuemilanove/UNO ¶ČC7¢Ŭ

• »nÆ_åà�í�Ū��»n�çResetŪ 59mEŪ×�_¦ōResetŲŪŢ���IJťõçUpdateũ

• ��çŗı �ArudinoĬĴŁŦŪČC$Ĩ®�USBũ

• ��iNĉç±Ū�ç»n�-Ķād ũ

Sunday, May 4, 14

Page 22: Mao arduino

ŗc(Voltage)

ŗÐ (Current)

Sunday, May 4, 14

Page 23: Mao arduino

āıð�^ ŗı^

• �&ŗıNěÖ�&ĸ]ŪĒĚ+ÅŪ=LĚvŗı��®ıFNũ

• ��çLEDāıņ±ãÇ��çŮŗÔŨLEDŨŗÐŒ</�(ÇÖŗő)ũ• þ´gçŗőŪīÿŁLEDçŗÐĪyŪ=���¶ÒyůI�ŪŗőijyŪ=��Īgũ• RÀçłáŪþçŗįgŪLED�¶į�(> ±�Ú�)ũ

s�Çŗı

Digital Outupt Circuit

Sunday, May 4, 14

Page 24: Mao arduino

Digital Outupt Circuit

Sunday, May 4, 14

Page 25: Mao arduino

Digital Outupt Circuit

Sunday, May 4, 14

Page 26: Mao arduino

breadborad

Sunday, May 4, 14

Page 27: Mao arduino

breadborad

Sunday, May 4, 14

Page 28: Mao arduino

Digital Outª�Ķ6

Digital Out

Sunday, May 4, 14

Page 29: Mao arduino

#1 | Blink

Sunday, May 4, 14

Page 30: Mao arduino

�ŧ±ª�Ű

• Only 1 or 0 / High or LOW / ON or OFF

HIGH

LOW

1

0

Sunday, May 4, 14

Page 31: Mao arduino

int ledPin = 13; // LED connected to digital pin 3

void setup(){ pinMode(ledPin, OUTPUT); // sets the digital pin as output}

void loop(){ digitalWrite(ledPin, HIGH); // sets the LED on delay(1000); // waits for a second digitalWrite(ledPin, LOW); // sets the LED off delay(1000); // waits for a second}

pinMode(pin, Mode) digitalWrite(pin, value) delay(ms)

#1çăĆó�Ū_ File > Examples > Basic > Blink

Sunday, May 4, 14

Page 32: Mao arduino

LED ¡�

W&pin ?

(ó��) �ĚâW&pin?pinMode(who, ?)

(ó��) Ķ6digitalWrite(who,?)

Sunday, May 4, 14

Page 33: Mao arduino

輸入才是互動的精華

Sunday, May 4, 14

Page 34: Mao arduino

Digital Inputª�Ķ1

Digital In

Sunday, May 4, 14

Page 35: Mao arduino

#6 | Button

Sunday, May 4, 14

Page 36: Mao arduino

#6 | Button #6çăĆó�Ū_ File > Examples > Digital > Button

Sunday, May 4, 14

Page 37: Mao arduino

const int buttonPin = 2; // the number of the pushbutton pinconst int ledPin = 13; // the number of the LED pin

int buttonState = 0; // variable for reading the pushbutton status

void setup() { // initialize the LED pin as an output: pinMode(ledPin, OUTPUT); // initialize the pushbutton pin as an input: pinMode(buttonPin, INPUT); }

void loop(){ // read the state of the pushbutton value: buttonState = digitalRead(buttonPin);

// check if the pushbutton is pressed. // if it is, the buttonState is HIGH: if (buttonState == HIGH) { // turn LED on: digitalWrite(ledPin, HIGH); } else { // turn LED off: digitalWrite(ledPin, LOW); }}

#6çăĆó�Ū_ File > Examples > Digital > Button

Sunday, May 4, 14

Page 38: Mao arduino

Sunday, May 4, 14

Page 39: Mao arduino

#7 | StateChangDetection #7çăĆó�Ū_ File > Examples > Digital > StateChangDetection

Sunday, May 4, 14

Page 40: Mao arduino

Analog OutŠÉĶ6

Analog Out

Sunday, May 4, 14

Page 41: Mao arduino

Analog Output

PWM (Pulse Width Modulation)

ŗĊĎ�ųá[±�NĉsŖĶ6ŠÉçŗc(.ĉ0~5V)ũ

��'N�)ľ6Š�稼ũĒ�Ľ_2&ŗc�*7¢Ū�'N��;�&�`(Ů

Output Voltage = High_time(%) * Max_Voltage

Arduino çPWM pinL·3,5,6,9,10,11

Sunday, May 4, 14

Page 42: Mao arduino

Arduino çPWM pinL·3,5,6,9,10,11

ŠÉĶ60~5Vx�çª(Ö0~255analogWrite( pin, val )

Sunday, May 4, 14

Page 43: Mao arduino

#4 | Fade s�UTÙ稼#4çăĆó�Ū_ File > Examples > Basic > Fade

Sunday, May 4, 14

Page 44: Mao arduino

int brightness = 0; // how bright the LED isint fadeAmount = 5; // how many points to fade the LED by

void setup() { // declare pin 9 to be an output: pinMode(9, OUTPUT);}

void loop() { // set the brightness of pin 9: analogWrite(9, brightness);

// change the brightness for next time through the loop: brightness = brightness + fadeAmount;

// reverse the direction of the fading at the ends of the fade: if (brightness == 0 || brightness == 255) { fadeAmount = -fadeAmount ; } // wait for 30 milliseconds to see the dimming effect delay(30); }

#4çăĆó�Ū_ File > Examples > Basic > Fade

Sunday, May 4, 14

Page 45: Mao arduino

Servo

Sunday, May 4, 14

Page 46: Mao arduino

伺服馬達跟DC馬達比較不同,DC馬達是供電就不停地轉動,而伺服馬達是透過PWM訊號供給的時間長短來決定,而伺服馬達有分兩種:

(1) 360度不停轉的,會依照PWM時間長短,決定轉動快慢與轉動方向(2) 定角度的,會依照PWM時間長短,在0~180度角間,精準地控制要擺到那個角度

Sunday, May 4, 14

Page 47: Mao arduino

坊間買得到的伺服馬達會有兩種顏色配對的接線:

(紅.黑.白)~ 對應 V+. GND . 訊號pin

(紅.棕.橘)~ 對應 V+. GND . 訊號pin

#ø"ó� File> Example> Servo> Sweep

Sunday, May 4, 14

Page 48: Mao arduino

輸入才是互動的精華

Sunday, May 4, 14

Page 49: Mao arduino

Analog InputŠÉĶ1

Analog In

Sunday, May 4, 14

Page 50: Mao arduino

Potentiometer

Sunday, May 4, 14

Page 51: Mao arduino

Photocell

get value get value

get value

Sunday, May 4, 14

Page 52: Mao arduino

Arduino çŠÉĶ1 âA0~A5

ŠÉĶ10~5Vx�çª(Ö0~1023analogRead( pin )

Sunday, May 4, 14

Page 53: Mao arduino

#10 | analog_control

#10çăĆó�Ū_ http://code.mutienliao.tw/arduino/analog_control.pde

Sunday, May 4, 14

Page 54: Mao arduino

int ledPin = 13; // LED connected to digital pin 13int analogPin = 0; // photocell connected to analog pin 0int val = 0;

void setup(){ pinMode(ledPin, OUTPUT); // sets the digital pin as output}

void loop(){ val = analogRead(analogPin); // read the value from the sensor if(val<80) { digitalWrite(ledPin, HIGH); // sets the LED on } else { digitalWrite(ledPin, LOW); // sets the LED off } delay(50); }

#10çăĆó�Ū_ http://code.mutienliao.tw/arduino/analog_control.pde

Sunday, May 4, 14

Page 55: Mao arduino

int ledPin = 13; // LED connected to digital pin 13int analogPin = 0; // photocell connected to analog pin 0int val = 0;

void setup(){ pinMode(ledPin, OUTPUT); // sets the digital pin as output Serial.begin(9600);}

void loop(){ val = analogRead(analogPin); // read the value from the sensor Serial.println(val); if(val<80) { digitalWrite(ledPin, HIGH); // sets the LED on } else { digitalWrite(ledPin, LOW); // sets the LED off } delay(50); }

%¥#10çăĆó�ŪJ�analogReadŀ!çª(#10çăĆó�Ū_ http://code.mutienliao.tw/arduino/analog_control.pde

Sunday, May 4, 14

Page 56: Mao arduino

�'N�0âArduino Software #çSerial Monitor!0ÓĠArduino»nõ-!çĞ�ũ

546756456575456745674567447

baud rate ğr

�Ě-çĞ�Ķ1

-Ĺ!çĞ�

Sunday, May 4, 14

Page 57: Mao arduino

#11 | AnalogInOutSerial #11çăĆó�Ū_ File > Examples > Analog > AnalogInOutSerial

Sunday, May 4, 14

Page 58: Mao arduino

const int analogInPin = A0; // Analog input pin that the potentiometer is attached toconst int analogOutPin = 9; // Analog output pin that the LED is attached to

int sensorValue = 0; // value read from the potint outputValue = 0; // value output to the PWM (analog out)

void setup() { // initialize serial communications at 9600 bps: Serial.begin(9600); }

void loop() { // read the analog in value: sensorValue = analogRead(analogInPin); // map it to the range of the analog out: outputValue = map(sensorValue, 0, 1023, 0, 255); // change the analog out value: analogWrite(analogOutPin, outputValue);

// print the results to the serial monitor: Serial.print("sensor = " ); Serial.print(sensorValue); Serial.print("\t output = "); Serial.println(outputValue);

// wait 10 milliseconds before the next loop // for the analog-to-digital converter to settle // after the last reading: delay(10); }

#11çăĆó�Ū_ File > Examples > Analog > AnalogInOutSerial

Sunday, May 4, 14

Page 59: Mao arduino

CommunicationÕļ

Communication

Sunday, May 4, 14

Page 60: Mao arduino

Arduino ��±ìçĺŁUSB!İŗĊÕļŪĈ±ĺŁRS-232 Serialç¯�ũ

ĺŁ�ĿHIGH / LOWçĂïĞĖŪN�ķ¢��'ĚçĞ�Ů

�ĥŗĊõâ�ŧIJťŪLĚĉĺŁSerial port-ĹĞ�ŪzN�İArduinoÕļũ§�'N�â C/C++, VB, MAX/MSP, VVVV, Processing �±FLASH(ŘĚö�¯IJťç�A)

Sunday, May 4, 14

Page 61: Mao arduino

#12 | PC to Arduino #12çăĆó�Ū_File > Example > Communication > PhysicalPixel

Sunday, May 4, 14

Page 62: Mao arduino

RGBSunday, May 4, 14

Page 63: Mao arduino

RGB LED

Sunday, May 4, 14

Page 64: Mao arduino

RED5V

Blue

Green

4Ŕ�đLED

Sunday, May 4, 14

Page 65: Mao arduino

Arduino

pin 9

5V

pin 10pin 11

RED

BlueGreen

#13çăĆó�Ū_ http://code.mutienliao.tw/arduino/common_anode_RGB.pde

#13çăĆó�Ū_ http://code. mutienliao.tw/arduino/Serial_common_anode_RGB.ino

Sunday, May 4, 14

Page 66: Mao arduino

�ŧs�ÑđŰ

#13çăĆó�Ū_ http://code.mutienliao.tw/arduino/common_anode_RGB.pde

#13çăĆó�Ū_ http://code. mutienliao.tw/arduino/Serial_common_anode_RGB.ino

Sunday, May 4, 14

Page 67: Mao arduino

RGB sensor

Sunday, May 4, 14

Page 68: Mao arduino

VCCS1S0

LEDGND

VCCS3S2OUTGND

5Vpin 7pin 6

GND

pin 5pin 4pin 3

[Arduino] _ http://code.mutienliao.tw/arduino/LightSensing_Simple.ino

Sunday, May 4, 14

Page 69: Mao arduino

[Arduino] _ http://code.mutienliao.tw/arduino/LightSensing_showcolor.ino

FŲJşđčŗĊñ6!

[Processing] _ http://code.mutienliao.tw/processing/show_color.pde

Sunday, May 4, 14