NXT-G Coding & More

Lets talk about some of the basics of programming (or coding) using the NXT-G language with the Mindstorm products and also we will mention some other programming options that are available to you.

Now, the NXT-G programming environment will usually come on a CD with your retail NXT kit and once you install it on your computer you can begin to program.

Programming with NXT G involves moving some amount of the 35 graphical blocks onto the screen in a certain order to make your robot move or react to sensors or do motions over and over.

Once you assemble these blocks on the screen and adjust some of the blocks parameters with speed or direction etc, you would then send the program to your NXT brick using your USB cable.

Then you would disconnect your computer from the brick, and the brick would move the motors or access the sensors that are attached to it based on what your computer program told it to do.

This is basically the same way that you work with an arduino microcontroller. You program it on your computer using the Arduino software and then you copy the program you create called a sketch to your arduino microcontroller which has motors or sensors attached to it and then you run the program you created.

Here is a link to a great website that gives you programming projects that you can copy for your NXT or EV3 kit. http://www.NXTprograms.com

So once you install the NXT-G software you will see a menu on the side and bottom and a space in the center where you drag your programming blocks of motors , sensors and programming logic.

Programming is all about thinking logically where you put things in a certain order and then allow for changes that happen when a motor or sensor is added to the robot.

You start by thinking about your program first and then writing it all out on paper using simple english first which is called pseudocode in the programming business and then you go on the computer to start putting the blocks together on the screen to create the well thought out program.

Now you can of course program directly on the brick itself by pressing the keys on the brick itself but this is quite a bit more time consuming and not very intuitive.

Its not that easy to program directly on the brick since you are pushing small arrow buttons up and down and sideways to get your program in there etc so you should really start off by programming using the graphical NXT-G program on your computer.

The 3 main types of blocks found in NXT-G are called action blocks, flow blocks and my blocks.

You would choose blocks from the left menu which could either be basic common blocks or more advanced blocks.

The basic command blocks are commands like move, play sound, wait and loop.

There are also blocks for motors, actions and bluetooth and data manipulation.

You could select a motor block and then change its various paramters to make it move forward or change many times the motor will spin.

You could then try to do some actual programming by controlling the sequence of how things happen in your program.

You would use the blocks for program control like wait and loop.

You always begin a programming sequence with the Start block and then add blocks from there like the following action blocks:

  • move steering block
  • – sound block
  • display block
  • – brick status
  • – on and off
  • – move motors
  • – touch sensor
  • – color sensor
  • – infrared sensor
  • – brick button or rotation sensor
  • and then you could add to your programming knowledge by not just having things go in a direct sequence but by making things repeat or make a decision on what to do next:
  • – wait block
  • – loop block
  • – my block (create your own block)
  • You basically start dragging blocks on to the screen and modifying their built in parameters like in the case of a motor to how fast it will spin and in what direction and so on.

When you start using sensors then even more of the programming world opens up to you.

The ultrasonic sensor has two main ways to deal with checking its environment by either checking continuously or by checking now and again called pinging. You would specify this in your programming code later.

You can then get fancier by having several actions go on at once which is called multitasking and you can do that in two ways either you add two or more start actions or you attach a screen wire from one to another.

You could then get into learning about other programming concepts like variables , constants, input/output and more.

You could use the built in bluetooth to connect to up to 4 other bricks if you found a reason to.

You could later attach your brick to an arduino using something called a Bricktonics shield or use other specialty 3rd party specialty products like XBee wireless or Zigbee .

Once you are comfortable with programming with the visual technique and NXT-G you may want to use a language that will process your programming steps faster and more efficiently.

You can also use the more complicated language called NXC with the NXT brick and that code looks a lot like the C programming language.

You can download the NXC IDE (integrated development environment) and then write the code using NXC.

We could also talk about the wires that come with all Mindstorm kits and they are basically the same as a standard RJ11 telephone wire although the end of the wire has a slightly different bump on it so you can’t plug it into a phone jack by mistake.

Now the EV3 has a newer programming software environment but you can use it the same way that you use NXT-G by moving blocks of motors and sensors etc around the screen and copying the program back to your brick which would then move the motors and sensors that are attached to it.

You can download the EV3 app to your cellphone and control your EV3 robot or do some of the programming there by moving the blocks that represent motors and sensors around the screen.

Later when you start to work with a microcontroller like the Arduino you will see that the process is the same. You write the program called the Sketch on your computer which then copies the program to your arduino microcontroller which is attached to the computer with a USB cable. Of course the motors and sensors are attached to your arduino and once the program is copied over from the computer, you can disconnect the arduino and it is free to roam around the room or do whatever the program tells it to do.

Here are some other options to program your EV3 in C.

  • C# With Microsoft Robotics Developer Studio
  • Next Byte code
  • Not Exactly C
  • RoboLab
  • RoboMind

You can go onto our Video lessons section in the Fall 2021 where we will put some videos that actually show how to put together a program using the Mindstorm kits.