You are on page 1of 5

Using NXC on Linux

Written by JCLarsen Thursday, 04 September 2008 10:17 - Last Updated Monday, 22 August 2011 09:46

When you want to use NXC on Linux, you can not use the BrixcCC. You will have to download a compiler, to compile the programming, and a communication tool for sending the programs to the NXT. This guide is describing the way of downloading the compiler and the comminication tool, and how to make it work on Ubuntu.

Installing the NBC compiler

The NBC compiler can be downloaded from the Bricxcc web site.

First we download the NBC compiler to the directory you wan't to install it to

$ wget http://downloads.sourceforge.net/bricxcc/nbc-1.2.1.r4.tgz

Now we unpack the downloaded NBC compiler

$ mkdir nbc

$ tar xzfnbc-1.2.1.r4.tgz-C nbc

$ cd nbc/NXT

We try out the downloaded compiler to see if it works

1/5

Using NXC on Linux


Written by JCLarsen Thursday, 04 September 2008 10:17 - Last Updated Monday, 22 August 2011 09:46

$ ./nbc

Next Byte Codes Compiler version 1.2 (1.2.1.r4, built Tue Mar 15 16:10:49 CDT 2011)

Copyright (c) 2006-2010, John Hansen

Use "nbc -help" for more information. You then move it to /usr/local/bin

$ sudo mv nbc /usr/local/bin/

Testing out the compiler


To se if the compiler works, open you favorit editor

$ nano hello.nxc

And write the following

task main() {

2/5

Using NXC on Linux


Written by JCLarsen Thursday, 04 September 2008 10:17 - Last Updated Monday, 22 August 2011 09:46

TextOut(0, 0, "Hello world!");

Wait(1000);

To compile the file do

$ nbc hello.nxc -O=hello.rxe -sm-

Hopefully you will only see the file "hello.rex" being created and no messages being printed in the terminal.

Setting up the communication to the NXT via USB cable


This part of the guide is inspired from: http://bricxcc.sourceforge.net/nbc/doc/nxtlinux.txt

Start by creating a group called: legonxt

$ sudo addgroup legonxt

Then add you use to that group

3/5

Using NXC on Linux


Written by JCLarsen Thursday, 04 September 2008 10:17 - Last Updated Monday, 22 August 2011 09:46

$ sudo adduser yourusername legonxt

Create a new file called 45-legonxt.rules in /etc/udev/rules.d, using your favorite editor

$sudo nano /etc/udev/rules.d/45-legonxt.rules

In this file youinsertthe following content: SUBSYSTEM=="usb_device", ACTION=="add", SYSFS{idVendor}=="0694", SYSFS{idProduct}=="0002", SYMLINK+="legonxt-%k", GROUP="legonxt", MODE="0660", RUN+="/etc/udev/legonxt.sh" You then create a file called legonxt.sh in /etc/udev, using your favorite editor

$sudo nano /etc/udev/legonxt.sh

In this file you insert the following centent: #!/bin/bash # GROUP=legonxt if [ "${ACTION}" = "add" ] && [ -f "${DEVICE}" ] then chmod o-rwx "${DEVICE}" chgrp "${GROUP}" "${DEVICE}" chmod g+rw "${DEVICE}" fi To make sure the script is executable run the following command

$ sudo chmod a+x /etc/udev/legonxt.sh This should do the trick. Now you have to reboot to make it work. Compiling

programming in one process

and

4/5

Using NXC on Linux


Written by JCLarsen Thursday, 04 September 2008 10:17 - Last Updated Monday, 22 August 2011 09:46

Now with everything in place and working is it now possible to compile and program the NXT in one process with the following command. In this example, the program that should be downloaded to the NXT brick is called hello.nxc.

$nbc hello.nxc -sm- -d -S=usb If you also would like to have the NXT brick to start the program after it have been downloaded the command are the following: $ nbc hello.nxc -sm- -r -S=usb

Documentation

Now this compiling and communication for the NXT is working (hopefully). To get into the programming I will recommend the following material: - The " Programming Lego Robots using NXC ", by Danny Benedettelli - A simple getting started guide. - The " NXC_Guide.pdf " - This is a really comprehensive guide that have all the details about NBC/NCX.

Examples
Follow the link(s) below to get some example code to get started with - Tutorial code by Danny Bennedettelli click her

5/5

You might also like