我正在使用一个HC_05蓝牙模块和一个Arduino Uno试图建立一个简单的蓝牙连接我的Windows (HTC8X)。我是跟随在线教程这里。
当我进入设置时,我的手机会看到"HC_05“蓝牙信号。我点击它,它马上就连接起来了。它保持连接5-10秒,然后突然断开连接.
我认为我的手机没有接收到来自蓝牙模块的任何数据,因此决定信号是毫无价值的,并丢弃它。但即便如此,为什么呢?当我从链接代码调用btSerial.read()时,这不是在和设备说话吗?
“Arduino法典”:
#include <SoftwareSerial.h>
const int TX_BT = 10;
const int RX_BT = 11;
SoftwareSerial btSerial(TX_BT, RX_BT);
//Frequency to send periodic messages to Windows Phone, in milliseconds.
//Core code.
const unsigned long periodicMessageFrequency = 5000;
unsigned long time = 0;
//Process the incoming command from Windows Phone.
//It should be changed according to what you want to do.
void processCommand(char* command) {
}
//Send a message back to the Windows Phone.
//Is can't be changed.
void sendMessage(char* message) {
int messageLen = strlen(message);
if(messageLen < 256) {
btSerial.write(messageLen);
btSerial.print(message);
}
}
//Send a set of periodic messages to the Windows Phone.
//It should be changed according to what you want to do.
//This message could be a sensor data, like a thermometer data.
void sendPeriodicMessages() {
}
//Setup Arduino function
void setup() {
Serial.begin(9600);
Serial.println("USB Connected");
btSerial.begin(9600);
}
//Loop Arduino function
//It can't be changed
void loop() {
if(btSerial.available()) {
int commandSize = (int)btSerial.read();
char command[commandSize];
int commandPos = 0;
while(commandPos < commandSize) {
if(btSerial.available()) {
command[commandPos] = (char)btSerial.read();
commandPos++;
}
}
command[commandPos] = 0;
processCommand(command);
}
unsigned long currentTime = millis();
if((currentTime - time) > periodicMessageFrequency) {
sendPeriodicMessages();
time = currentTime;
}
}HC_05按以下方式连接:
GND -> GND
3.3V -> 3.3V
RX -> D11
TX-> D10发布于 2015-07-09 08:45:40
您将HC-05与Arduino直接连接到Tx线路.HC-05应该在3.3v而不是5伏的情况下驱动。您的Arduino Tx引脚将在HC-05的Rx线路上提供5v信号,高于重新推荐的水平。尝试在Arduino Tx引脚(5v)和HC-05 Rx引脚(3.3V)之间放置一个电压转换器。
也许内部有一个保护,当电压超过3.3时,可以重置HC-05内部的微控制器。
https://stackoverflow.com/questions/22162519
复制相似问题