Data transfer from NXJ to PC via Bluetooth

This is where you talk about the NXJ software itself, installation issues, and programming talk.

Moderators: 99jonathan, roger, imaqine

Data transfer from NXJ to PC via Bluetooth

Postby tehsumo » Tue Apr 24, 2012 3:55 pm

Hello,

I am currently working on a team project trying to create a robot that will traverse a maze and report any obstacles back to the pc and display a GUI for the user. We have tried for a few days trying to get the BT connection to work and we are stumped and have yet to get any successful code to work on the PC side.

Were running a sample code of this on the NXT:
Code: Select all
import java.io.*;
import lejos.nxt.*;
import lejos.nxt.comm.*;

/**
 * sample of selecting channel at run time
 */
public class CommTest
{
  public static void main(String[] args) {
    LCD.drawString("right BT",0, 0);
    NXTConnection connection = null;

    if(Button.waitForAnyPress() == Button.ID_RIGHT){
      LCD.drawString("waiting for BT", 0,1 );
      connection = Bluetooth.waitForConnection();
    } else {
      LCD.drawString("waiting for USB", 0,1 );
      connection = USB.waitForConnection();
    }

    DataOutputStream dataOut = connection.openDataOutputStream();
    try {
      dataOut.writeInt(1234);
    } catch (IOException e ) {
      System.out.println(" write error "+e);
    }
  }   
}


However when it comes to the PC code we haven't really found anything that we could use. We were trying to use something like this:
NXTComm nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
However it is not allowing us to compile anything with this line specificly. Some of the links I have read mentioned that you need to download a diffrent .jar file for the BT communication to work, but we aren't even at the baby steps. Can someone provide a link or some code or advice on how to actually connect the PC to the NXT and transfer some sample data?

On a side note is there a way to compile and run code in an ide for the pc side? (I tried eclipse but couldn't find a way to DL the plugin).

Thanks in advance!
tehsumo
New User
 
Posts: 4
Joined: Tue Apr 24, 2012 2:49 pm

Re: Data transfer from NXJ to PC via Bluetooth

Postby skoehler » Tue Apr 24, 2012 6:17 pm

NXT-side samples are in the samples folder, and PC-side samples are in the pcsamples folder. The latter should help you with getting started.
skoehler
leJOS Team Member
 
Posts: 1410
Joined: Thu Oct 30, 2008 4:54 pm

Re: Data transfer from NXJ to PC via Bluetooth

Postby tehsumo » Tue Apr 24, 2012 6:33 pm

Wow. I can't believe I overlooked that. Quick and potentially dumb questions:
//You need pccomm.jar and bluecove.jar on the CLASSPATH

Where would I get these two files, and more importantly what do I need to do with them? I am assuming that I will just need to have these in a certain directory... but so far my assumptions have yeilded no good results.

Then, how do I compile and run with with javac? Would it be something like
C:> javac example.java ?

also at the top of the samples it includes
package org.lejos.pcsample.btsend;

Can I just remove this so it compiles or will this cause an error?
tehsumo
New User
 
Posts: 4
Joined: Tue Apr 24, 2012 2:49 pm

Re: Data transfer from NXJ to PC via Bluetooth

Postby skoehler » Tue Apr 24, 2012 6:48 pm

Use the Eclipse plug-in to avoid the command line.

pccomm.jar and bluecove.jar are part of leJOS. You already have them on your computer.
Use the -cp argument of javac to add them to the classpath. You might also want to try nxjpcc and nxjpc to compile/launch programs. These scripts will call javac/java with the appropriate classpath.
skoehler
leJOS Team Member
 
Posts: 1410
Joined: Thu Oct 30, 2008 4:54 pm

Re: Data transfer from NXJ to PC via Bluetooth

Postby tehsumo » Tue Apr 24, 2012 7:01 pm

Awesome! I will try these ideas out tonight and let you know if I have any more questions, many thanks.
tehsumo
New User
 
Posts: 4
Joined: Tue Apr 24, 2012 2:49 pm

Re: Data transfer from NXJ to PC via Bluetooth

Postby tehsumo » Wed Apr 25, 2012 10:23 pm

This is the error I receive when I try to connect. I believe this is an issue with my Bluetooth Driver which is Broadcom... any suggestions to fix?

C:\...>nxjbrowse
leJOS NXJ> Searching for any NXT using Bluetooth inquiry
leJOS NXJ> Error: Search failed.
leJOS NXJ> Caused by lejos.pc.comm.NXTCommException: Bluetooth stack not detecte
d
leJOS NXJ> at lejos.pc.comm.NXTCommBluecove.search(NXTCommBluecove.java:54)

leJOS NXJ> Caused by javax.bluetooth.BluetoothStateException: BluetoothStack not
detected
leJOS NXJ> at com.intel.bluetooth.BlueCoveImpl.detectStack(BlueCoveImpl.jav
a:476)
leJOS NXJ> Failed to find any NXTs
tehsumo
New User
 
Posts: 4
Joined: Tue Apr 24, 2012 2:49 pm

Re: Data transfer from NXJ to PC via Bluetooth

Postby skoehler » Wed Apr 25, 2012 10:47 pm

Is the Bluetooth stick plugged in/turned on? Do you have the nice little Bluetooth icon in the start-menu bar? Which Bluetooth stack is installed? (WIDCOMM, Bluesoleil, Toshiba, Microsoft?)
skoehler
leJOS Team Member
 
Posts: 1410
Joined: Thu Oct 30, 2008 4:54 pm


Return to NXJ Software

Who is online

Users browsing this forum: Google [Bot] and 4 guests

more stuff