2017-09-29 240 views
1

我是Arduino的新手,我一直在解決一直困擾着我幾天的問題。通過藍牙發送String + Int數據Arduino

我有一個Arduino Uno和一個HC-05藍牙模塊。

基本上我想通過藍牙一起發送字符串和內部數據。

CODE

#include <SoftwareSerial.h>   
SoftwareSerial BTSerial(10, 11); // RX | TX 

void setup(void) { 
    // Arduino setup 
    Serial.begin(9600); 
    // setting the baud rate of bluetooth 
    BTSerial.begin(38400); // HC-05 default speed in AT command more 
} 

void loop(void) { 
    int num = 123; 
    BTSerial.write("#"); // Works 
    BTSerial.write(num); // works 
    BTSerial.write(String(num) + "#"); 
    // Error: no matching function for call to 'SoftwareSerial::write(StringSumHelper&)' 
} 

而且結果字符串應該有最後的 '#' 字符。

根據Arduino Website,它有2個功能。

- Serial.write(val) 
- Serial.write(str) 

任何幫助表示讚賞。

謝謝。

回答

-1

寫入用於發送原始字節。你想改用Serial.print。

+0

我該如何使用Serial.print –

+0

通過藍牙發送數據?你有沒有嘗試過只有BTSerial.print(someVariable); –