新手試試 --- PC BlueTooth USB Dongle to Arduino BlueTooth with LCD Display 試作

上次試過兩個 Arduino 用 BlueTooth 主從方式單向發訊,今次就由PC向 Arduino 發訊,

所以塊 BlueTooth 板仔要用從屬果塊。塊板就用番上次果塊加一個大D既 LCD Display,
同埋加多個 Bluetooth 2 既 USB Dongle 連接PC。

PC BlueTooth USB Dongle to Arduino BlueTooth
PC BlueTooth USB Dongle to Arduino BlueTooth.jpg

用個舊code改左少少。
  1. // include the library code:
  2. #include <LiquidCrystal.h>

  3. // initialize the library with the numbers of the interface pins
  4. LiquidCrystal lcd(13, 11, 7, 6, 5, 4);

  5. void setup()
  6. {
  7.   pinMode(3,OUTPUT);
  8.   digitalWrite(3,HIGH);
  9.   // set up the LCD's number of rows and columns:
  10.   delay(1000);
  11.   lcd.begin(20, 4);
  12.   // Print a message to the LCD.
  13.   lcd.print("OK");
  14.   // Print a message to the LCD.
  15.   // set the cursor to column 0, line 1
  16.   // (note: line 1 is the second row, since counting begins with 0):
  17.   lcd.setCursor(0, 0);
  18.   Serial.begin(115200);
  19. }

  20. void loop()
  21. {
  22.    char val;
  23.    val = Serial.read();
  24.    if(val!=-1)
  25.     {
  26.         // serial display received char:
  27.                 lcd.print(val);
  28.      }
  29. }
複製代碼

TOP

插個 BlueTooth USB Dongle 去PC到就會自己認到同裝個 Driver。
係系統匣就會見到個icon,

BlueTooth icon
BlueTooth icon.gif

係個Device Manager就見到 Bluetooth Radios 同埋 Bluetooth Networks。

Bluetooth Radios
Bluetooth Radios.gif

Bluetooth Networks
Bluetooth Networks.gif

跟住就用Add Bluetooth Device去搵個 Arduino BlueTooth。
冇個icon,就去control panelel搵或者用Run  bthprops.cpl 都可以。

Add Bluetooth Device
Add Bluetooth Device.gif

個 Bluetooth UI 就會彈出來

Bluetooth UI
Bluetooth UI.gif

按 Add 就會準備搜索程序。
但繼續前必須完成拔走個 Bluetooth,compile同upload左個code去 Arduino 到
就再插返個 BlueTooth,然後接電源。

Adding Bluetooth Wizard
Adding Bluetooth Wizard.gif

個 LCD Display 見到OK,就可以繼續。搵到就會見到個 Arduino BlueTooth 名。

bluetooth found
bluetooth found.gif

選左個device就可以繼續,同埋輸入個 Passkey, E塊 Arduino BlueTooth 板用"1234"

Bluetooth Passkey
bluetooth passkey.gif

如果個Passkey正確就會繼續係部PC到加兩個聯絡端口。今次係com port 14,15。

Bluetooth com port
Bluetooth com port.gif

完成後,個Bluetooth UI就會係Devices度多左個device,同埋係個COM ports度多左兩個port。
其中com port 14係用作由PC輪出端口,com port 15係用作由PC接收端口。

bluetooth added device,bluetooth added COM port
bluetooth added device.gif bluetooth added com port.gif

咁就完成左安裝不過就未用得住, 同時Arduino bluetooth 上既Led會閃動。
要用個 Arduino bluetooth 就要先open個port去確認連線, 同時 Arduino bluetooth 上既Led會長著。

TOP

E個Code都係放在examples入面....

PC BlueTooth USB Dongle to Arduino BlueTooth with LCD Display Location

今次係試下傳送一個Text File,所以就用XP個Hyper terminal,可以係accessories/communication下搵到。

所以就要用根據加左用作輸出的com port 14。

PC_com port
PC_com port.gif

可以用同 Arduino bluetooth 唔同既傳輸speed。

PC_com port speed
PC_com port speed.gif

如果聯絡得上 Arduino bluetooth 上既Led就會長著。
見到Led長著就可以開始傳輸。

Hyper terminal sent file
Hyperterminal sent file.gif

用完就以disconnect

Hyperterminal disconnect
Hyperterminal disconnect.gif

有需要用就再call個 Arduino bluetooth

Hyperterminal connect
Hyperterminal connect.gif.gif

個 Arduino 收到個text file,就會將內容輸出到 LCD Display

PC BlueTooth USB Dongle to Arduino BlueTooth Success
PC BlueTooth USB Dongle to Arduino BlueTooth Success.jpg

