A brief primer on LEGO NXT Bluetooth
Author: Bob Sherbert
Keywords: LEGO, NXT, Bluetooth, Remote Control
The photos depict the physical components of a system created to deomonstrate the LEGO NXT system's bluetooh capabilities. The left picture is of the reciever unit and right of the controll unit. The bluetooth module allows the user to transmit up to 10 different variables between the two units using a 'mailbox' organizational scheme. This data can be either integer, text, or logical (boolean) data. This system's implementation helps to demonstrate transmission and reception concepts in both code and physical system. It also hopes to dmonstrate the importance of efficiecy in communication systems and a possible approach to informational organization. The tutorial should take 2-3 hours to complete.
Motivation and Audience
This documents serves as a quick introduction to the LEGO NXT Bluetooth communication system. I present a simple uni-directional, master/slave system which is packaged onto a simple car and controller pair. The tutorial aims to illistrate the concepts needed to implement Bluetooth within the NXT-G programming enviroment.
This tutorial assumes that the reader has the following skills/experience:
- Basic familiarity with the NXT programming enviroment (write/compile/download simple programs)
- Understanding of the different programming "blocks" within the NXT-G enviroment
- Ability to install "My Blocks"
- Basic knowldge of programming constructs (loops, functions, etc)
The rest of the tutorial is presented as follows:
Parts List and Sources
To complete this tutorial, you'll need the following items
TABLE 1: Parts required for construction
| PART DESCRIPTION |
VENDOR |
PART |
PRICE (2007) |
QTY |
| LEGO Mindstorms Education Base Set |
Lego Education |
W979797 |
$250.00 |
2 |
Construction
The following details step-by-step instructions for building the controller and receiver modules.
Step 1
The first step is to build the reciever unit. Instructions for building the simple two motor unit, called the tribot, can be found in the instruction book contained in the NXT Education kit. The design is detailed on pages 8-22 of the manual.
Step 2
The second step is to build the controller unit. Instructions for building the controller unit can be found here.
Step 3
Programming the two units is the next step. You can attempt to write you own code, or use that which is supplied on this page. To install the code below, copy the EncodeAngle and DecodeAngle files to your "MyBlocks" directory. Then compile the receiver and controller files and download them to their respective NXT units.
Step 4
To connect the two units together via Bluetooth follow these steps:
- Turn both units on, and make sure bluetooth is enabled on both, and that both are set to 'visible'.
- On the controller unit: navigate to Bluetooth -> Search
- A search diagram will appear on the screen, be patient while the search progresses.
- When the menu reappears select the reciever unit from the list. and then select connection slot #1.
- A connection screen will appear, again be patient.
- You will be prompted for a passkey on both units. Enter the same key on both and press enter to confirm. Leaving the default of 1234 is perfectly acceptable. Although you should be aware this is the kind of combination an idiot would put on his luggage.
- On the controller again select the option for the reciever
- At this point you should see the reciever unit displated with a small '1' in the upper left corner. Select it one last time and then back out to the main menu.
Step 5
Start the reciever program on the reciever unit, and the controller program on the controller unit. You should be good to go at this point.
Source Code
To be compiled in NXT-G Progamming Enviroment
Full code is available in the archive Nxt-Bluetoothcode.zip
controller.rbt
The controller program is a straightforward loop which reads the present positions of the two throtle sticks, converts the data to a single value using EncodeAngle and then transmits the data to the reciever using one mailbox for each of the two data pieces.
receiver.rbt
The reciever consists of three threads. Two secondary threads sit in loops and monitor the two mailboxes for any new data from the controller. When data is recieved the loops copy it to variables making the data available to a primary thread. The primary thread reads these variables, converts them back to the two piece data needed by the motor functions with DecodeAngle and then applies them to the motors.
EncodeAngle.rbt
The NXT unit stores motor encoder and command data as seperate sign and magnitude values. Sending two transmissions in order to convey all the data to the other unit is ineffiecet and confusing. This function combines the seperate sign and magnitude into a single signed number which can then be transmitted by the controller.
DecodeAngle.rbt
This function reverses the function of EncodeAngle so that the data can be used to drive the motors on the reciever unit.
Final Words
After completing this tutorial you should be able to implement basic I/O programming of the Bluetooth module on the LEGO NXT with the provided NXT-G programming language.
The author can be reached by email