Changes between Version 10 and Version 11 of rock/note/arduino


Ignore:
Timestamp:
Jan 20, 2010, 5:15:16 PM (14 years ago)
Author:
rock
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • rock/note/arduino

    v10 v11  
    11[[PageOutline]]
    2 == 【1.環境】 ==
     2= 【1.環境】 =
    33 * OS - Ubuntu 9.10 Desktop (32bit)
    44 * gcc-avr - 1:4.3.3-1
    5 
    6 [[BR]]
    7 == 【2.安裝開發工具於 Ubuntu】 ==
     5----
     6= 【2.安裝開發工具於 Ubuntu】 =
    87 * 安裝
    98{{{
     
    1716$ ./arduino
    1817}}}
    19 
    20 [[BR]]
    21 == 【3.Hello World】 ==
     18----
     19= 【3.Hello World】 =
    2220 * 先透過 USB 連接到電腦,若是有抓到 Arduino 板子的話,可以看到 PWR 燈和 L 燈會亮起來,可透過 dmesg 指令去察看
    2321{{{
     
    5048   * 察看 Console,此時可以觀察板子上的 TX 燈號會亮起,表示正在傳送狀態
    5149[[Image(Console.png,width=300px)]]
    52 
    53 [[BR]]
    54 == 【4.控制燈號】 ==
     50----
     51= 【4.控制燈號】 =
    5552 * 此範例程式讓 L 燈亮5秒之後熄滅1秒,一樣透過 Arduino IDE "complie" 後再 "upload",之後可看 Arduino 板子上的 L 燈變化
    5653{{{
     
    6865}
    6966}}}
    70 
    71 [[BR]]
    72 == 【5.Interfacing with linux】 ==
     67----
     68= 【5.Interfacing with linux】 =
    7369 * Arduino 在 linux 上會被視為一個 char device,可以透過簡單的導向功能,把輸入和輸出導向 Arduino
    7470 * 此段程式碼會讓 Arduino 把輸入的字元輸出
     
    9086}}}
    9187[[Image(echo.png,width=300px)]] [[Image(tail.png,width=300px)]]
     88----
     89= 【6.Interfacing with processing】 =
     90|| 本範例利用 processing 去擷取網頁內容,並傳送到Arduino||
     91 * processing code
     92{{{
     93import processing.serial.*;
     94String feed = "http://trac.nchc.org.tw";
     95String data;
     96Serial port;
    9297
    93 [[BR]]
    94 == 【可能遇到問題】 ==
     98void setup(){
     99
     100  String arduinoPort = Serial.list()[0];
     101  port = new Serial(this, arduinoPort, 9600);
     102
     103
     104
     105}
     106
     107void draw(){
     108    try {
     109    URL url = new URL(feed);  // An object to represent the URL
     110    // prepare a connection   
     111    URLConnection conn = url.openConnection();
     112    conn.connect(); // now connect to the Website
     113 
     114    BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
     115
     116    while ((data = in.readLine()) !=null){
     117    port.write(in.readLine());
     118    }
     119   
     120  }
     121  catch (Exception ex) { // If there was an error, stop the sketch
     122    ex.printStackTrace();
     123    System.out.println("ERROR: "+ex.getMessage());
     124  }
     125}
     126}}}
     127 * Arduino code
     128{{{
     129void setup()
     130{
     131  Serial.begin(9600);
     132}
     133
     134void loop()
     135{
     136  while (Serial.available() > 0) {
     137    Serial.write(Serial.read());
     138  }
     139}
     140 * 執行結果
     141[[Image(processing_arduino.png,width=350px)]]
     142}}}
     143----
     144= 【可能遇到問題】 =
    95145 * 開啟 IDE 時有錯誤訊息 -> (1)檢查環境變數 (2)是否已安裝相關套件(avr-libc, gcc-avr...)
    96146 * 無法燒錄 -> (1)檢查Tool/Board (2)檢查 Tool/Serial (3)重新拔插USB介面
    97147[[BR]]
    98 == 【參考資源】 ==
     148= 【參考資源】 =
    99149 * 書目
    100150   * [http://www.books.com.tw/exep/prod/booksfile.php?item=0010446252 踏進互動科技世界 - 使用 Arduino](本書譯者收入的13%將捐助台灣88水災用)