6

I am trying to perform serial communication on between Ubuntu 12.04 and a JY-MCU bluetooth serial module connected to an Arduino.

I have created this configuration in /etc/bluetooth/rfcomm.conf

rfcomm0 {
#   # Automatically bind the device at startup
    bind yes;
#
#   # Bluetooth address of the device    
    device 00:12:11:19:08:54
#   # RFCOMM channel for the connection
    channel 1;
#   # Description of the connection
    comment "Linvor Bluetooth Module";
}

I can use putty to communicate with the /dev/rfcomm0 serial port and this works perfectly.

However, despite many attempts I simply cannot see how to create a serial port in Processing that works in any way.

For example :

println(Serial.list());

prints nothing at all.

If I execute:

String portName = "/dev/rfcomm0";
myPort = new Serial(this, portName, 9600);
println(myPort);

I see this in the monitor:

processing.serial.Serial@1712651

But if I then call:

 myPort.write('9');

I get an exception:

java.lang.NullPointerException
    at processing.serial.Serial.write(Serial.java:572)
    ...

I can't understand why this fails. I have been following all the instructions from Tom Igoe's "Making Things Talk", but this just does not work the way he says...

Any help would b great!

Thanks,

Bob

4
  • Can you debug if myPort is really created? Maybe something inside myPort is null and giving the exception when you want to write something. Also, try to use a terminal on both sides, so you know the connection is set up right. On the arduino side, you could use another linux device if you have that available. Mar 18, 2013 at 9:48
  • I am really ignorant in processing... I can communicate with the arduino if I write a routine in python or via putty, but just in processing, which is my goal... Mar 19, 2013 at 16:31
  • Seems to be a processing isue then, Iḿ not familiar with that, sadly. You need sudo/admin rights? I guess it would error earlier if you did. Mar 20, 2013 at 8:08
  • I tired that but Sudo/admin rights made no difference... There doesn't seem to be anybody out there who knows about this. I even wrote to Tom Igoe, because his book gives incorrect instructions regarding serial via rfcomm... Mar 20, 2013 at 12:02

2 Answers 2

9

Aftert searching high and low, I have made this work.

The key issue is that processing uses the rxtx java library (RXTX-2.1-7) for serial communications.

The RXTX wiki says:

"rxtx tries to detect ports on by scanning /dev for files matching any of a set of known-good prefixes, such as 'ttyS', 'ttym', and since 2.2 'ttyUSB' and so on. "

And since the bluetooth device is named rfcomm* it cannot be detected.

The trick is to create a sym link to fool rxtx (use a ttyS device that is not yet assigned):

$ sudo ln -s  /dev/rfcomm0 /dev/ttyS99

Then, connect:

$ sudo rfcomm connect 0
 Connected /dev/rfcomm0 to 00:12:11:19:08:54 on channel 1
 Press CTRL-C for hangup

At this point the red led on the JY-MCU becomes solid and processing can detect it:

println(Serial.list());

output is:

[0] "/dev/ttyACM0" 
[1] "/dev/ttyS99"

So, serial communication can work.

To summarize, the following process will allow a processing script to communicate via a serial port with a JY-MCU device in a BlueZ linux framework

One time setup:

  1. power up the JY-MCU,

  2. use the following command to get its hardware address, mine is 00:12:11:19:08:54

    $ hcitool scan  
    
  3. use that to create the /etc/bluetooth/rfcomm.conf file; you'll note that I chose 0 for the rfcomm device , we need that for connection later:

    $ cat /etc/bluetooth/rfcomm.conf
    rfcomm0 {
        bind yes;
        device 00:12:11:19:08:54;
        channel    1;
        comment "Linvor Bluetooth Module";
    }
    
  4. use BlueMan to pair the JY-MCU.

Every time you want to use the JY-MCU

  1. create the sym link:

    $ sudo ln -s  /dev/rfcomm0 /dev/ttyS99
    
  2. connect to the JY-MCU:

    $ sudo rfcomm connect 0
      Connected /dev/rfcomm0 to 00:12:11:19:08:54 on channel 1
      Press CTRL-C for hangup
    
  3. you can now run a processing script and connect to the JY-MCU with the code:

    String portName = "/dev/ttyS99";
    myPort = new Serial(this, portName, 9600);
    
  4. after running the processing script, be sure to CTRL-C at the command line to disconnect the JY-MCU.

That should do it! Ciao, Bob

1
  • Thanks, I've followed your steps. I'm able to run the Processing sketch once, then the communication is lost and every time I re-run the program, i gives Port Busy exception. Any advice?
    – UserK
    Aug 20, 2015 at 19:58
0

Just something popped up in my mind. I had similar problems that were caused due to channel 1 is already used. If you bind to a channel which already is in use, bad things may happen.

sdptool browse local

Use that command to see which channels are available on your Ubuntu device.

1
  • Thanks, but that still doesn't help. I can see the rfcomm0 device from Putty, or via the python bluethooth bluez package, but not from processing... I'm pretty sure it's my own ignorance, but see no way forward... Mar 19, 2013 at 16:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.