0

I would like to connect to my mindstorms nxt robot over bluetooth with java. Also keep in mind that I have lejos installed. Lejos includes classes to connect with the robot. Thank you so much I have spent weeks trying to figure this out and would really appreciate your help!

I would like my mac to initiate the connection.

Thank you post a comment if you don't understand what I am asking. Thank you!

The code running on the mac:

//package
package bluetoothtest;


//imports
import lejos.nxt.LCD;
import lejos.pc.comm.*;
import lejos.pc.*;


//main class
public class test {
//main method
public static void main(String[] args) throws Exception
{
//establish a connection...
NXTComm nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
NXTInfo nxtInfo = new NXTInfo(NXTCommFactory.BLUETOOTH, "NXT", "00:16:53:0B:9C:CA");
}
}

code on robot:

//package
package bluetoothrobottest;

//imports
import java.io.DataInputStream;
import java.io.DataOutputStream;
import lejos.nxt.comm.Bluetooth;
import lejos.nxt.comm.NXTConnection;

//main class
public class test {
//main method
public static void main(String[] args)
{
//wait for connection...
System.out.println("waiting for bluetooth connection...");
NXTConnection connection = Bluetooth.waitForConnection();
System.out.println("connected...");
//create streams
DataInputStream dis = connection.openDataInputStream();
DataOutputStream dos = connection.openDataOutputStream();
}
}

When I put this line of code in it gives me an error saying that the bluecove library isn't available:

nxtComm.open(nxtInfo,NXTComm.PACKET);
www139
  • 2,111
  • 3
  • 13
  • 8

2 Answers2

0

Simple google search returns this: http://www.lejos.org/nxt/nxj/tutorial/Communications/Communications.htm

I only used lejos for a bit, sorry I couldn't help more :(

vedi0boy
  • 1,030
  • 4
  • 11
  • 32
  • I've already seen that page I forgot to mention that I had trouble with it. I tried to piece together the code but it didn't work. I'll post the code that I used. – www139 Aug 09 '14 at 15:06
  • Like I said I can't help you too much more, I just have basic knowledge of this api for things like drawing to a screen or using motors and sensor, not much, sorry – vedi0boy Aug 09 '14 at 15:07
  • no problem. Kinda sucks that not many people use lejos, it's such a great api. That's one reason why I kind of gave up on it because its community is so small and support is hard to find – vedi0boy Aug 09 '14 at 15:18
  • Their site doesn't give a good tutorial. They should have full code examples! – www139 Aug 09 '14 at 20:57
0

If you look in the folder you get when you download lejos from http://www.lejos.org/nxj-downloads.php, you will see a .zip-file named "samples". Extract that and go to: "samples/pcsamples/src/org/lejos/pcsample/BTSend.java" for some test code for your pc and "samples/samples/src/org/lejos/sample/btreceive.java" for some test code for your NXT. Remember to pair the two devices before you run the code, otherwise nothing will happen (The nxt's default password is: 1234).

From what I remember the bluecove-library, which is used for this kind of communication, are no longer supported by Mac OS. Which makes it impossible to use bluetooth between a newer Mac and a NXT... But you can try it anyway.

USB might be an alternative, it works great.

rlh
  • 16
  • 1