48

I'm curious to know if there is any way to program the NXT other than the provided software.

I don't necessarily have any issue with the software.

Does the program created by the software translate into an actual programming/scripting language? If so is that language proprietary to Lego or is it a common programming language?

1

7 Answers 7

24

The programming interface used by LEGO creates programs which make use of the standard firmware, that is, the one provided by LEGO.

If you look at alternatives (see also this answer for more information), you'll notice that quite a lot of them use the same firmware.

This means that the programs they produce use the same language which is interpreted by the standard firmware. One advantage is that you can have a mix of programs on the same NXT brick and it doesn't matter with what they've been originally written.

If you're interested to know more about the standard firmware and how to program it, you can download the Mindstorms Software Developer Kit. One of the interesting aspects of it is that you don't always need to create programs but you can send direct commands to the NXT as well - meaning you actual programming logic can sit on another connected device (PC, smartphone,...).

Others alternate languages use a different firwmare altogether, which means you can't mix languages at all. But if it uses a language you're more familiar with, it may be worth trying. (You can always revert to the standard firmware anyway.)

2
  • As an example of the programming logic running on another device, my nxt floppy-disk machine used Python on a laptop to control an NXT running the standard firmware.
    – retracile
    Aug 23, 2012 at 18:30
  • Not eXactly C is a good language to learn when transitioning from LEGO's NXT-G to text-based programming.
    – shea
    Nov 14, 2012 at 21:30
14

There are alternate text-based programming languages for the NXT. Three of the most popular ones are NXC/NBC, LeJOS NXJ, and RobotC. There are many more, all with their pros and cons, and are much more versatile than NXT-G, even on slow computers. I my personal favorite is NXC/NBC. But really it's up to you. The best way to see what suits your needs is to look at this table. It lists most of the pros and cons of the different programming languages. NOTE: it may be slightly out of date, but useful none the less.

9

Please help make this post better! This needs:

  • Clean up
  • Removal of irrelevant information plagiarized from copied off Wikipedia
  • Links
  • [Possibly] Pictures or Code samples


NXT-G

  • Graphical programming environment
    • Uses Blocks
    • Based on LabView
    • Parallel "sequence beams" are actually parallel threads
  • Comes bundled with the NXT
  • The language supports virtual instruments for all LEGO branded and most 3rd party sensors/components.
  • Community support is significant, for example, Brickshelf.

Enchanting

  • Graphical programming environment
    • Based on MIT's Scratch
    • Drag and drop
  • Based on LeJOS VM.
  • Fast.

Robotary / Swift

  • Mac IDE and robotics studio based on the Swift programming language
  • IDE features
    • context-aware code completions
    • syntax highlighting
    • LLDB-based debugger
    • visual debug gauges
    • built-in documentation viewer
    • various examples
    • Bluetooth and USB support

HELP!

The following section needs serious editing!


C# with Microsoft Robotics Developer Studio

  • Free tools Visual Studio Express and the Robotics Developer Studio allow you to program using the C# language.
  • Sample Project on coding4fun
  • Other languages are supported as well, including IronPython and VB.NET

BricxCC, Next Byte Codes, Not eXactly C


Bricx Command Center (BricxCC)

  • IDE used to write, compile, and edit NBC and NXC programs for the NXT.
  • Can flash different firmwares to NXT.
  • BricxCC has many utilities, such as:
    • NeXTExplorer (upload/download files, defragment the NXT, use file hex viewer)
    • NeXTScreen (view what's on the NXT's LCD display, and capture images and video)

Next Byte Codes (NBC)

  • Open Source
  • Assembly language syntax
  • BricxCC can decompile standard NXT executables (.rxe) to NBC

Not eXactly C (NXC)

  • Open Source.
  • Text based language.
  • Based on C.
  • Uses NBC as assembly language.
  • One of the most popular third-party programming languages for the NXT.

Robolab

  • Older programming environment; originally used for RCX bricks.
  • Version 2.9 has been updated so that it can be used to program the NXT brick
  • Lego has announced that it will stop officially supporting Robolab but Robolab 2.9 is still available and there are still many user forums and other sources of help available.

ROBOTC

  • Developed by the Carnegie Mellon Robotic's Academy
  • Based on C
  • Used on VEX, VEX Cortex, FIRST Tech Challenge, and Lego Mindstorms NXT.
  • Custom firmware for very fast program execution.
  • Compresses files to increase available space.

NXTGCC

  • GCC toolchain.
  • For programming the NXT firmware in C

leJOS NXJ

  • High level language
  • Open source
  • Based on Java
  • Uses custom firmware

nxtOSEK

  • C/C++
  • Requires custom firmware

ICON

  • To write files on the NXT itself

MATLAB and Simulink

MATLAB

  • High-level programming language.
  • For numerical computing, data acquisition and analysis.
  • It can be used to control LEGO NXT robots over a Bluetooth serial port (serial port communication is part of the base functionality of MATLAB) or via a USB connection; for example using the free and open source RWTH - Mindstorms NXT Toolbox.

