Developing the LEGO MINDSTORMS NXT to a LogIT sensor adaptor using LabVIEW software
Creating an adaptor for the LEGO Mindstorms NXT controller that allows connection of the LogIT Microsense range of sensors to enable the use of robotics and data logging as supported by LEGO Mindstorms NXT.
LEGO Mindstorms NXT communicates with the LogIT NXT adapter via I2C commands. A microcontroller inside the adapter performs various functions depending on the commands received, what sensor has been plugged in to the adaptor, and what value is being measured.
Left: NXT shown with the LEGO NXT to LogIT sensor adaptor and humidity sensor.
The LabVIEW solution builds on the basic sensor template supplied within the LabVIEW Toolkit for LEGO Mindstorms NXT. The major changes in the sensor sub VI, Draw sensor VI, and Config sensor VI and the addition of various VIs enable the NXT to perform data logging. New VIs enable reading from the adaptor’s microcontroller and formatting the data to appear on the LEGO Mindstorms NXT LCD screen with suitable units and sensor description.
At this stage, the “Creating LEGO Mindstorms NXT Software Blocks” booklet and the “LabVIEW Toolkit for LEGO Mindstorms NXT Programming Guide” were extremely useful. These materials are available to download from National Instruments at www.ni.com/academic/mindstorms/.
Because we have previous experience using the LEGO RCX data brick, working with the new LEGO Mindstorms NXT was a natural progression. We conducted initial trials with the analog-to-digital lines used by the NXT. We quickly discovered that this could cause inaccuracies due to different reference voltages used by each system with the NXT using 0 to 5 V and DCPs Microsense system using 0 to 2.5 V.
Our solution used the I2C digital lines so the adaptor could reference 0 to 2.5 V and the NXT could simply request the values from the adaptor when required. After programming the adaptor’s microcontroller to respond to specific instructions, we constructed the sensor block in LabVIEW, meaning the user did not need to calibrate the sensors beforehand.
The sensor block templates supplied within the NXT graphical language were modified for use with the adaptor, but all compatibility with the LabVIEW Toolkit for LEGO Mindstorms NXT was retained, allowing full integration with other NXT sensor blocks.
We seamlessly integrated the data logging application in the LEGO Mindstorms NXT 2.0 software using LabVIEW, which gives educational establishments the opportunity to perform robotic investigations and data logging with one robot.
After choosing the basic format of the sensor block, we had to determine which outputs would be required by users to enable the highest level of flexibility and usability.
The Output Requirements for the Sensor Blocks
The first requirement from the sensor block was some form of “Formatted Text” output of the sensor data. This would enable the sensor identity, units, and value to be displayed on the NXT LCD screen without first having to convert the numeric values into text. We used a sub VI, which passes the sensor unit name, such as “Temp” for temperature; the units of measurements, such as “CO”; and the number of decimal points the sensor produces.
We have sensors that produce zero to four decimal points; therefore, the ability of the sub VI to handle a range of decimal points was important. In addition to displaying the sensor values, the sub VI is fed the range values for the sensor. This enables a suitable range error message to be displayed if the sensor data falls outside specifications.
The next requirement was for a simple numerical output of the sensor value to control the robots and use with the data logging part of the LEGO Mindstorms NXT program. After obtaining the data bits from the adaptor’s microcontroller, we performed a simple set of mathematical conversions (each will depend on the sensor that the block is designed for) and the numerical value output from the block to be used for comparison functions and form part of the NXT Boolean logic programming.
Even though our sensor adaptor has been designed to function with any of the Microsense range of sensors, the blocks are designed for specific sensors. This presented a challenge because if a temperature block is used with a humidity sensor, for example, then a range error is displayed, at best, or the wrong values are recorded, at worst. To provide a functional solution for the NXT user, a Boolean function was required to identify the plugged in sensor.
This function can also state if the correct answer is being used within the sensor block by quickly comparing within the LabVIEW code. This was achieved using the unique identity code, which all Microsense sensors have to identify themselves. This code is simply read using the microcontroller from the sensor and then a comparison with the known ID code performed in LabVIEW. A simple Boolean “SensorOK” logic indicator is subsequently used.
In addition to the Boolean sensor check, we implemented a simple numeric sensor ID, which outputs the unique numeric number of the sensor. Each block will have this ID number to indicate the sensor being used. Then, the user can implement this information for projects such as making the NXT emit a warning if the wrong sensor is plugged in. We hope this will be a useful feature in education to ensure students are using the correct sensor and block.
The additional I/O controls for the sensor block are standard NXT block requirements: the port number, trigger point, and greater/less/yes/no comparisons.