Encoding 发送alphabeth时仅接收2次方的串行数据

Encoding 发送alphabeth时仅接收2次方的串行数据,encoding,bluetooth,arduino,serial-port,Encoding,Bluetooth,Arduino,Serial Port,我正在尝试使用Arduino Uno和Sparkfun()中的模块执行一个简单的实验 我的硬件设置如下所示: Arduino(power through USB)->BlueSmirf ---(bluetooth)--> PC(no wired connection the the Arduino)->RealTerm 在Arduino上,以下草图正在运行: #include <SoftwareSerial.h> int txPin = 2; in

我正在尝试使用Arduino Uno和Sparkfun()中的模块执行一个简单的实验

我的硬件设置如下所示:

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);
}

剩下的字母和数字去了哪里?似乎所有的字母都是二的幂(即a=1,b=2,d=4,h=8,p=16)打印出来的,但其余的都没有。这只是巧合吗

我认为您的串行端口运行得太快了。根据sparkfun BlueSmirf示例中的注释,在“115200有时可能太快,NewSoftSerial无法可靠地中继数据”

使用下面的代码示例将波特率降低到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);
}
/*
蓝牙串行直通示意图示例
作者:吉姆·林德布洛姆
SparkFun电子公司
日期:2013年2月26日
许可证:公共领域
此示例草图将RN-42蓝牙模块转换为
以9600 bps(从115200开始)通信,并通过任何串行通信
串行监视器和蓝牙模块之间的数据。
*/
#包括
int bluetoothTx=2;//蓝牙配对的TX-O引脚,Arduino D2
int bluetoothRx=3;//蓝牙配对的RX-I引脚,Arduino D3
软件串行蓝牙(bluetoothTx、bluetoothRx);
无效设置()
{
bluetooth.begin(115200);//蓝牙配对默认为115200bps
bluetooth.print(“$”;//单独打印三次
蓝牙。打印($);
bluetooth.print(“$”;//进入命令模式
延迟(100);//短暂延迟,等待大副发回指令
bluetooth.println(“U,9600,N”);//暂时将波特率更改为9600,无奇偶校验
//115200有时可能太快,NewSoftSerial无法可靠地中继数据
bluetooth.begin(9600);//在9600启动bluetooth串行
}
void循环()
{
字符串textToSend=“abcdefghijklmnopqrstuv123456789”;
蓝牙打印(textToSend);
延迟(5000);
}

尝试将波特率降低到9600左右,您可能会在某处溢出缓冲区。即蓝牙开始(9600)@汤姆凯迪,你可能是对的。我确实尝试在9600运行它,但是现在使用当前的测试字符串。我会这么做的,看看我能得到什么。嗨,汤姆!我给了这个草图另一卷,并试图在调试过程中改变一些东西。事实证明,这个草图的失败点是“bluetooth.begin(9600)”——设置了第二次软件.Serial——这破坏了一切。我设法以波特率115200与调制解调器通信(获得上述奇怪行为),但当我切换到波特率9600时,arduino和调制解调器之间的连接完全断开。有什么想法吗?对不起,托莫德,我没有任何想法给你-除了在第二次调用begin()之前调用bluetooth.end()之外?这实际上是个不错的主意。我要试一试。谢谢。:-)
/*
  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);
}