# Lego Mindstorms NXT

Lego Mindstorms NXT is a programmable robotics kit released by Lego on August 2, 2006. It replaced the Robotics Invention System, the first-generation Lego Mindstorms kit. The base kit ships in two versions: the retail version and the education base set. It comes with the NXT-G programming software or the optional LabVIEW for Lego Mindstorms. A variety of unofficial languages exist, such as NXC, NBC, leJOS NXJ, and RobotC. A second-generation set, Lego Mindstorms NXT 2.0, was released on August 1, 2009, with a color sensor and other upgrades. The third-generation EV3 was released in September 2013.

## NXT Intelligent Brick

The kit's main component is the NXT Intelligent Brick computer, which can accept input from up to four sensors and control up to three motors with a modified version of RJ12 cables (similar to, but incompatible with, RJ11 phone lines). The plastic pin to hold the cable in the socket is moved slightly to the right. The brick has a 100×64 pixel monochrome LCD and four buttons that can navigate a user interface with hierarchical menus. It has a 32-bit ARM7TDMI-core Atmel AT91SAM7S256 microcontroller with 256 KB of FLASH memory and 64 KB of RAM, an 8-bit Atmel AVR ATmega48 microcontroller, and Bluetooth support. The kit has a speaker, and can play sound files at sampling rates up to 8 kHz. Power is supplied by 6 AA batteries (1.5 V each) in the consumer version of the kit, and a rechargeable Li-Ion battery in the educational version. The brick is compatible with sensors and motors of its successor Lego Mindstorms EV3.

### Development kits

Lego has released open source firmware for the NXT Intelligent Brick and schematics for all hardware components.
Several developer kits are available with documentation for the NXT:
* Software Developer Kit (SDK), with information on host USB drivers, executable file format, and bytecode reference
* Hardware Developer Kit (HDK), with documentation and schematics for the NXT brick and sensors
* Bluetooth Developer Kit (BDK), documenting protocols used for Bluetooth communications

## Programming

Simple programs can be created using the menu on the NXT Intelligent Brick. More complicated programs and sound files can be downloaded with a USB port or Bluetooth. Files can be copied wirelessly between two NXT bricks, and some mobile phones can be used as a remote control. Up to three NXT bricks can communicate simultaneously via Bluetooth when user-created programs are run.
The kit's retail version includes software for writing programs that run on Windows and Mac OS personal computers. The software, based on National Instruments LabVIEW, provides a visual programming language for writing simple programs and downloading them to the NXT Brick; instead of requiring users to write lines of code, they can use flowchart-like blocks to design their program.

### NXT

    NXT-G v2.0 is a graphical programming environment that comes bundled with the NXT and can be used for real-world programming. The software can run a handful of parallel loops or blend autonomous control with Bluetooth or other remote control. It supports virtual instruments for all Lego and most third-party sensors and components. Version 2.0 contains new challenges, a remote control, custom graphics and sound designers, and Lego color sensor support.

### C# with Microsoft Robotics Developer Studio

    Free tools (Visual Studio Express in combination with the Robotics Developer Studio) enable programming the NXT using the C# language.

### BricxCC, Next Byte Codes, Not eXactly C

    Bricx Command Center (BricxCC) is the integrated development environment (IDE) used to write, compile, and edit NBC and NXC programs for the NXT. Also, as BricxCC was originally made for the RCX, programs for it can be written using NQC via BricxCC. Different firmware versions can be flashed to the NXT using BricxCC. Next Byte Codes (NBC) is a simple open source language with an assembly language syntax that can be used to program the NXT brick. BricxCC also has the capability to decompile standard .rxe NXT executables to NBC. Not eXactly C (NXC) is a high-level open source language, similar to C and built on the NBC compiler. It can be used to program the NXT brick. NXC is basically NQC for the NXT.

### Robolab

    The newer programming environment originally used on the RCX programmable brick. Version 2.9 has been updated to program the NXT brick. Lego has announced that it will stop supporting Robolab, but Robolab 2.9 is still available.

### RoboMind

    RoboMind is educational software to teach students about logic, programming and robotics. Scripts can be transferred to a Lego Mindstorms NXT robot for testing.

### Enchanting

    Enchanting brings NXT programming to the Scratch IDE, designed by the Lifelong Kindergarten Group at MIT to make programming intuitive for young children.

### ROBOTC

    A programming language based on C for VEX, the VEX Cortex, FIRST Tech Challenge, and Lego Mindstorms. ROBOTC allows the NXT to run programs quickly, and compresses files to accommodate a large number of programs.

### NXTGCC

    A GCC toolchain for programming NXT firmware in C.

### leJOS NXT

    leJOS NXJ is a high-level open source language based on Java that uses custom firmware.

### nxtOSEK

    nxtOSEK can be used to write in C and C++ with custom firmware.

### ICON

    ICON can write files on the NXT itself.

### MATLAB and Simulink

    MATLAB is a high-level programming language for numerical computing, data acquisition, and analysis. It can control Lego NXT robots over a Bluetooth serial port (serial port communication is part of the base functionality of MATLAB) or via USB. (free & open-source). Simulink is a block-diagram environment for modeling and simulating dynamic systems. A user can design and simulate control algorithms and Lego systems, and program the Lego NXT or EV3.

### Lua

    plLua is a port of the Lua programming language, a general-purpose scripting language, for Lego Mindstorms.

### Ada

    A port of GNAT for the NXT. It relies on a dedicated run-time kernel based on the Ravenscar profile used on the Goce satellite, allowing high-level Ada features to develop concurrent and real-time systems on the Mindstorms NXT.

### URBI

    URBI is a parallel, event-driven language with interfaces to C++/Java and Matlab. It has a component architecture (UObject) for distribution. Urbi is compatible with many robots, including Nao (cf Robocup), Bioloid and Aibo.

### FLL NXT Navigation

    FLL Nxt Navigation is an open source program to aid navigation on the FLL competition table. It uses NXT-G and .txt files to write programs.

### Ruby-nxt

    Ruby-nxt is a library to program the NXT for the Ruby programming language. The code is not compiled to a binary file (unlike other languages for the NXT), but is transmitted to the NXT via Bluetooth.

### Robotics.NXT

    Robotics.NXT is a Haskell interface to NXT over Bluetooth. It supports direct commands, messages and many sensors, and supports simple message-based control of an NXT brick via a remotely-executed program. Basic NXC code is included.

### LibNXT

    LibNXT is a utility library for talking to the Lego Mindstorms NXT intelligent brick at a relatively low level. It is targeted at platforms overlooked by official Lego Mindstorms NXT software (such as Linux), and works on any POSIX-compliant operating system where libusb 0.1 is supported. Windows support is also possible with libusb's win32 port.

### C_NXT

    C_NXT is a library for controlling the Lego NXT licensed under the GPLv2. It allows users to control a Lego NXT via Bluetooth from other C programs. The library, which runs on Linux, provides low-level control and high-level abstraction.

### PyNXC

    PyNXC is a project which converts Python code to Not Exactly C (NXC) to download to Lego Mindstorms robots.

### NXT-Python

    NXT-Python is a Python module which communicates with the NXT via USB or Bluetooth. It supports commands and several aftermarket sensors.

### LEGO Mindstorms EV3 Software

    The software which ships with the newer Mindstorms EV3 set can program the NXT.

### Physical Etoys

    A Lego NXT car which avoids walls, implemented in Physical Etoys Physical Etoys is a visual programming system for electronic devices which supports direct and compiled modes.

### C/C++ Interpreter Ch
## Sensors and actuators

The Lego Mindstorms NXT base kit includes:
* Three servo motors with built-in reduction gear assemblies and internal optical rotary encoders which sense their rotations within one degree of accuracy.
* A touch sensor detects whether it is pressed, has been bumped, or is released. The orange enter button and the gray right and left NXT buttons can be programmed as touch sensors. In the NXT-G programming software, a value of 0 is given when it is not pressed and a value of 1 is given if it is pressed.
* A light sensor detects the light level in one direction, and includes an LED for illuminating an object. It can sense reflected light values with the built-in red LED, or ambient light. In the NXT-G programming software, it senses light on a scale of 0 to 100; 100 is very bright, and 0 is dark. If calibrated, the sensor can be used as a distance sensor.
* A sound sensor measures volume on a scale of 0 to 100; 100 is very loud, and 0 is silent.
* An ultrasonic sensor can measure the distance from the sensor to something it is facing and detect movement. It can show distance in centimeters and inches. The maximum distance it can measure is 233 centimetres (92 in), with a precision of 3 centimetres (1.2 in). The sensor sends ultrasonic sound waves that bounce off an object ahead of it and then back, and senses the time it took.
Other parts may be bought separately. Third-party companies manufacture sensors such as a compass, gyroscope, infrared tracker, RFID reader and accelerometer sensors sold by Lego. The temperature sensor can measure in Celsius or Fahrenheit.

### Connector

Sensors are connected to the NXT brick with a six-position modular connector with analog and digital interfaces. The analog interface is backward-compatible (using an adapter) with the older Robotics Invention System. The digital interface is capable of I$^2$C and RS-485 communication.
NXT sensor interface pinout :
| Pin | Name | Function | Color |
| 1 | ANALOG | Analog interface, +9V supply | White |
| 2 | GND | Ground | Black |
| 3 | GND | Ground | Red |
| 4 | IPOWERA | +4.3V supply | Green |
| 5 | DIGIAI0 | I$^2$C clock (SCL), RS-485 B | Yellow |
| 6 | DIGIAI1 | I$^2$C data (SDA), RS-485 A | Blue |

## NXT 2.0

Lego Mindstorms NXT 2.0 is the second set in the Lego Mindstorms series, introduced on August 5, 2009, at the Lego Shop in the U.S. The set contains 619 pieces, including a sensor that can detect colors. It was followed by the Lego Mindstorms EV3.

### Features

* A sound editor for recording a sound and programming the NXT brick to play it.
* An image editor for downloading an image to the NXT brick to appear on the screen.

#### NXT intelligent brick

* 32-bit Atmel AT91SAM7S256 main microcontroller (256 KB flash memory, 64 KB RAM)
* 8-bit Atmel ATmega48 microcontroller @ 4 MHz (4 KB flash memory, 512 Bytes RAM)
* 100×64 pixel LCD screen
* Four RJ12 input ports (ports 1–4)
* Three RJ12 output ports (ports A-C)
* USB port
* Bluetooth Class II V2.0
* Loudspeaker – 8 kHz sound quality, 8-bit resolution, 2–16 kHz sample rate
* Four push buttons to navigate menus and use in programs
* Powered by six AA batteries or the NXT rechargeable battery