Simulink

  • MATLAB-based environment for modeling and simulating dynamic systems.
  • Using Simulink, a user can design control algorithms, automatically generate C code for those algorithms, and download the compiled code onto the LEGO NXT.

MATLAB and Simulink code for LEGO MINDSTORMS NXT programming is freely available.


Lua

  • Port of the Lua
  • General purpose scripting language

Ada

  • A [http://libre.adacore.com/libre/tools/mindstorms/ port of GNAT] is available for the NXT. It relies on a dedicated run-time kernel based on the [[Ravenscar profile]], the same used on the [[Goce satellite]]: this permits to use high-level Ada features to develop concurrent and real-time systems on the MINDSTORMS NXT.

URBI

  • [[URBI]] is yet another language and is a parallel and event-driven language, with interfaces to C++/Java and Matlab. It also has a component architecture (UObject) for distribution. Urbi is compatible with many robots, including Nao (cf Robocup), Bioloid or Aibo.[http://www.gostai.com/nxt URBI NXT Page]

FLL NXT Navigation

ruby-nxt

  • Library to program the NXT for the Ruby programming language.
  • Code is not compiled to a binary file; it is directly transmitted to the NXT via a Bluetooth connection.

Robotics.NXT

  • Haskellinterface to NXT over Bluetoooth.
  • Supports direct commands, messages and many sensors (also unofficial).
  • It has also support for a simple message-based control of a NXT brick via remotely executed program (basic NXC code included).

LibNXT

  • utility library for talking to the LEGO Mindstorms NXT intelligent brick at a relatively low level.
  • is targeted mainly at the platforms that the official Lego Minstorms NXT software overlooks, namely Linux and other unices.
  • It will work on any POSIX-compliant operating system where libusb 0.1 http://libusb.sf.net/ is supported.
  • Windows support is also possible with the win32 port of libusb.

PyNXC

  • Translates Python code into NXC (see above) code, to compile and download to LEGO MINDSTORMS Robots.

(Some content from Wikipedia. Licensed under CC-Wiki, obviously.)

6

You can program the raw hardware:

The main microcontroller in the NXT is an Atmel AT91SAM7S256 (data sheet), which uses the ARM7TDMI core from ARM. This core is supported by gcc, so you can use GNU tools to program it in Assembly/C/C++.

You can build a firmware for the AT91SAM7S256 and load it via USB, after putting the controller in SAM-BA mode by a long press on the reset button.

There is also a smaller ATmega48 controller in the NXT, but it is not intended to be reprogrammed.

LEGO provides a Hardware Developer Kit among their support files. It contains schematics and descriptions of the sensors and motors, so that you know how the microcontroller is connected to the NXTs ports.

4

I started coding using NXT software and later EV3 and lately I have switched to java using leJOS. EV3 software ( and NXT ) is great for quickly hacking your ideas but when things get ugly the graphical language doesn't help at all.

Just watch what I needed to do to create a playable version of Pong for one player at http://thetechnicgear.com/2014/03/playable-pong-lego-mindstorms-ev3/

2

You can program the lego NXT in any language you wish! What is really the question is if you want the mindstorms brick to perform the decision making, or if you want some other device to do that for you. This works in two ways:

You download a program onto the NXT that it can run in its native format. Based on sensor input and the program which you've written, the NXT can operate by itself. This is how the mindstorms modules are primarely designed to operate out of the box - where you use their "visual" programming interface to create a program and then download it to the NXT.

As listed above, there are various other types of programming languages and interfaces you can use to write programs for the NXT. Eventually they require you to download them to the NXT - which will again be performing all the necessary calculations to run the program on-bard of the brick. These tend to offer you more control over your program however ultimately rely on the computing power available on the NXT.

The second scenario is to use the NXT as sort of a "slave" to another device with more computing power. This device - such as a PC or MAC, can be used to send down real-time direct commands to the NXT device to operate on. Based on feedback transfered back to the host computer, you can send down other commands. Using this method, you can use any programming language you are comfortable with - and simply use the NXT as a "dumb" device. This offers you the most verstility, and you can use virtually any programming language you are comfortable with.

What's nice about the NXT is that it allows you to use such a wide array of different techniques to control it - which makes it a great platform. One great walk-through of sending these direct commands over bluetooth to the NXT can be found here: http://www.robotappstore.com/Knowledge-Base/Programming-LEGO-NXT-Mindstorms/92.html I would recomend checking it out, since its a great introduction to getting started. If your computer supports bluetooth, you can easily download realterm (free) and get your robotic project working quickly!

I will admit that sending these direct commands to the NXT is a bit more advanced than say the type of visual programming used with the supplied Lego software, but it will allow you to use any language you wish, and with slight modification you can use your code for un-related projects too!

Hope this helps! -Ryan

2

You can use a python module called NXT-Python. If you know how to use python it will be very useful tool.

You can find it on GitHub. You can also use the package manager on some Linux distributions:

apt install python-nxt

Here you have some tutorials:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.