Imifos versus the Lego NXT Mindstorm(tm)

I’m currently adapting the Sagan-1 Robot Simulator to work hand in hand with the Lego Mindstorm NXT robots. Since I didn’t read the doc (Hey, I’m a coder after all ;), I was expecting a huge brainstorm to make this happen, but actually *ehm* it was rather boring :-)

The Sagen-1 Project, as the Mindstrom, is supposed to be simple to use. So I base the integration on the first robot that the Lego introduction paper actually proposes to build: the “Get your 1st Robot in 30 Minutes” robot. I added an additional sensor to the front, to be a bit more preemptive concerning collisions and I added a push button allowing to  start the program easily on the playground.

The command line programming of Mindstorms is quite easy (providing you have installed the Lego USB driver). First download the latest version of the NXC release:

Actually, you just need the “nbc.exe” file (in case of Windows). The Bricx Command Center comes as handy bonus if you want to do more than just build NXC into the Mindstorm. There is as well a very convenient utility suite available on the web site.

Not eXactly C” (NXC) is a high level programming language similar to NQC (“Not Quite C“). It targets the new LEGO NXT product.  Like NQC, it is available for Windows, Mac OS X, and Linux platforms.  While NXC is not yet complete (sic), it is very functional, with a large API for the NXT.

So – having the “nbc.exe” ready and steady, write your first NXC:

int stopIt=0;

task main_prog() {  // -- this is a thread


   OnFwdSync(OUT_BC,50,100); // drive in circles
   Wait(5000);               // for 5 seconds

   stopIt=1; // let all threads exit gracefully


task check_sensors() {

   while(stopIt==0) {
      if (SensorUS(IN_1)‹=6) {  // crash alarm
         Off(OUT_BC);           // full stop
         stopIt=1;              // abort other threads.

task display() {

   TextOut(0,LCD_LINE1,"OUT_B Speed:");
   TextOut(0,LCD_LINE2,"OUT_C Speed:");
   while(stopIt==0) {

task main() {


   // wait for starting push button
   while(SENSOR_3 == 0) Wait(50);
   Wait(1500); // run away, as long as you can...

   // Start execution, display and monitoring threads
   Precedes(main_prog, check_sensors,display);

Now, connect the robot, wait for the USB *pling* and type:

nbc -r -S=usb myprogram.nxc

-S usb tells the tool to upload the program into the NXT after successful compilation and -r starts the program directly.

And, btw, don’t hesitate to buy John C. Hansen’s book! It’s absolutely worth every cent and gives great insides into the Mindstorm internals.

(Disclaimer: Lego and Lego Mindstorm Nxt are trademarks of the LEGO group).

2 thoughts on “Imifos versus the Lego NXT Mindstorm(tm)

    1. Hi Joachim,

      That’s for my 2nd NXT. For Sagan it’s important that the NXT hasn’t to be flashed.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.