leJOS driver for NXTBee
leJOS driver for NXTBee
May 2012
Last updated 14 May, 2012
All content © 2008, 2009, 2010, 2011, 2012 Mark Crosbie mark@mastincrosbie.com
LEGO® is a trademark of the LEGO Group of companies which does not sponsor, authorize or endorse this site. This site, its owner and contents are in no way affiliated with or endorsed by the LEGO Group. For more please read the LEGO Fair Play policy.
I’ve written extensively about the Dexter Industries NXTBee sensor before. The NXTBee provides long-range serial wireless communication for the Lego Mindstorms NXT.
In my previous project I developed a RobotC type-packing library to send and receive basic data types between NXTs and PCs using the NXTBee.
This project presents a leJOS class to interface with the NXTBee, along with some sample Java code in leJOS showing how to send and receive data.
The NXTBee class wraps the serial interface to the NXTBee with high-level Java primitives. The class contains a thread that runs in the background to send and receive data to and from the NXTBee. The thread uses two circular byte buffers (one for sending, one for receiving data) to hold data until the caller is ready to process it. All of this detail is hidden behind a Java Input/Output Stream interface, which is the default Java interface for reading and writing data values.
The NXTBee class also provides a direct command control method that turns off the data reading thread and allows you to re-configure the NXTBee. For example, you can use this method to change the baud rate of the NXTBee, change the device address and so on.
The JavaDoc methods for the class is shown below.
You can download the class file, and I’ve also included three test programs to send and receive data, and to adjust the baud rate of the NXTBee. These classes are also in the latest SVN snapshot for leJOS.
•NXTBee.java - the core NXTBee driver class in the lejos.nxt.addon package.
•CircularByteBuffer.java - a circular byte buffer implementation from the Ostermiller java utilities.
•NXTBeeBaud.java - allows you to change the baud rate of the NXTBee sensor.
•NXTBeeSend.java - sends basic data over the NXTBee, with no error detection or checksum. You will need to build a type-packing library on top of this class.
•NXTBeeReceive.java - receive basic types sent by NXTBeeSend (or from another XBee device).