Christophe Nowicki

June 12, 2008

Build NXC programs under Debian GNU/Linux

This document explain how to build and load an Not eXactly C program for the Lego Mindstoms NXT Robot under Debian GNU/Linux.

Introduction

Lego does not provide tools for building programs for the NXT under Linux.
I don’t like Bricxcc, because :

  • It looks like Visual Studio ;
  • runs only on Microsoft Windows ;
  • I’m more familiar with VIM, make and GCC ;0)

Install the compiler

Ths NXC compiler can be downloaded on the Bricxcc web site. The compiler is writen in Pascal.

You need to install the FreePascal Compiler and build the compiler :


$ wget http://downloads.sourceforge.net/bricxcc/nbc-1.0.1.b34.src.tgz
# apt-get install fp-compiler fp-units-fcl fp-units-base
$ mkdir nbc
$ tar xzf nbc-1.0.1.b34.src.tgz -C nbc
$ cd nbc/nxt
$ make -f nbclinux.mak
$ ./nbc
Next Byte Codes Compiler version 1.0.1.b34 (1.0.1.34, built Thu Jun 12 21:21:22 CEST 2008)
Copyright (c) 2006, John Hansen
Use "nbc -help" for more information.
# mv nbc /usr/local/bin/

Hello world

Let’s try to build and send a simple hello world program to the robot :


$ cat > hello.nxc <

USB Transfert

In order to send the program to the robot, you need the Talk 2 NXT program : T2N.

Warning: on amd64, you need to patch the source code.


# apt-get install g++ libusb-dev
$ wget http://www-verimag.imag.fr/~raymond/edu/lego/t2n/t2n-0.2.src.tgz
$ wget https://csquad.org/wp-content/t2n_amd64.diff
$ cd t2n-0.2.src
$ patch -p1 < ../t2n_amd64.diff patching file src/usbmisc.cc patching file src/usbmisc.h $ make # mv obj/t2n /usr/local/bin/

Now you can plug, turn on your NXT and send the program via the USB port.


# t2n -i
#### NXT INFOS ###############
protocol version=1.124 firmware version=1.1
NXT Name: NXT
Blutooth address: 16:53:06:37:ffffffbc:00
Blutooth signal: 0
Free user flash: 44416
# t2n -v -put hello.rxe
nxt brick found, usb initialized
testing for existing file "hello.rxe"
deleting for existing file "hello.rxe"
upload hello.rxe (376 bytes) from /goinfre
that's all folks...

That’s all folks…

Filed under: Debian,Robotics — Tags:, , , — cscm @ 23:50

4 responses to “Build NXC programs under Debian GNU/Linux”

  1. Glen says:

    Thanks Christophe,
    Nice instructions. When I give the command:
    t2n -v -put hello.rxe

    I get the error:
    usbnxt: usbmisc: fails to set config, errno=-1 (cf=1 vendor=0x0694 product=0x0002)

    any suggestions?
    Thanks,
    Glen

  2. Scrool says:

    Glen: try to run it as root, eg.
    sudo t2n -v -put hello.rxe
    (type root password)

  3. Glen says:

    Thanks Christophe,
    It works fine!

  4. Ugilten says:

    Hi Christophe,

    Thanks for the instruction.

    I do, however, get a “stack smashing detected” that terminates t2n.
    The message is the following:
    ——————————————————————————-
    $ sudo t2n -i
    #### NXT INFOS ###############
    protocol version=1.124 firmware version=1.4
    NXT Name: NXT
    Blutooth address: 16:53:03:ffffffda:ffffffd8:00
    Blutooth signal: 0
    Free user flash: 53812
    *** stack smashing detected ***: t2n terminated
    ======= Backtrace: =========
    /lib/tls/i686/cmov/libc.so.6(__fortify_fail+0x48)[0xb7da2da8]
    /lib/tls/i686/cmov/libc.so.6(__fortify_fail+0x0)[0xb7da2d60]
    t2n[0x804bbec]
    t2n[0x8049324]
    /lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xe5)[0xb7cbb775]
    t2n[0x8049051]
    ======= Memory map: ========
    08048000-0804f000 r-xp 00000000 08:01 6586407 /usr/local/bin/t2n
    0804f000-08050000 r–p 00006000 08:01 6586407 /usr/local/bin/t2n
    08050000-08051000 rw-p 00007000 08:01 6586407 /usr/local/bin/t2n
    09db2000-09dd3000 rw-p 09db2000 00:00 0 [heap]
    b7ca4000-b7ca5000 rw-p b7ca4000 00:00 0
    b7ca5000-b7e01000 r-xp 00000000 08:01 5914628 /lib/tls/i686/cmov/libc-2.9.so
    b7e01000-b7e02000 —p 0015c000 08:01 5914628 /lib/tls/i686/cmov/libc-2.9.so
    b7e02000-b7e04000 r–p 0015c000 08:01 5914628 /lib/tls/i686/cmov/libc-2.9.so
    b7e04000-b7e05000 rw-p 0015e000 08:01 5914628 /lib/tls/i686/cmov/libc-2.9.so
    b7e05000-b7e08000 rw-p b7e05000 00:00 0
    b7e08000-b7e15000 r-xp 00000000 08:01 5890112 /lib/libgcc_s.so.1
    b7e15000-b7e16000 r–p 0000c000 08:01 5890112 /lib/libgcc_s.so.1
    b7e16000-b7e17000 rw-p 0000d000 08:01 5890112 /lib/libgcc_s.so.1
    b7e17000-b7e3b000 r-xp 00000000 08:01 5914632 /lib/tls/i686/cmov/libm-2.9.so
    b7e3b000-b7e3c000 r–p 00023000 08:01 5914632 /lib/tls/i686/cmov/libm-2.9.so
    b7e3c000-b7e3d000 rw-p 00024000 08:01 5914632 /lib/tls/i686/cmov/libm-2.9.so
    b7e3d000-b7e3e000 rw-p b7e3d000 00:00 0
    b7e3e000-b7f22000 r-xp 00000000 08:01 4269086 /usr/lib/libstdc++.so.6.0.10
    b7f22000-b7f26000 r–p 000e3000 08:01 4269086 /usr/lib/libstdc++.so.6.0.10
    b7f26000-b7f27000 rw-p 000e7000 08:01 4269086 /usr/lib/libstdc++.so.6.0.10
    b7f27000-b7f2d000 rw-p b7f27000 00:00 0
    b7f2d000-b7f33000 r-xp 00000000 08:01 5890124 /lib/libusb-0.1.so.4.4.4
    b7f33000-b7f34000 r–p 00005000 08:01 5890124 /lib/libusb-0.1.so.4.4.4
    b7f34000-b7f36000 rw-p 00006000 08:01 5890124 /lib/libusb-0.1.so.4.4.4
    b7f45000-b7f48000 rw-p b7f45000 00:00 0
    b7f48000-b7f49000 r-xp b7f48000 00:00 0 [vdso]
    b7f49000-b7f65000 r-xp 00000000 08:01 5890060 /lib/ld-2.9.so
    b7f65000-b7f66000 r–p 0001b000 08:01 5890060 /lib/ld-2.9.so
    b7f66000-b7f67000 rw-p 0001c000 08:01 5890060 /lib/ld-2.9.so
    bfc52000-bfc67000 rw-p bffeb000 00:00 0 [stack]
    Aborted
    ——————————————————————————-
    Any ideas on whats wrong???

    Ugilten

Powered by WordPress