Disclaimer
This page is not connected with or endorsed by

The LEGO Company.

LEGO, LEGOLAND, LEGO SYSTEM, LEGO TECHNIC, DUPLO, LEGO PRIMO and LEGO MINDSTORMS are trademarks of The LEGO Company.  MATLAB is a trademark of MathWorks.

 

 

 

 

 

Home

NXT Robotics

 

MATLAB Bluetooth Router

 

16 January, 2009

 

Daniele Benedettelli

 

 

 

Ever wanted to automatically setup a Bluetooth network

with a master NXT and 3 slave NXTs?

Ever wanted to control these 3 NXTs from the powerful MATLAB environment,

regardless of your OS (Linux, Win, MAC)?

Well, this library is for you.

 

Requirements:

  4 (2 minimum) NXT bricks, the master attached to the computer via USB,

 the other 3 (1 minimum) slave NXT in a range of 10 meters from the master NXT.

  MATLAB running on a computer with RWTH - MINDSTORMS NXT Toolbox

 properly installed (see official page for download and instructions).

  NXT Fantom driver installed (for UNIX drivers, see this page)

  The programs are written in NXC,so you need BricxCC 3.3.7.19 (NBC Beta 35).

  All the NXT bricks should have John Hansen's enhanced firmware installed.

 

 

 

 In the provided archive you can find the files BTmaster.nxc, BTslave.nxc,

the library autoconnect.nxc (an updated version of the one from my book) and a really simple MATLAB script to test the whole thing out, BTmaster.m.

 

The slave programs are just demonstrative versions, they do anything but displaying incoming messages; you can customize them to make whatever you want, for example a team of remote controlled mobile robots.

 

The master program works as a router, forwarding the USB messages coming from the computer to the 3 slave BT connections. Sending a string message from computer to mailbox 0, the router NXT will forward it to BT slave 1, and similarly from mailbox 1 to slave 2, and from mailbox 2 to slave 3.

 

The MATLAB script just connects via USB to master NXT and starts sending string messages to the mailboxes 0, 1 and 2.

 

 

 

 

 

Getting Started

 

Update the firmware of all the NXTs downloading the John Hansen's firmware using BricxCC; without it, the Bluetooth autoconnection feature won't work.

 

To use the John Hansen's firmware Bluetooth autoconnection feature, the 4 NXT bricks must be introduced for the first time. To do this, connect them using the on-brick menu (check NXT manual for reference), so they exchange their passkeys and then are present in each other's contact list.

 

Rename the slave bricks with three different names,for example "SLAVE1", "SLAVE2" and "SLAVE3"; you can do this using my NXT Control Panel or the official LEGO NXT-G software. Then edit the BTmaster.nxc definitions at the top of the listing:

#define NXT_SLAVE1 "SLAVE1"
#define NXT_SLAVE2 "SLAVE2"
#define NXT_SLAVE3 "SLAVE3"

so that the defined strings match to the names you gave to the 3 slaves.

 

Download and run the BTslave.nxc program on every slave NXT. It will remain stuck waiting for the master to connect, displaying "Waiting router...". Download and run the BTmaster.nxc program on master NXT: it will automatically disconnect from any existing Bluetooth connection and connect the three named slaves to channels 1 2 and 3.

 

Once the master is connected to the slaves it display "Router online", and on the slave NXT screen will appear "Slave online". You can interrupt the master while it is connecting by pressing the orange button.

 

Now, just run the MATLAB script and the router should display the incoming messages, and on the slave NXT screens the forwarded messages.

 

Have fun!

I would be glad to know if you ever make and/or publish

something using this library.

 

 

     
   

 

Downloads:

 

 

NXC MATLAB Bluetooth Router for MINDSTORMS NXT (17KB)