Last active
December 4, 2018 05:26
-
-
Save wwin3286tw/6dd1ef4478fad057891d8b29738b3de2 to your computer and use it in GitHub Desktop.
HC05 藍芽模組,Ardunio測試用
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define BT_KEY_PIN 8 | |
#define HARDWARE_SERIAL_SPEED 38400 | |
void setup() | |
{ | |
pinMode(BT_KEY_PIN, OUTPUT); //設定KEY_PIN為輸出模式 | |
digitalWrite(BT_KEY_PIN, HIGH); //這將把藍芽模組的第34腳位拉高,使其進入AT模式 | |
Serial.begin(HARDWARE_SERIAL_SPEED); | |
Serial.println("Bluebooth>"); //看到此提示,即可在串列終端機輸入想輸入的AT指令 | |
void loop() | |
{ | |
// Keep reading from HC-05 and send to Arduino Serial Monitor | |
if (Serial.available()) | |
Serial.write(Serial.read()); | |
// Keep reading from Arduino Serial Monitor and send to HC-05 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define BT_KEY_PIN 8 | |
#define BEEPER_PIN 9 | |
#define R1_BTN 4 | |
#define HARDWARE_SERIAL_SPEED 38400 | |
void setup() | |
{ | |
pinMode(BT_KEY_PIN, OUTPUT); // this pin will pull the HC-05 pin 34 (key pin) HIGH to switch module to AT mode | |
pinMode(R1_BTN, INPUT); | |
digitalWrite(BT_KEY_PIN, HIGH); | |
Serial.begin(HARDWARE_SERIAL_SPEED); | |
Serial.println("[ARKLAB - Write Bluetooth Raud Rate Tool]"); | |
} | |
void loop() | |
{ | |
if ( digitalRead(R1_BTN) == LOW) { | |
Serial.println("Start Writting Bluetooth Parameter."); | |
Serial.write( "AT+UART?\r\n" ); //檢查藍芽是否有回應 | |
String BT_readString = Serial.readString(); | |
Serial.print(BT_readString); | |
if (BT_readString != "+UART:115200,0,0\r\n" && BT_readString != "") { | |
Serial.println("[Parameter NOT match, start writing.]"); | |
Serial.write("AT+UART=115200,0,0\r\n"); | |
Serial.print(Serial.readString()); | |
Serial.write("AT+ROLE=1\r\n"); | |
Serial.print(Serial.readString()); | |
Serial.println("[Start checking.]"); | |
Serial.write("AT+UART?\r\n"); | |
Serial.print(Serial.readString()); | |
Serial.write("AT+ROLE?\r\n"); | |
Serial.print(Serial.readString()); | |
Serial.println("[END]"); | |
Serial.println(""); | |
tone(BEEPER_PIN, 1000, 250); | |
delay(100); | |
tone(BEEPER_PIN, 1000, 250); | |
} else { | |
tone(BEEPER_PIN, 2000, 1000); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment