├── ArduinoAndESP32_AI2.aia ├── ESP32SampleCode ├── 01_1Terminal_HelloWorld.ino ├── 01_2Terminal_Conversation.ino ├── 02_ButtonControlLed.ino └── 03_Measurement.ino ├── LICENSE └── README.md /ArduinoAndESP32_AI2.aia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/youjunjer/ArduinoAndESP32_BT_Android_By_AI2/0081e32fdde2ada2314d0aebe0214e81852549b7/ArduinoAndESP32_AI2.aia -------------------------------------------------------------------------------- /ESP32SampleCode/01_1Terminal_HelloWorld.ino: -------------------------------------------------------------------------------- 1 | //這個程式將會對配對的裝置(Android)傳送藍芽訊息一秒一次,請使用APP的Terminal 功能接收ESP32的訊息 2 | //This code will send BT string per second to Android, please use APP Terminal function to receive ESP32 message 3 | #include 4 | BluetoothSerial SerialBT; 5 | 6 | void setup(){ 7 | Serial.begin(115200); 8 | SerialBT.begin("Your ESP32 BT Name");//請將這裡改成你喜歡的藍芽名稱 9 | } 10 | 11 | void loop(){ 12 | SerialBT.println("Hello World"); 13 | delay(1000); 14 | } 15 | -------------------------------------------------------------------------------- /ESP32SampleCode/01_2Terminal_Conversation.ino: -------------------------------------------------------------------------------- 1 | //這個程式將可以讓ESP32與Android進行雙向對話,請使用Terminal功能進行測試。 2 | //This code let you make text conversation between ESP32 and Android, please use APP Terminal function. 3 | #include 4 | BluetoothSerial SerialBT; 5 | 6 | void setup(){ 7 | Serial.begin(115200); 8 | SerialBT.begin("Your ESP32 BT Name");//請將這裡改成你喜歡的藍芽名稱 9 | } 10 | 11 | void loop(){ 12 | //ESP32->Android 13 | if(Serial.available()) { 14 | String Sdata=Serial.readString(); 15 | SerialBT.println(Sdata); 16 | } 17 | //Android->ESP32 18 | if(SerialBT.available()) { 19 | String BTdata=SerialBT.readString(); 20 | Serial.println(BTdata); 21 | } 22 | delay(1); 23 | } 24 | -------------------------------------------------------------------------------- /ESP32SampleCode/02_ButtonControlLed.ino: -------------------------------------------------------------------------------- 1 | //這個程式將會對配對的裝置(Android)送出Button命令給ESP32,這些命令會使用字元'1','2','3'....等進行傳輸,ESP32則針對收到的文字來改變腳位狀態 2 | //This code will receive button command from android, such as '1','2','3'... When ESP32 receive the command, it will change the state of pins. 3 | // GPIO 15 -> GreenLED 4 | // GPIO 2 -> YellowLED 5 | // GPIO 4 -> RedLED 6 | // GPIO 16 -> Other 7 | #include 8 | BluetoothSerial SerialBT; 9 | 10 | void setup(){ 11 | Serial.begin(115200); 12 | SerialBT.begin("Your ESP32 BT Name");//請將這裡改成你喜歡的藍芽名稱 13 | pinMode(15,OUTPUT); //GreenLED 14 | pinMode(2,OUTPUT); //YellowLED 15 | pinMode(4,OUTPUT); //RedLED 16 | pinMode(16,OUTPUT); //Other(例如繼電器) 17 | } 18 | 19 | void loop(){ 20 | //ESP32->Android 21 | if(Serial.available()) { 22 | String Sdata=Serial.readString(); 23 | SerialBT.println(Sdata); 24 | } 25 | //Android->ESP32 26 | if(SerialBT.available()) { 27 | Serial.println(""); 28 | while(SerialBT.available()) { 29 | char btdata=SerialBT.read(); 30 | if(btdata=='1') {digitalWrite(15,HIGH);}//Turn ON GreenLed 31 | if(btdata=='2') {digitalWrite(15,LOW);}//Turn OFF GreenLed 32 | if(btdata=='3') {digitalWrite(2,HIGH);}//Turn ON YellowLed 33 | if(btdata=='4') {digitalWrite(2,LOW);}//Turn OFF YellowLed 34 | if(btdata=='5') {digitalWrite(4,HIGH);}//Turn ON RedLed 35 | if(btdata=='6') {digitalWrite(4,LOW);}//Turn OFF RedLed 36 | if(btdata=='7') {digitalWrite(16,HIGH);}//Turn ON OtherDevice 37 | if(btdata=='8') {digitalWrite(16,LOW);}//Turn OFF OtherDevice 38 | Serial.print(btdata); 39 | } 40 | } 41 | delay(1); 42 | } 43 | -------------------------------------------------------------------------------- /ESP32SampleCode/03_Measurement.ino: -------------------------------------------------------------------------------- 1 | // 這個程式將會對配對的裝置(Android)送出類比訊號給ESP32,這些命令會使用字串"25,32,255"三個逗號分隔,另外可以接收ESP32傳來的"32,25"兩筆資料,顯示在APP上 2 | // 會使用到RGB全彩LED及DHT11,請先安裝SimpleDHT及ESP32 analogWrite程式庫 3 | // GPIO 15 -> Blue pin of RGBLED 4 | // GPIO 2 -> Green pin of RGBLED 5 | // GPIO 4 -> Red pin of RGBLED 6 | // GPIO 16 -> Signal pin of DHT 11 7 | // 3.3V -> Vin pin of DHT11 8 | // GND -> GND pin of DHT11 9 | 10 | #include 11 | BluetoothSerial SerialBT; 12 | //Setup DHT11 13 | #include 14 | int pinDHT11 = 16; 15 | SimpleDHT11 dht11(pinDHT11); 16 | //送出溫濕度的時間間隔,由於藍芽必須即時接收,所以不使用delay 17 | long BTLastPublishTime;//紀錄最後送出時間 18 | long BTPublishInterval = 10000;//每10秒送出溫濕度一次 19 | #include 20 | 21 | void setup() { 22 | Serial.begin(115200); 23 | SerialBT.begin("Your ESP32 BT Name");//請將這裡改成你喜歡的藍芽名稱 24 | pinMode(15,OUTPUT); //Blue pin of RGBLED 25 | pinMode(2,OUTPUT); //Green pin of RGBLED 26 | pinMode(4,OUTPUT); //Red pin of RGBLED 27 | } 28 | 29 | void loop() { 30 | //ESP32->Android 31 | if(Serial.available()) { 32 | String Sdata=Serial.readString(); 33 | SerialBT.println(Sdata); 34 | } 35 | //Android->ESP32 36 | if(SerialBT.available()) { 37 | String btdata=SerialBT.readString(); 38 | Serial.println(btdata); 39 | //以 ',' 逗號拆解文字 40 | String Red=getValue(btdata,',',0); 41 | String Green=getValue(btdata,',',1); 42 | String Blue=getValue(btdata,',',2); 43 | Serial.print("Green=" + Green);Serial.print(",Red=" + Red);Serial.println(",Blue=" + Blue); 44 | //用類比寫入腳位4,2,15 45 | analogWrite(4, Red.toInt()); 46 | analogWrite(2, Green.toInt()); 47 | analogWrite(15, Blue.toInt()); 48 | } 49 | // Send DHT11 data to Android 50 | if ((millis() - BTLastPublishTime) >= BTPublishInterval ) { 51 | BTLastPublishTime = millis(); //更新最後傳輸時間 52 | byte temperature = 0; byte humidity = 0; 53 | int err = SimpleDHTErrSuccess; 54 | if ((err = dht11.read(&temperature, &humidity, NULL)) != SimpleDHTErrSuccess) { 55 | Serial.print("Read DHT11 failed, err="); Serial.print(SimpleDHTErrCode(err)); 56 | Serial.print(","); Serial.println(SimpleDHTErrDuration(err)); delay(1000); 57 | return; 58 | } 59 | Serial.print((int)temperature); Serial.print(" *C, "); 60 | Serial.print((int)humidity); Serial.println(" H"); 61 | String tempAndhumi=String(temperature)+ "," +String(humidity) ; 62 | SerialBT.println(tempAndhumi); 63 | } 64 | delay(1); 65 | } 66 | 67 | //此副程式用來拆解','分隔的字串 68 | String getValue(String data, char separator, int index){ 69 | int found = 0; 70 | int strIndex[] = { 0, -1 }; 71 | int maxIndex = data.length() - 1; 72 | for (int i = 0; i <= maxIndex && found <= index; i++) { 73 | if (data.charAt(i) == separator || i == maxIndex) { 74 | found++; 75 | strIndex[0] = strIndex[1] + 1; 76 | strIndex[1] = (i == maxIndex) ? i+1 : i; 77 | } 78 | } 79 | return found > index ? data.substring(strIndex[0], strIndex[1]) : ""; 80 | } 81 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 youjunjer 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ArduinoAndESP32_BT_Android_By_AI2 2 | [![Build Status](https://travis-ci.org/joemccann/dillinger.svg?branch=master)](https://travis-ci.org/joemccann/dillinger) 3 | 4 | 5 | ## 使用說明 6 | **本APP由小霸王實驗室研發,主要以Android手機的藍芽連接ESP32或其他藍芽裝置 7 | 應用於物聯網課程教學或實驗,APP免費下載且開源,無需版權,非商業領域可隨意使用。** 8 | 9 | ![未命名 - 2](https://user-images.githubusercontent.com/40359899/175762204-574c4be7-d2c2-41bc-b308-794520e38d2f.jpg) 10 | 11 | 12 | ** 13 | 【六大功能介紹】 14 | 15 | 1.序列通訊:實現藍芽即時雙向通訊 16 | 17 | 2.按鈕控制:內建8組自定義按鈕控制ESP32裝置 18 | 19 | 3.方向控制:四方向及3個自定義按鈕,可實現藍芽遙控車 20 | 21 | 4.加速感測:利用手機內建的陀螺儀及加速規,實現體感遙控 22 | 23 | 5.語音指令:結合手機的Google語音辨識,實現語音智能家電 24 | 25 | 6.度量工具:將ESP32所測量的數值傳遞至手機,呈現圖表 26 | 27 | ** 28 | 29 | -Developer Sihying, Huang & Junjer, You 30 | 31 | ## 檔案頁面 32 | 33 | 檔案中共有11個頁面視窗,以下說明名稱及對應的頁面內容 34 | 35 | | Screen | Description | 36 | | ------ | ------ | 37 | | Screen1 | loading 畫面 | 38 | | BT_SET | 按鈕控制設定主頁 | 39 | | BT_SET_A | 按鈕內容設置頁面-名稱、數據 | 40 | | VOICE_SET | 語音指令設定主頁 | 41 | | VOICE_SET1 | 指令內容設置頁面-指令名稱、數據 | 42 | | UP_SET | 方向控制設定主頁-數據 | 43 | | Speed_SET | 加速感測器設定主頁-數據 | 44 | | Measure_SET | 度量工具設定主頁-名稱、單位 | 45 | | Terminal_SET | 序列通訊設定主頁-字體、外觀 | 46 | | setting_page | 主要功能首頁區 | 47 | | Screen2 | 操作說明頁 | 48 | 49 | ## 功能首頁區 -setting_page 50 | 51 | AI2中藍芽功能有無法跨視窗操作的限制,因此頁面中包含了所有主要功能的指令圖塊及藍芽連結功能 52 | 並且使用元件中【可見性】屬性來解決功能區分的問題,你可以在這個頁面自由變動/取用以下功能。 53 | 54 | 1. 序列通訊功能-視窗元件、字體、外觀 55 | 2. 按鈕控制功能-按鈕元件、按鈕數量 56 | 3. 方向控制功能-按鈕元件、按鈕數量、放置位置 57 | 4. 加速感測功能-球型精靈、敏感容許值 58 | 5. 語音辨識功能-指令數量 59 | 6. 度量功能-讀取圖表外觀、數量、數值範圍 60 | 61 | ※ aia原檔中的重要圖塊,皆有相提供關的提示註解 62 | 63 | 64 | --- 65 | 66 | 67 | ### 1.序列通訊功能 68 | 69 | 70 | **1.1在已定義的【接收訊息】程序中,可從【createMessage】指令中的【time size】【text size】變動文字訊息的大小** 71 | 72 | ![termi block1](https://snipboard.io/Q8g40k.jpg) 73 | 74 | **1.2在已定義的【外觀顏色】程序中,可變動視窗的顏色與圖片** 75 | 76 | ![termi block1](https://snipboard.io/W48MZz.jpg) 77 | 78 | ### 2.按鈕控制功能 79 | 80 | 81 | **2.1使用【微型資料庫】指令即可增加按鈕數量,若想讓按鈕資料可任意編輯,可在【BT_SET】及【BT_SETA】視窗中做指令設定** 82 | 83 | ![termi block1](https://snipboard.io/Ma1mEc.jpg) 84 | 85 | **2.2取得變量中的數據索引值項目[3]後,即可透過藍芽傳送數據** 86 | 87 | ![termi block1](https://snipboard.io/pbwOVB.jpg) 88 | 89 | ### 3.方向控制功能 90 | 91 | 92 | **3.1使用【微型資料庫】指令即可增加按鈕數量,若想讓按鈕資料可任意編輯,可在【UP_SET】視窗中做指令設定** 93 | 94 | ![termi block1](https://snipboard.io/bTkPiB.jpg) 95 | 96 | **3.2取得指定變量中的數據後,即可透過藍芽傳送數據** 97 | 98 | ![termi block1](https://snipboard.io/vpN90m.jpg) 99 | 100 | 101 | ### 4.加速感測功能 102 | 103 | 104 | **4.1利用球精靈移動的X,Y值判斷手機傾斜方向,調整感測數值的範圍,即可變更數據傳送的靈敏度** 105 | 106 | ![termi block1](https://snipboard.io/jL0syg.jpg) 107 | 108 | **4.2位於中間範圍受機靜止時,將發送數據設為0,即不發送對應位置數據** 109 | 110 | ![termi block1](https://snipboard.io/QHTJ34.jpg) 111 | 112 | 113 | ### 5.語音辨識功能 114 | 115 | 116 | **5.1使用【微型資料庫】指令即可增加語音指令數量,若想讓語音資料可任意編輯,可在【VOICE_SET】及【VOICE_SET1】視窗中做指令設定** 117 | 118 | ![termi block1](https://snipboard.io/z7Mmob.jpg) 119 | 120 | **5.2位於中間範圍受機靜止時,將發送數據設為0,即不發送對應位置數據** 121 | 122 | ![termi block1](https://snipboard.io/L5ARox.jpg) 123 | 124 | 125 | ### 6.度量功能 126 | 127 | 128 | **6.1使用【微型資料庫】指令即可增加度量資料的組數,若想讓度量資料可任意編輯,可在【Measure_SET】視窗中做指令設定** 129 | 130 | ![termi block1](https://snipboard.io/bdzC36.jpg) 131 | 132 | **6.2在已定議程序【Update】中,可調整圖表外觀樣式** 133 | 134 | ![termi block1](https://snipboard.io/TjZlGF.jpg) 135 | 136 | **6.3利用【計時器】工具可即時讀取接收的數據,多筆資料的接收需先檢查【,】字串做判讀分別顯示,並以【是否為數字?】屬性做數據處理限制** 137 | 138 | ![termi block1](https://snipboard.io/bVzGEy.jpg) 139 | 140 | **6.4接收單一數據且數據>3個數字時 e.g.100,只顯示其一圖表數值,另個圖表數據自動設定為【0】 141 | 因此數據中可判斷有空白【 】字串且無【,】字串** 142 | 143 | ![termi block1](https://snipboard.io/IrNkvg.jpg) 144 | 145 | **6.5接收單一數據且數據>1個數字時 e.g.24.1,只顯示其一圖表數值,另個圖表數據自動設定為【0】,因此數據中可判斷有空白【 】字串** 146 | 147 | ![termi block1](https://snipboard.io/Sty1wK.jpg) 148 | 149 | 150 | ## Licnese 151 | 152 | MIT License 153 | 154 | Copyright (c) 2022 youjunjer 155 | 156 | Permission is hereby granted, free of charge, to any person obtaining a copy 157 | of this software and associated documentation files (the "Software"), to deal 158 | in the Software without restriction, including without limitation the rights 159 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 160 | copies of the Software, and to permit persons to whom the Software is 161 | furnished to do so, subject to the following conditions: 162 | 163 | The above copyright notice and this permission notice shall be included in all 164 | copies or substantial portions of the Software. 165 | 166 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 167 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 168 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 169 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 170 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 171 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 172 | SOFTWARE. 173 | 174 | [//]: # (These are reference links used in the body of this note and get stripped out when the markdown processor does its job. There is no need to format nicely because it shouldn't be seen. Thanks SO - http://stackoverflow.com/questions/4823468/store-comments-in-markdown-syntax) 175 | 176 | [dill]: 177 | [git-repo-url]: 178 | [john gruber]: 179 | [df1]: 180 | [markdown-it]: 181 | [Ace Editor]: 182 | [node.js]: 183 | [Twitter Bootstrap]: 184 | [jQuery]: 185 | [@tjholowaychuk]: 186 | [express]: 187 | [AngularJS]: 188 | [Gulp]: 189 | 190 | [PlDb]: 191 | [PlGh]: 192 | [PlGd]: 193 | [PlOd]: 194 | [PlMe]: 195 | [PlGa]: 196 | --------------------------------------------------------------------------------