一Arduino的應用市場
二如何開始使用你的Arduino kit
三Arduino的入門與精深

一Arduino的應用市場
便宜——和其他平臺相比。arduino板是相當便宜。最便宜的arduino課可以自己動手制作,即使組裝好的成品,也不會超過200元。
跨平臺——arduino軟件在window,Macintosh OSX和Linux平臺上均可以操作,大部分其他的單片機只能運行在window操作系統下。
簡易的操作環境——初學者很容易就能學會arduino的編程環境,同時它還能為高級用戶提供高級運用。對于老師們來講,一般都很容易運用processing編程環境,如果學生使用processing編程環境的話,也很容易熟悉。
軟件開源并可拓展——arduino軟件是開源的,對于有經驗的程序員是可以拓展的。arduino編程語言可以通過c++庫進行拓展。如果有人想要去了解技術上的細節,可以通過arduino語言直接使用AVR c語言(因為arduino語言是機基于AVR c語言的)。類似,如果你有需要的話,也可以再arduino中寫入AVR c語言。
硬件開源并可拓展——arduino板是基于ateml 的atmelga8和atmelga128/328的單片機。arduino是基于creative Commons許可協議。所以有經驗的設計師根據需求設計自己的模塊,可以對其進行拓展和改造。甚至對于一些相對沒有經驗的用戶,也可以通過制作實驗板來理解arduino是如何工作的,省錢又省事。
arduino的起源
Massimo Banzi之前是意大利Ivrea一家高科技設計學校的老師。他的學生們經常抱怨找不到便宜好用的微控制器。 2005年冬天, Massimo Banzi跟David Cuartielles討論了這個問題。 David Cuartielles是一個西班牙籍晶片工程師,當時在這所學校做訪問學者。兩人決定設計自己的電路板,并引入了Banzi的學生David Mellis為電路板設計編程語言。兩天以后,David Mellis就寫出了程式碼。又過了三天,電路板就完工了。這塊電路板被命名為Arduino。

各種arduino型號
Arduino Uno
  
Arduino Nano Arduino GSM Shield Front Arduino Ethernet Shield
二如何開始使用你的Arduino kit
arduino的配置:
arduino是基于AVR平臺,對AVR庫進行二次封裝編譯,把端口都打包好了。神馬寄存器呀,地址指針呀,都不用寫。大大降低軟件開發難度,適合非專業愛好者使用。優點和缺點并存,因為是二次開發,所以代碼執行不如AVR代碼精練,代碼執行效率和代碼體積都弱于AVR直接編譯。
基本性能配置:
ditital i/o 數字輸入/輸出端口0-13.
anglog i/o 模擬輸入/輸出端口0-5.
支持ICP下載,支持tx/rx.
輸入電壓:支持3.3v/5v輸出。
處理器:支持atmel atmegal168/328處理器,因為支持者眾多,已有公司開發出32位的mcu支持arduino。
arduino的開發環境介紹
Arduino能通過各種各樣的傳感器來感知環境,通過控制燈光、馬達和其他的裝置來反饋、影響環境。板子上的微控制器可以通過Arduino的編程語言來編寫程序,編譯成二進制文件,燒錄進微控制器。對Arduino的編程是利用 Arduino編程語言 (基于 Wiring)和Arduino開發環境(基于 Processing)來實現的。基于Arduino的項目,可以只包含Arduino,也可以包含Arduino和其他一些在PC上運行的軟件,他們之間進行通信 (比如 Flash, Processing, MaxMSP)來實現。
Arduino是一個基于開放原始碼的軟硬件平臺,構建于開放原始碼simple I/O介面版,并且具有使用類似Java、C語y言Processing/Wiring開發環境。
可以快速使用Arduino與Adobe Flash, Processing, Max/MSP, Pure Data, SuperCollider等軟件結合,作出互動作品。 Arduino可以使用現有的電子元件例如開關或者傳感器或者其他控制器件、LED、步進馬達或其他輸出裝置。 Arduino也可以獨立運行,并與軟件進行交互,例如: Macromedia Flash, Processing, Max/MSP, Pure Data, VVVV或其他互動軟件…。 Arduino的IDE界面基于開放源代碼,可以免費下載使用,開發出更多令人驚艷的互動作品。
三Arduino的入門與精深
開始運行你的你的Arduino kit
一個簡單的程序讓讀取模擬端口ao的值并用串口發送
void setup() {
Serial.begin(9600);//串口波特率9.6kb//d0-tx//d1-rx
}
void loop()
{
int sensorValue = analogRead(A0);//讀取a0值(0-1023)
Serial.println(sensorValue);//串口發送數據
delay(1); //延時
}
注:arduino由初始化函數setup()
與循環函數loop組成。

