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.

 

 

 

 

Home

NXT Robotics

Software

NXC Bluetooth library

 

Wrote in January, 2007

 

Daniele Benedettelli

 

 

 

 

 

 

NXT hardware technology is simply amazing, we already know.

But NXT-G, Lego-Labview graphical programming language

is not very handy, if you want to write complex large programs.

Among all the language choices available at the moment,

I would certainly prefer NXC (the high level son of NBC):

it is easy to learn, it offers full access to low level firmware routines,

it is OPEN SOURCE and free!

 

THIS LIBRARY IS NOW OBSOLETE, since newest NXC Beta versions

integrate all Bluetooth API functions.

 

 

 

 

  The routines that allow your robots to send and receive Bluetooth messages are quite tricky, since vary in the case your NXT acts as master or slave.

Also, the programmer must know the low level structure of NXT Communication protocol

and Direct Commands opcodes, mecanisms hidden inside NXT-G blocks.

Since NXC and NBC don't offer a simple interface to communicate, I decided to write and share this

user-friendly library.

 

 

 

 

To use this library, just include it at the top of your program like this: #include "NXCDefs.h"
#include "BTlib.nxc"

 

To check if the NXTs are connected, use this function, where CONN

is 0 on the slave side, 1,2 or 3 on the master side: it returns 0 if there's an error.

BTCommCheck(CONN);

 

To wait for a BT transaction to end, use this function, where CONN is defined as above

BTWait(CONN);

 

To send a string message, use this function specifying which connection to use, to which mailbox send data and the message itself. To send a number, first convert it to a string using NXC function s = NumToStr(n)

BTSendMessage(CONN,MAILBOX,MSG);

 

To receive a string message, use this function specifying which connection to use, from which mailbox pick data, if you want to clear remote message. The function returns the message into MSG.

MSG = BTReceiveMessage(CONN, MAILBOX, FLUSH);

 

You'll discover by yourselves how it is easy now to use Bluetooth with NXC!

 

I wish to thank Sivan Toledo for his NXT bluetooth page,

though I disagree on his idea that NXT BT protocol loses messages, it is not quite true, since using BTWait-like routines all works good.

Also, thanks to David Wallace, for his kind help on NBC.

Many many thanks go to John Hansen, whose work is priceless!

If you have any question, ask me!

 

     
   

 

Downloads:

 

NXC Bluetooth library for Mindstorms NXT

NXC Example files to learn how to use NXC BTlib