node package manager


Mindstorms BlueTooth

Mindstorms bluetooth is a nodejs module to communicate with your mindstorm brick using the direct api over bluetooth.

How to install:

npm install mindstorms_bluetooth

How to use:

First setup your Lego Mindstoms NXT brick. It will create a serial port, get that name. On Mac OS X is it on the form: /dev/tty.NXT-DevB, or at least on my mac is it so.

Require it, initialize and use.

var Nxt = require('mindstorms_bluetooth');
var nxt = new Nxt("/dev/tty.NXT-DevB");
nxt.play_tone(440, 1000);


Please see the nxt.js for now. I will create a better api documentation soon.

Linux settings


For ubuntu and other recent linux distributions here is a new procedure that I recommend using to configure your Linux box for use with the NXT:

  1. Add a legonxt group. From a terminal prompt type
sudo addgroup legonxt
  1. Add your account to the legonxt group. From a terminal prompt type
sudo adduser YourUserName legonxt
  1. Create a file called 45-legonxt.rules using your favorite text editor. Its contents should look like this:
# NXT brick 
SUBSYSTEM=="usb", ATTRS{idVendor}=="0694", ATTRS{idProduct}=="0002", SYMLINK+="legonxt-%k", GROUP="legonxt", MODE="0666"
# NXT brick in firmware update mode (Atmel SAM-BA mode)
SUBSYSTEM=="usb", ATTRS{idVendor}=="03eb", ATTRS{idProduct}=="6124", SYMLINK+="legonxt-%k", GROUP="legonxt", MODE="0666"
  1. Copy this file to /etc/udev/rules.d. From a terminal prompt type
sudo cp 45-legonxt.rules /etc/udev/rules.d
  1. That should be all you need to do (aside from reboot) to make sure that your NXT will always be accessible via USB for any user who is a member of the legonxt group. Whenever you plug in your NXT it should show up in /dev as

where x and y depend on which USB port you plug the NXT into. On my laptop which has 4 USB ports I get 1-1, 1-2, 2-1, and 2-2 depending on which port I plug into. There will be other entries such as /dev/legonxt-usbdevx.y where y increments but you should be able to use the above device alias without any problems.

  1. That should take care of USB support. Now let's work on Bluetooth support.

  2. The procedure below is described by Tony Buser here:

  3. You may need to install bluetooth support using apt-get. If hcitool doesn't work then from a terminal prompt type

sudo apt-get install bluetooth
  1. Get your NXT's bluetooth address using hcitool. From a terminal prompt type
sudo hcitool scan
  1. Edit a file called /etc/bluetooth/rfcomm.conf using your favorite text editor. Add an entry for your NXT that looks like this:
rfcomm0 {
    # Automatically bind the device at startup
    bind yes;
    # Bluetooth address of the device
    device 00:16:53:FF:01:56;
    # RFCOMM channel for the connection
    channel 1;
    # Description of the connection
    comment "JCH2";

Make sure you enter your NXT's bluetooth address as shown by the hcitool scan. If you have more than one NXT you can create additional entries in this file with incremental rfcomm names (e.g., rfcomm1, rfcomm2, etc...).

  1. Now restart your bluetooth services. From a terminal prompt type
sudo /etc/init.d/bluetooth restart

You may have to use /etc/init.d/bluez-utils restart but on my ubuntu system it uses bluetooth instead.

  1. Make sure rfcomm is working properly. From a terminal prompt type

You should see

rfcomm0: 00:16:53:FF:01:56 channel 1 clean

with your NXT's bluetooth address instead, of course.

  1. Make sure the device shows up in /dev and that you have permission to read/write to it. On my system it shows it associated with the dialout group and my user account is in the dialout group as shown below. Make sure yours looks similar.
john@john-laptop:~/Desktop$ ls -l /dev/rfcomm0
crw-rw---- 1 root dialout 216, 0 2008-04-02 20:52 /dev/rfcomm0
john@john-laptop:~/Desktop$ groups
users adm dialout cdrom floppy audio dip video plugdev scanner lpadmin admin netdev powerdev legonxt
  1. As Tony mentions, the first time you try to connect to /dev/rfcomm0 you should be prompted on your PC and your NXT to enter or accept the PIN number. Use 1234. Once that has been exchanged once you should not have to do that again.

In other utilities you should be able to use /dev/legonxt-x-y or /dev/rfcomm0 to communicate with your NXT by USB or Bluetooth respectively.

Bigger example