PC BlueTooth USB Dongle to Arduino BlueTooth 試機成功....

ps 加番D圖

[ 本帖最後由 zonebaby 於 2009-9-27 13:24 編輯 ]

TOP

後記:

又試下用個 LCD Smartie 由 BlueTooth 發資料。

測試時,有信號錯既問題,幾個speed既設定,試左一輪,至可以正常,遲D至搵下真正原因。
最後將個舊既 LCD Smartie code改左個速度去115200就用得。
但個 LCD Smartie 既速度最高只可以上到19200, 再高就再唔可以聯絡到個 Arduino BlueTooth

LCD Smartie Setup
LCD Smartie Setup.gif

LCD Smartie
LCD Smartie.gif

個code係
  1. /*
  2.   LCD Smartie  testing
  3. */

  4. // include the library code:
  5. #include <LiquidCrystal.h>

  6. // initialize the library with the numbers of the interface pins
  7.      LiquidCrystal lcd(13, 11, 7, 6, 5, 4);
  8.      byte getByte;
  9.      byte temmBbyte[8];

  10. void setup() {
  11.      pinMode(3, OUTPUT);
  12.      Serial.begin(115200);
  13. //   set up the LCD's number of rows and columns:
  14.      lcd.begin(20,4);
  15.      lcd.clear();
  16.      digitalWrite(3, HIGH);
  17. }

  18. byte getSerialByte() {
  19.      int inSerialByte=0;
  20.      while (Serial.available()==0){}
  21.      inSerialByte=Serial.read();
  22.      return (byte) (inSerialByte & 0xff);
  23. }

  24. void loop() {
  25.      getByte=getSerialByte();
  26.      if (getByte==254)
  27.      {
  28. //     test next command byte  
  29.        switch (getSerialByte())
  30.        {
  31.          case  66: //LCD backlight on
  32.                  digitalWrite(3, HIGH);
  33.                  break;
  34.          case  70: //LCD backlight off
  35.                  digitalWrite(3,LOW);
  36.                  break;
  37.          case  71: //LCD position [col] [row]
  38.                  temmBbyte[0]=(getSerialByte()-1);
  39.                  temmBbyte[1]=(getSerialByte()-1);
  40.                  lcd.setCursor(temmBbyte[0],temmBbyte[1]);
  41.                  break;
  42.          case  72: //LCD home
  43.                  lcd.home();
  44.                  break;
  45.          case  74: //LCD underline cursor on
  46.                  lcd.cursor();
  47.                  break;
  48.          case  75: //LCD underline cursor off
  49.                  lcd.noCursor();
  50.                  break;
  51.          case  78: //LCD custom character [no of custom char] [8 bytes char pattern])
  52.                  getByte=getSerialByte();
  53.                  for (int i=0; i<=7; i++)
  54.                  {
  55.                    temmBbyte[i]=getSerialByte();
  56.                  }
  57.                  lcd.createChar(getByte, temmBbyte);
  58.                  break;
  59.          case  83: //LCD block cursor on
  60.                  lcd.blink();
  61.                  break;
  62.          case  84: //LCD block cursor off
  63.                  lcd.noBlink();
  64.                  break;
  65.          case  88: //LCD display clear
  66.                  lcd.clear();
  67.                  break;
  68.          case 152: //LCD backlight brightness [brightness]
  69.                  analogWrite(3, getSerialByte()) ;
  70.                  break;
  71.        }
  72.        return;

  73.     }
  74.     lcd.print(getByte);
  75. }
複製代碼
Arduino BlueTooth LCD Smartie
Arduino BlueTooth LCD Smartie .jpg

Arduino BlueTooth LCD Smartie from PC BlueTooth USB Dongle 試機成功....

[ 本帖最後由 zonebaby 於 2009-10-1 02:07 編輯 ]

TOP

試下配合lcd smartie 睇下得吾得
想知得吾得好耐不過冇錢買藍牙黎試

TOP

原帖由 薯餅v.v 於 2009-9-27 16:40 發表
試下配合lcd smartie 睇下得吾得
想知得吾得好耐不過冇錢買藍牙黎試


應該得,......計劃中.........

TOP

原帖由 zonebaby 於 2009-9-27 17:06 發表


應該得,......計劃中.........

期待

TOP

原帖由 薯餅v.v 於 2009-9-27 17:11 發表

期待


試左個舊code可以直接用,但要改下D速度。可意睇下post#5。

TOP


另外一點想知道就係用十幾蚊買粒usb bluetooth dongle
拆左佢強行用MCU控制有冇機會行得通
不過唔知係咪一黎入面粒chip 係bulit-in usb interface,再轉就好慢
有空會試一試

TOP