串口控制輸出
void setup() {
Serial.begin(9600);
for (int thisPin = 2; thisPin < 7; thisPin++)
{
pinMode(thisPin, OUTPUT);//將d2-d7設置為輸出模式
}
}
void loop()
{
if (Serial.available() > 0) { //如果串口收到信息
int inByte = Serial.read();
switch (inByte) {
case 'a': //接受a,將d2置高
digitalWrite(2, HIGH);
break;
case 'b':
digitalWrite(3, HIGH); //接受b,將d3置高
break;
case 'c':
digitalWrite(4, HIGH); //接受c,將d4置高
break;
case 'd':
digitalWrite(5, HIGH); //接受d,將d5置高
break;
case 'e':
digitalWrite(6, HIGH); //接受e,將d6置高
break;
default:
// turn all the LEDs off:
for (int thisPin = 2; thisPin < 7; thisPin++)
{
digitalWrite(thisPin, LOW);
//其他情況就將d2-d7均置低
}
}
}
}

局域網控制LED燈
核心代碼:void loop () {
word pos =ether.packetLoop(ether.packetReceive());
if(pos)
{
if(strstr((char *)Ethernet::buffer + pos, "GET /led_off.png") != 0)
send_png_image(led_off, sizeof(led_off));
else if(strstr((char *)Ethernet::buffer + pos, "GET /led_on.png") != 0)
send_png_image(led_on, sizeof(led_on));
else
{
if(strstr((char *)Ethernet::buffer + pos, "GET /?LED1") != 0)
{ led1Status = !led1Status;
digitalWrite(LED1PIN, led1Status);
}
if(strstr((char *)Ethernet::buffer + pos, "GET /?LED2") != 0) { 網頁中LED圖標
led2Status = !led2Status;
digitalWrite(LED2PIN, led2Status);
}
BufferFiller bfill = ether.tcpOffset();
bfill.emit_p(PSTR("HTTP/1.0 200 OK\r\n"
"Content-Type: text/html\r\nPragma: no-cache\r\n\r\n"
"<html><head><title>WebLeds</title></head><body>"
"Toggle leds: "));
if(led1Status) bfill.emit_p(PSTR("<a href=\"/?LED1\"><img src=\"led_on.png\"></a>"));
else bfill.emit_p(PSTR("<a href=\"/?LED1\"><img src=\"led_off.png\"></a>"));
if(led2Status) bfill.emit_p(PSTR("<a href=\"/?LED2\"><img src=\"led_on.png\"></a>"));
else bfill.emit_p(PSTR("<a href=\"/?LED2\"><img src=\"led_off.png\"></a>"));
bfill.emit_p(PSTR("</body></html>"));
ether.httpServerReply(bfill.position());
}
}
}

讓你的arduino連入物聯網





小節:
通過一周對arduino的學習,我們意識到雖然arduino的開源軟硬件都很多,在消費類電子市場占有很大比例,但 對于資深工程師來說,arduino只是AVR的入門硬件,在精密電子儀器,中高端設備中有明顯的不足。對學習嵌入式,物聯網方面有一定的輔助作用。
|