04-藍牙控制
(2017/04/09)
參考資料:Arduino Otto 跳舞機器人
官網:http://otto.strikingly.com/
Otto的Arduino Source Code網址:https://github.com/OttoDIY/OttoDIY
=====================================
設定HC06藍牙模組
Otto先不要接上藍牙
進入Arduino IDE中,開啟官網程式中的HC06_BT_config,直接上傳程式
將HC06藍牙模組接上Nano擴展板
HC-06與Arduino Nano接線方式如下:
HC-06 GND --> Nano GND Pin
HC-06 VCC (5V) ---> Nano 5V
HC-06 TX --> Nano RX
HC-06 RX --> Nano TX
開啟序列埠監控視窗,並將右下角的鮑速選9600
3.靜待幾秒後,會將資料寫進HC06藍牙模組,這時藍牙模組就設定好了(名稱、鮑速及密碼)
手機連接HC06藍牙模組
進入手機藍牙設定,重新整理後,發現可用的裝置中有Zowi這個設備
輸入密碼,並完成配對
測試 OttoDIY_EasyBluetooth 程式 (接續前一個單元)
開啟官網檔案中的OttoDIY_EasyBluetooth,上傳程式時,記得要將HC06的RX及TX的線先拔掉,否則程式寫不進去
這時也可以與上一單元一樣利用序列埠監控視窗來控制
if (Serial.available()) //If something received over bluetooth, store the char
dato= Serial.read();
//check the char received
switch(dato)
{//if we receive a...
case 85: //"U": Up arrow received
{
Otto.walk(2,1000,1); //2 steps FORWARD
break;
}
case 68: //"D": Down arrow received
{
Otto.walk(2,1000,-1); //2 steps FORWARD
break;
}
case 67: //"C": Center button received
{
Otto.playGesture(OttoFretful);
Otto.home();
Otto.sing(S_sleeping);
delay(1000);
break;
}
case 76: //"L": Left arrow received
{
Otto.turn(2,1000,1);//2 steps turning RIGHT
delay(50);
break;
}
case 82: //"R": Right arrow received
{
Otto.turn(2,1000,-1);//2 steps turning RIGHT
delay(50);
break;
}
case 97: // "a" Received
{
Otto.moonwalker(3, 1000, 25, 1);
Otto.home();
break;
}
case 98: // "b" Received
{
Otto.bend (1, 2000, 1);
Otto.home();
break;
}
case 99: // "c" Received
{
Otto.ascendingTurn(1, 2000, 22);
Otto.home();
break;
}
case 100: // "d" Received
{
Otto.updown(1, 2000, 22);
Otto.home();
break;
}
case 101: // "e" Received----OBSTACLE MODE ON!!!! (until a button is pressed in the app)------
{
obstacleMode();
break;
}
//////////You can add different modes here with the other buttons in the app (f,g,h...)
}
利用APP Inventor 來寫手機APP ,操控以上動作 (如果不想自己寫APP,也可直接用Zowi提供的APP來控制,此部分下個單元介紹)
有關APP Inventor,下次有空再來寫了