我正在尝试使用Arduino Uno和来自Sparkfun (documentation)的BlueSmirf Bluetooth模块执行一个简单的实验。
我的硬件设置如下所示:
Arduino(power through USB)->BlueSmirf ---(bluetooth)--> PC(no wired connection the the Arduino)->RealTerm在Arduino上,正在运行以下草图:
#include <SoftwareSerial.h>
int txPin = 2;
int rxPin = 3;
SoftwareSerial bluetooth(txPin, rxPin);
void setup() {
bluetooth.begin(115200);
delay(100);
}
void loop() {
String textToSend = "abcdefghijklmnopqrstuvw123456789";
bluetooth.print(textToSend);
delay(5000);
}现在,蓝牙可以很好地连接到PC,但当我在RealTerm中检查COM端口时,我只得到以下输出:
abdhp1248剩下的字母和数字到哪里去了?似乎所有跟在2的幂后面的字母(即a=1,b=2,d=4,h=8,p=16)都会打印,但其他字母都不会打印。这只是一个巧合吗?
发布于 2016-09-28 05:14:50
我觉得你的串口运行得太快了。根据https://learn.sparkfun.com/tutorials/using-the-bluesmirf上的sparkfun BlueSmirf示例中的评论-“对于NewSoftSerial来说,115200有时可能太快了,无法可靠地中继数据”。
使用下面的代码示例将波特率降低到9600,修改自上述网页。
/*
Example Bluetooth Serial Passthrough Sketch
by: Jim Lindblom
SparkFun Electronics
date: February 26, 2013
license: Public domain
This example sketch converts an RN-42 bluetooth module to
communicate at 9600 bps (from 115200), and passes any serial
data between Serial Monitor and bluetooth module.
*/
#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);
void setup()
{
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()
{
String textToSend = "abcdefghijklmnopqrstuvw123456789";
bluetooth.print(textToSend);
delay(5000);
}https://stackoverflow.com/questions/39731245
复制相似问题