2009-09-02 42 views
1

DF机器人蓝牙模块如何连接到Arduino以便Arduino可以与之通信。DF机器人蓝牙模块与Arduino的接口

我用this tutorial

我设法让灯闪烁在模块上,它似乎可以配对,但是当我运行串行监视器并发送一个字母(说'H')这应该打开一个灯我得到Java错误:

java.io.IOException: Bad file descriptor in nativeDrain 
    at gnu.io.RXTXPort.nativeDrain(Native Method) 
at gnu.io.RXTXPort$SerialOutputStream.flush(RXTXPort.java:1201) 
at processing.app.Serial.write(Serial.java:470) 
at processing.app.Serial.write(Serial.java:492) 
at processing.app.SerialMonitor.send(SerialMonitor.java:128) 
at processing.app.SerialMonitor.access$100(SerialMonitor.java:29) 
at processing.app.SerialMonitor$4.actionPerformed(SerialMonitor.java:82) 
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source) 
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source) 
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source) 
at javax.swing.DefaultButtonModel.setPressed(Unknown Source) 
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source) 
at java.awt.Component.processMouseEvent(Unknown Source) 
at javax.swing.JComponent.processMouseEvent(Unknown Source) 
at java.awt.Component.processEvent(Unknown Source) 
at java.awt.Container.processEvent(Unknown Source) 
at java.awt.Component.dispatchEventImpl(Unknown Source) 
at java.awt.Container.dispatchEventImpl(Unknown Source) 
at java.awt.Component.dispatchEvent(Unknown Source) 
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) 
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) 
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) 
at java.awt.Container.dispatchEventImpl(Unknown Source) 
at java.awt.Window.dispatchEventImpl(Unknown Source) 
at java.awt.Component.dispatchEvent(Unknown Source) 
at java.awt.EventQueue.dispatchEvent(Unknown Source) 
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) 
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) 
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) 
at java.awt.EventDispatchThread.pumpEvents(Unknown Source) 
at java.awt.EventDispatchThread.pumpEvents(Unknown Source) 
at java.awt.EventDispatchThread.run(Unknown Source) 

我检查了线路和我有RXD要去RX在董事会和TXD到TX(引脚1)(引脚0),其余有线了,但同样仍然没有运气。什么可能是这个问题?

这是我对Arduino的代码:

int ledpin = 13; 
char val; 
void setup() { 
    pinMode(ledpin, OUTPUT); // pin 48 (on-board LED) as OUTPUT 
    Serial.begin(9600); // start serial communication at 9600bps 
} 

void loop() { 
    if(Serial.available()) { // if data is available to read 
     val = Serial.read(); // read it and store it in 'val' 
    } 

    if(val == 'H') { // if 'H' was received 
     digitalWrite(ledpin, HIGH); // turn ON the LED 
    } else { 
     digitalWrite(ledpin, LOW); // otherwise turn it OFF 
    } 

    delay(100); // wait 100ms for next reading 
} 
+0

您是否能够直接将Arduino连接到串行端口并使通信正常工作(即没有混合蓝牙模块)? – 2009-09-02 15:56:55

+0

是的,它似乎只是蓝牙不喜欢的IDE连接库liburi – 2009-09-03 09:00:38

+0

请你详细介绍一下组件(Arduino IDE,串口,蓝牙模块,Arduino等)以及它们之间的通信机制(串口,蓝牙,等等。)?特别是我不清楚如何将数据发送到串行端口转换为蓝牙信号并由模块接收。 – 2009-09-03 09:39:01

回答

1

这可能是一个狡猾的电源供应Arduino /蓝牙模块可能会导致此错误(即它可能与this Arduino Forum Topic中报告的错误有关)。

+0

嗯是的我想,但是我怎么能得到它工作的自定义C#应用程序,但不是标准 – 2009-09-03 22:09:37

+0

它可能取决于如果。 NET库和gnu.io.RXTXPort代码句柄以不同方式丢失连接(例如,G。重新建立连接与关闭关联的文件描述符)? – 2009-09-06 11:28:35

+0

经过一番调查似乎是这样的情况下,我尝试了另一个arduino,似乎很好地工作,谢谢! – 2009-09-07 12:23:50

0

我在通过串口GSM调制解调器建立从PC通讯也有类似的烦恼。我第一次在vista上使用java.comm,这是不可能的。后来,我转而使用RxTxComm,它更加可靠。改用它。

+0

我使用的是Arduino IDE,所以我没有选择它使用的端口连接,也有看它确实使用... RXTXPort $ SerialOutputStream.flush(RXTXPort ... – 2009-09-02 10:55:49

+0

我的不好,我直接去了代码,并没有看到任何RxTx的命令,所以我发布它nvm。 – 2009-09-02 11:21:46

1

尝试将您的RXTX库升级到最新版本。 IIRC Arduino IDE捆绑了它的一个版本。

+0

我已经试过这个,没有运气 – 2009-09-03 09:58:19

1

这是一个长镜头,但...

在链接的教程中的示例使用的115200波特率(而不是9600在您的示例中使用),并说:

Check the serial setting! Make sure the baud rate is set to 115200 on both master and slave.

这可能是两种:

  • 这只能与115200波特率(这似乎不太可能),或者可能是
  • 桅杆上的波特率呃和奴隶是不是9600
+0

您好,我已经尝试过,但仍然没有运气感谢您的帮助 – 2009-09-03 09:31:08

+0

您是否尝试过更简单的示例代码在教程中? – 2009-09-03 09:39:32

+0

是的,并没有什么通过,所以我想我会尝试发送数据,然后我可以truley确保 – 2009-09-03 09:53:01

1

您应该将蓝牙模块的Rx连接到Arduino板上的Tx,反之亦然。或者你已经这样做了?将其挂在12 V适配器电源上以确保电源不是问题。 (一个500毫安应该没问题。)

0

我使用蓝牙伴侣银与我的Arduino和以下链接是我用来管理我的蓝牙通信。

http://rxtx.qbang.org/wiki/index.php/Two_way_communcation_with_the_serial_port

我只好从这里进口RXTX库:

http://rxtx.qbang.org/wiki/index.php/Two_way_communcation_with_the_serial_port

也像其他用户所指出的,使用的115200波特率,并连接

蓝牙-RX line - > Arduino-TX line,以及

蓝牙-TX线 - > Arduino-RX线

第一个环节对我来说是一个重大突破。希望它可以帮助你。

1

我看到两个可能的问题。

首先可能出现的问题:

你拥有了它的有线或不对您所描述的接线错误的。通常情况下,您将蓝牙模块上的RX连接到Arduino上的TX,BT上的TX连接到Arduino上的RX上。

其次可能出现的问题:

您无法连接到蓝牙模块,然后使用内置串口监听程序来监视Arduino的串口。我不确定你的硬件,但通常你不能让它们都连接,因为它们是相同的串行端口。

断开Arduino与PC的连接。从其他来源加电Arduino。将PC连接到BT模块。在电脑上运行你最喜欢的TTY应用程序(tera term is nice)并连接到BT模块的COM端口并输入'H'。

让我知道你得到什么!