wiki:rock/note/arduino

Version 8 (modified by rock, 15 years ago) (diff)

--

1.環境

  • OS - Ubuntu 9.10 Desktop (32bit)
  • gcc-avr - 1:4.3.3-1


2.安裝開發工具於 Ubuntu

  • 安裝
    $ sudo aptitude install binutils-avr avrdude gcc-avr
    
  • 安裝 Arduino IDE
    $ wget http://arduino.googlecode.com/files/arduino-0017.tgz
    $ tar zxvf arduino-0017.tgz
    $ cd arduino-0017
    $ ./arduino
    


3.Hello World

  • 先透過 USB 連接到電腦,若是有抓到 Arduino 板子的話,可以看到 PWR 燈和 L 燈會亮起來,可透過 dmesg 指令去察看
    [   51.480017] usb 4-2: new full speed USB device using uhci_hcd and address 5
    [   51.671681] usb 4-2: configuration #1 chosen from 1 choice
    [   51.703685] usbcore: registered new interface driver usbserial
    [   51.703703] USB Serial support registered for generic
    [   51.703739] usbcore: registered new interface driver usbserial_generic
    [   51.703742] usbserial: USB Serial Driver core
    [   51.722008] USB Serial support registered for FTDI USB Serial Device
    [   51.722100] ftdi_sio 4-2:1.0: FTDI USB Serial Device converter detected
    [   51.722128] usb 4-2: Detected FT232RL
    [   51.722131] usb 4-2: Number of endpoints 2
    [   51.722133] usb 4-2: Endpoint 1 MaxPacketSize 64
    [   51.722136] usb 4-2: Endpoint 2 MaxPacketSize 64
    [   51.722138] usb 4-2: Setting MaxPacketSize 64
    [   51.723643] usb 4-2: FTDI USB Serial Device converter now attached to ttyUSB0
    [   51.723662] usbcore: registered new interface driver ftdi_sio
    [   51.723664] ftdi_sio: v1.5.0:USB FTDI Serial Converters Driver
    
  • 開啟 Arduino IDE,設定連接埠

  • HelloWorld 範例程式 (選取範例檔,如下圖)

  • 編譯,按下 Verify 按鈕,若出現 「done compiling」表示編譯完成

  • 燒錄至 Arduino 版子

  • 察看 Console,此時可以觀察板子上的 TX 燈號會亮起,表示正在傳送狀態


4.控制燈號

  • 此範例程式讓 L 燈亮5秒之後熄滅1秒,一樣透過 Arduino IDE "complie" 後再 "upload",之後可看 Arduino 板子上的 L 燈變化
    #define LED 13
    void setup()
    {
    }
    
    void loop()
    {
      digitalWrite(LED, HIGH);
      delay(5000);
      digitalWrite(LED, LOW);
      delay(1000);
    }
    


4.Interfacing with linux

  • Arduino 在 linux 上會被視為一個 char device,可以透過簡單的導向功能,把輸入和輸出導向 Arduino
  • 此段程式碼會讓 Arduino 把輸入的字元輸出
    /*
    * Reflect serial input back.
    */
    void setup()
    {
      Serial.begin(9600);
    }
    
    void loop()
    {
      while (Serial.available() > 0) {
        Serial.write(Serial.read());
      }
    }
    


Attachments (8)

Download all attachments as: .zip