views:

1064

answers:

4

Does anyone know how to connect the DF Robot Bluetooth module up to the arduino and get it to communicate with the software?

I used this tutorial.

I managed to get the light flashing on the module and it seems to be able to pair fine but when I run the serial monitor and send a letter (say 'H') which should turn a light on I get a Java error:

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)

I checked the wiring and I have the RXD going to the RX (pin 0) on the board and TXD to TX(pin 1) and the rest wired up, but again still no luck. Anyone have any thoughts?

This is also the code I have on the 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
}
A: 

I've had similar troubles in establishing communication from PC to GSM Modem via serial port. I was first working with java.comm on vista and it was impossible. Later, I switched to RxTxComm and it was a lot more reliable. Use it instead.

hsilomedus
I am using the arduino IDE so i have no choice on what port connection it uses, also have looking it does use ...RXTXPort$SerialOutputStream.flush(RXTXPort...
Matthew De'Loughry
My bad. I went straight to the code and didn't see any RxTx like commands so I posted it. nvm.
hsilomedus
+1  A: 

Try to upgrade your RXTX library to the latest version. IIRC the Arduino IDE comes bundled with a version of it.

Omry
I've tried this and had no luck
Matthew De'Loughry
+1  A: 

This is a long shot, but...

The example in the linked tutorial uses a baud rate of 115200 (rather than the 9600 used in your example) and says:

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

It could be that either:

  • This only works with a baud rate of 115200 (which seems unlikely) or possibly
  • The baud rate on the master and slave is not 9600
Matthew Murdoch
Hi I have tried this however still no luck thanks for the help anyways
Matthew De'Loughry
Have you tried the simpler example code in the tutorial?
Matthew Murdoch
Yes, and nothing came through so I thought i'd try sending data then I can truley make sure
Matthew De'Loughry
+1  A: 

It's possible that a dodgy power supply to the Arduino/Bluetooth module could cause this error (i.e. it could be related to the error reported in this Arduino Forum Topic).

Matthew Murdoch
hmm yeah i suppose however how can i get it working a custom C# app but not the standard
Matthew De'Loughry
It may depend on if the .NET library and the gnu.io.RXTXPort code handle losing the connection differently (e.g. reestablishing the connection versus closing the associated file descriptor)?
Matthew Murdoch
after some investigation It seemed this was the case I tried another arduino and seemed to work fine thanks!
Matthew De'Loughry