kedonghe 发表于 2017-8-19 04:21:18

Arduino蓝牙模块通讯问题求助 急急急

我在Arduino uno上连接了一个蓝牙模块和传感器,目的想把传感器的数据通过蓝牙模块发送给连接的手机端。

在最初调试代码时候,一直使用USB供电。直到代码成功后,因为具体要求,利用电池进行供电,但是蓝牙模块不传输数据了。之前有看别的帖子,说是电池问题,我起初也怀疑这个,但用了实验室的恒稳电源发生器设置成12V,蓝牙模块还是工作不了(可以连接设备但是不能发送数据)。

后来把传感器给拆掉只留下蓝牙模块,还是老样子。我现在认为是这个SoftwareSerial库的问题,涉及到了串口。但是本人没有办法能够让通信不涉及到串口,希望大家可以给出建议。

使用的Arduino板子是RedBoard,蓝牙模块是BlueSMiRF Gold。

测试代码如下:

#include <SoftwareSerial.h>

int bluetoothTx = 2;// TX-O pin of bluetooth mate, Arduino D2
int bluetoothRx = 3;// RX-I pin of bluetooth mate, Arduino D3

SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);

int bpm = 50;

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);             // we agree to talk fast!

bluetooth.begin(115200);// The Bluetooth Mate defaults to 115200bps
bluetooth.print("$");// Print three times individually
bluetooth.print("$");
bluetooth.print("$");// Enter command mode
delay(100);// Short delay, wait for the Mate to send back CMD
bluetooth.println("U,9600,N");// Temporarily Change the baudrate to 9600, no parity
// 115200 can be too fast at times for NewSoftSerial to relay the data reliably
bluetooth.begin(9600);// Start bluetooth serial at 9600
}

void loop() {
// put your main code here, to run repeatedly:
if (bpm >= 100)
{
    bpm = 50;
    }
bluetooth.println((float)bpm);
bpm = bpm+1;
delay(2000);

}

Stormer 发表于 2017-8-19 06:15:00

本帖最后由 Stormer 于 2017-8-19 06:19 编辑

光电压高没用,是不是电流太小了。适当提高电流试试。看看蓝牙模块的说明,具体需要多大电压和电流。

还有你这代码

Serial.begin(9600);             // we agree to talk fast!

bluetooth.begin(115200);

……

bluetooth.begin(9600);

为什么不在一开始就写bluetooth.begin(9600);?


蓝牙的代码挺多吧,再找找看,我没用过。。

kedonghe 发表于 2017-8-19 06:37:07

Stormer 发表于 2017-8-19 06:15
光电压高没用,是不是电流太小了。适当提高电流试试。看看蓝牙模块的说明,具体需要多大电压和电流。

还 ...

setup代码是为了让蓝牙模块进入工作模式,即command mode。

电流问题我还没有测试过,应该不是这个吧。我用的是电源发生器,电流大小还是可以保证的,不过还是会去测试一下。

我现在比较担心的是SoftwareSerial这个库,会要求Arduino与电脑必须相连接。

zjz5717 发表于 2017-8-19 09:39:46

kedonghe 发表于 2017-8-19 06:37
setup代码是为了让蓝牙模块进入工作模式,即command mode。

电流问题我还没有测试过,应该不是这个吧 ...

那你直接用serial不行吗

BeTe 发表于 2017-8-19 10:21:40

顶起、、、、

huozhen 发表于 2017-8-19 17:00:31

可以直接用serial输出,你可以先拿个usb转ttl的模块用有线和电脑调试一下,没问题的话就是蓝牙模块的问题了,我之前用的是个hc-06的蓝牙模块,
页: [1]
查看完整版本: Arduino蓝牙模块通讯问题求助 急急急