
坊間有關HC-05藍芽模組的預設鮑率,有的寫9600 bps,有的寫38400 bps,筆者兩種版本的硬體都有買過,本篇文章一步步導引如何修改faya藍芽模組的Baud Rate,以便符合應用上的要求,例如和Scratch連線時,Baud Rate需為38400 bps才可。
本篇文章參考自以下網址,本篇文中只介紹程序,內容原理請參考原文
http://www.instructables.com/id/Modify-The-HC-05-Bluetooth-Module-Defaults-Using-A/
學習目標 : 修改faya藍芽模組的Baud Rate
學習時間 : 20min
示範模組 : (1) faya brickNano
(2) faya藍芽模組
======================程序======================
1. 電源線連接

2. 信號線連接
Arduino D9 => 藍芽模組_KEY
Arduino D10 => 藍芽模組_TxD
Arduino D11 => 藍芽模組_RxD
3. Arduino燒錄以下程式,燒錄成功後關閉Arduino程式介面
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
/* | |
AUTHOR: Hazim Bitar (techbitar) | |
DATE: Aug 29, 2013 | |
LICENSE: Public domain (use at your own risk) | |
CONTACT: techbitar at gmail dot com (techbitar.com) | |
*/ | |
#include <SoftwareSerial.h> | |
SoftwareSerial BTSerial(10, 11); // RX | TX | |
void setup() | |
{ | |
pinMode(9, OUTPUT); // this pin will pull the HC-05 pin 34 (key pin) HIGH to switch module to AT mode | |
digitalWrite(9, HIGH); | |
Serial.begin(9600); | |
Serial.println("Enter AT commands:"); | |
BTSerial.begin(38400); // HC-05 default speed in AT command more | |
} | |
void loop() | |
{ | |
// Keep reading from HC-05 and send to Arduino Serial Monitor | |
if (BTSerial.available()) | |
Serial.write(BTSerial.read()); | |
// Keep reading from Arduino Serial Monitor and send to HC-05 | |
if (Serial.available()) | |
BTSerial.write(Serial.read()); | |
} |
4. 將Arduino和藍芽模組間的電源線拔掉,2秒後再插回去,此時藍芽模組下的紅燈約每兩秒閃一下,代表模組已經進入AT command模式,此模式下能夠讓我們修改baud rate。
5. 開啟Arduino程式,點選序列埠監控視窗(毋須上傳程式),視窗會顯示"Enter AT Commands"訊息,此時輸入[AT],如果回應[OK],代表模組可在AT Command模式下順利溝通。

6. 輸入[AT+UART],視窗會回應目前的Baud Rate,由下圖知預設baud rate 為9600 bps。

7. 輸入[AT+UART=38400,0,0],將預設baud rate修改成38400,系統會回應OK告知修改完成。
8. 再次輸入[AT+UART],可查看 baud rate已更改成38400了。
更多的HC-05 AT Command可下載此檔案查詢!
fayalab 粉絲團
沒有留言:
張貼留言