我正尝试使用Python PyBluez在Arduino Uno开发板(带有蓝牙屏蔽)和我的Linux操作系统之间建立蓝牙通信。Arduino和PyBluez之间的蓝牙通信
我已经成功将我的笔记本电脑与Uno配对。我能够连接到电路板,但电路板不读取正在发送的数据,也不能发送数据。
这里是Arduino的素描
#include <SoftwareSerial.h>
#define RxD 0 //receive data on digital 0
#define TxD 1 //transmit on digital 1
SoftwareSerial blueToothSerial(RxD, TxD);
int counter = 0;
int incoming;
void setup(void){
Serial.begin(9600);
//pinMode(RxD,INPUT);
//pinMode(TxD,OUTPUT);
setupBlueToothConnection();
}
void setupBlueToothConnection(){
blueToothSerial.begin(19200);
blueToothSerial.print("\r\n+STWMOD=0\r\n"); //set the bluetooth work in slave mode
blueToothSerial.print("\r\n+STNA=SeeedBTSlave\r\n"); //set the bluetooth name as "SeeedBTSlave"
blueToothSerial.print("\r\n+STOAUT=1\r\n"); // Permit Paired device to connect me
//blueToothSerial.print("\r\n+STAUTO=0\r\n"); // Auto-connection should be forbidden here
delay(2000); // This delay is required.
blueToothSerial.print("\r\n+INQ=1\r\n"); //make the slave bluetooth inquirable
Serial.println("The slave bluetooth is inquirable!");
delay(2000); // This delay is required.
blueToothSerial.flush();
}
void loop(){
if(blueToothSerial.available())
Serial.println(blueToothSerial.read());
blueToothSerial.write('x');
}
而且我的Python模块:
import bluetooth
import sys
bd_addr = "00:12:10:23:10:18" #itade address
port = 1
sock=bluetooth.BluetoothSocket(bluetooth.RFCOMM)
sock.connect((bd_addr, port))
print 'Connected'
sock.settimeout(1.0)
sock.send("x")
print 'Sent data'
data = sock.recv(1)
print 'received [%s]'%data
sock.close()
我的Arduino IDE 1.0.4,我的笔记本电脑正在运行的Ubuntu 11.10
你能使用内部串行监视器从Arduino板发送和接收数据/ Arduino IDE? – ton1c 2013-03-18 21:03:02
似乎为我工作。我上传了你的脚本到我的Arduino Uno上。并执行python脚本。这是结果:'user @ ubuntu:〜/ $ python w.py连接已发送数据[2]'。你确定你有连接到你的Arduino和蓝牙设备吗? – ton1c 2013-03-18 21:40:29
你使用哪种Bth盾牌:它是[这一个](http://www.seeedstudio.com/wiki/Bluetooth_Shield)? – angelatlarge 2013-03-19 04:49:16