2016-09-27 4 views
1

Arduino UnoとSparkfunのBlueSmirf Bluetoothモジュールで簡単な実験を実行しようとしています(documentation)。アルファベットの送信時に2の累乗でシリアルデータのみを受信

私のハードウェアのセットアップは次のようになります。

Arduino(power through USB)->BlueSmirf  ---(bluetooth)--> PC(no wired connection the the Arduino)->RealTerm 

をアルドゥイーノで、次のスケッチが実行されている:

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

さて、BluetoothはPCにうまく接続されているが、私は点検したときにRealTermのCOMポートでは、私は次の出力しか得られません:

abdhp1248 

ここで残ったのはgの文字と数字は行く?これは、2の累乗に続くすべての文字(つまり、a = 1、b = 2、d = 4、h = 8、p = 16)のように見えますが、残りはありません。これはちょうど偶然でしょうか?

+1

ボーレートを9600に下げてみてください。バッファがあふれている可能性があります。すなわち、 bluetooth.begin(9600); – TomKeddie

+0

@TomKeddie、あなたは正しいかもしれません。私は9600で実行しようとしましたが、今現在のテスト文字列で実行します。私はそれを行い、私が得ることをします。 –

答えて

1

シリアルポートが速すぎると思います。 https://learn.sparkfun.com/tutorials/using-the-bluesmirfのsparkfun BlueSmirfの例のコメントによると、 "115200はNewSoftSerialがデータを確実に中継するのが速すぎることがあります"。

以下のコード例を使用して、上記のWebページから変更してボーレートを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); 
} 
+0

こんにちは、トム!私はこのスケッチに別のロールを与えて、それをデバッグする際にいくつかの変更を試みました。このスケッチの失敗点は、2度目のSoftware.Serialが設定された "bluetooth.begin(9600)"であり、これはすべて破損していることが分かります。私はボーレート115200(上記の奇妙な動作を得る)でモデムと通信することができますが、私がボー9600に切り替えると、arduinoとモデムの間の接続は完全に無くなります。何か案は? –

+1

申し訳ありませんTormod、あなたのためのアイデアはありません - あなたはもう一度begin()を呼び出す前にbluetooth.end()を呼び出すことを除いて? – TomKeddie

+0

これは実際にはかなり良い考えです。私はそれを試してみましょう。ありがとう。 :-) –

関連する問題