首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >发送字母表时仅接收2的幂的串行数据

发送字母表时仅接收2的幂的串行数据
EN

Stack Overflow用户
提问于 2016-09-28 01:50:33
回答 1查看 73关注 0票数 1

我正在尝试使用Arduino Uno和来自Sparkfun (documentation)的BlueSmirf Bluetooth模块执行一个简单的实验。

我的硬件设置如下所示:

代码语言:javascript
复制
Arduino(power through USB)->BlueSmirf     ---(bluetooth)-->    PC(no wired connection the the Arduino)->RealTerm

在Arduino上,正在运行以下草图:

代码语言:javascript
复制
#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端口时,我只得到以下输出:

代码语言:javascript
复制
abdhp1248

剩下的字母和数字到哪里去了?似乎所有跟在2的幂后面的字母(即a=1,b=2,d=4,h=8,p=16)都会打印,但其他字母都不会打印。这只是一个巧合吗?

EN

回答 1

Stack Overflow用户

发布于 2016-09-28 05:14:50

我觉得你的串口运行得太快了。根据https://learn.sparkfun.com/tutorials/using-the-bluesmirf上的sparkfun BlueSmirf示例中的评论-“对于NewSoftSerial来说,115200有时可能太快了,无法可靠地中继数据”。

使用下面的代码示例将波特率降低到9600,修改自上述网页。

代码语言:javascript
复制
/*
  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);
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39731245

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档