Changes between Version 10 and Version 11 of rock/note/arduino
- Timestamp:
- Jan 20, 2010, 5:15:16 PM (15 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
rock/note/arduino
v10 v11 1 1 [[PageOutline]] 2 = = 【1.環境】 ==2 = 【1.環境】 = 3 3 * OS - Ubuntu 9.10 Desktop (32bit) 4 4 * gcc-avr - 1:4.3.3-1 5 6 [[BR]] 7 == 【2.安裝開發工具於 Ubuntu】 == 5 ---- 6 = 【2.安裝開發工具於 Ubuntu】 = 8 7 * 安裝 9 8 {{{ … … 17 16 $ ./arduino 18 17 }}} 19 20 [[BR]] 21 == 【3.Hello World】 == 18 ---- 19 = 【3.Hello World】 = 22 20 * 先透過 USB 連接到電腦,若是有抓到 Arduino 板子的話,可以看到 PWR 燈和 L 燈會亮起來,可透過 dmesg 指令去察看 23 21 {{{ … … 50 48 * 察看 Console,此時可以觀察板子上的 TX 燈號會亮起,表示正在傳送狀態 51 49 [[Image(Console.png,width=300px)]] 52 53 [[BR]] 54 == 【4.控制燈號】 == 50 ---- 51 = 【4.控制燈號】 = 55 52 * 此範例程式讓 L 燈亮5秒之後熄滅1秒,一樣透過 Arduino IDE "complie" 後再 "upload",之後可看 Arduino 板子上的 L 燈變化 56 53 {{{ … … 68 65 } 69 66 }}} 70 71 [[BR]] 72 == 【5.Interfacing with linux】 == 67 ---- 68 = 【5.Interfacing with linux】 = 73 69 * Arduino 在 linux 上會被視為一個 char device,可以透過簡單的導向功能,把輸入和輸出導向 Arduino 74 70 * 此段程式碼會讓 Arduino 把輸入的字元輸出 … … 90 86 }}} 91 87 [[Image(echo.png,width=300px)]] [[Image(tail.png,width=300px)]] 88 ---- 89 = 【6.Interfacing with processing】 = 90 || 本範例利用 processing 去擷取網頁內容,並傳送到Arduino|| 91 * processing code 92 {{{ 93 import processing.serial.*; 94 String feed = "http://trac.nchc.org.tw"; 95 String data; 96 Serial port; 92 97 93 [[BR]] 94 == 【可能遇到問題】 == 98 void setup(){ 99 100 String arduinoPort = Serial.list()[0]; 101 port = new Serial(this, arduinoPort, 9600); 102 103 104 105 } 106 107 void 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 {{{ 129 void setup() 130 { 131 Serial.begin(9600); 132 } 133 134 void 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 = 【可能遇到問題】 = 95 145 * 開啟 IDE 時有錯誤訊息 -> (1)檢查環境變數 (2)是否已安裝相關套件(avr-libc, gcc-avr...) 96 146 * 無法燒錄 -> (1)檢查Tool/Board (2)檢查 Tool/Serial (3)重新拔插USB介面 97 147 [[BR]] 98 = = 【參考資源】 ==148 = 【參考資源】 = 99 149 * 書目 100 150 * [http://www.books.com.tw/exep/prod/booksfile.php?item=0010446252 踏進互動科技世界 - 使用 Arduino](本書譯者收入的13%將捐助台灣88水災用)