Lua on LEGO Mindstorm NXT 2

Posted by Tom Thu, 05 Jun 2008 22:39:00 GMT

Wow! It’s been a long time since I wrote here, but in the mean time cool things have happened. Firstly there’s pbLua, secondly I bought myself a Lua book.

So, how now do you go about to install pbLua on your NXT? If you’re using Windows, there’s not really an issue, because that’s all explained on the homepage. I’m using a Mac, so here it is.

Setup

1) First download pbLua, I’ve got a ‘nxt-lua-beta-15b’ folder on my Desktop.

2) Start up LEGO’s MINDSTORMS NXT

3) Use the Tools menu and use the “Update NXT Firmware…” option, click “Browse” and navigate using the browser to the folder ‘nxt-lua-beta-15b’ on your Desktop. The window should show “nxt-lua” as “Available Firmware Files”.

4) Now connect your NXT, click “Download” and wait ….

5) If everything is correct, your NXT screen should show “pbLua Beta 15b”, the 15b depends on the version you downloaded.

Okay now what?

Now you’ve got a Lua-enabled NXT, but it’s not very clear how to continue further. Luckily it says somewhere on the homepage that there’s a USB Console as well as a BT (BlueTooth) Console. Let’s start with the USB Console.

1) Fire up Terminal.app

2) Do an ls /dev/tty.usb*, in my case this shows a /dev/tty.usbmodem1a21, but your results may vary.

3) Then do a screen /dev/tty.usbmodem1a21, this should refresh your screen and show you:
pbLua Beta 15b
> 

You’re now in a Lua interpreter, type print("Hello World!"), just for the kicks of it!

Basically you can now use the pbLua API, to do anything you want, try nxt.SoundTone() for example, woohoo isn’t that great?!

4) To quit the Console type Ctrl-a Ctrl-\.

Enabling Bluetooth

1) Basically you go about as you would connect any other Bluetooth device to your Mac, just select “Any Device”, find the NXT in the list of Devices and have the “Use a specific passkey” option selected for the Passkey Options.

2) During “Gathering information about your device” and while it’s connecting, Mac OSX will ask you for a passkey, think of something, then go to your USB console and use the Lua function nxt.BtSetPIN('something') (on your USB console) to confirm the bluetooth-passkey from your NXT end. At some point Mac OSX will say “Connected”. Remember the device name!

Bluetooth Console

1) Reboot your NXT (by holding the grey button for some time) and start it again by clicking the orange button. Then you should see something like:

USB Console
BT Console
. 
. 
. 
. 
. 
. 
00000 Button:0

Then use the dark grey button, to highlight BT Console, next use the arrow buttons to find the device name of your computer (which in my case is ‘galactica’).

USB Console
BT Console
. 
.
galactica
AD:000000000000
CL:000000
ST:00 Idx: 00 
00000 Button:0

Once you’ve got this selected, the screen should show:

Wait for connect
Active: 00
Update:  0 
.
.
.
.
.
.

2) Fire up Terminal.app

3) Do an ls /dev/cu.<bluetooth-device-name>*, in my case my NXT is called “r2d2” (yup!). So I did a ls /dev/cu.r2d2*, this shows a /dev/cu.r2d2-DevB-1, but your results may vary, depending on your device name.

3) Then do a screen /dev/cu.r2d2-DevB-1 (or whatever you found at step 2), this should refresh your screen and show you:
pbLua Beta 15b
> 

Woohoo, wireless pbLua!!

More to follow, later, keep you posted – check back!

Cross-compile Ruby to ARM7 2228

Posted by Tom Sun, 14 Jan 2007 13:28:59 GMT

Okay, I had another go at cross-compiling Ruby to ARM7, which for me (a cross-compile newbee) is not very simple.

I found this site of Jürgen Stuber which helps a little, but just running ./configure --host powerpc-apple-darwin8.8.0 --target=arm-elf does not seem to do the trick. I also found this page by Richard Keene which also points me in the right direction.

Well you will know my intention: Getting Ruby to compile for running the Lego NXT brick. We’ll probably don’t need socket, curses and libruby (maybe more), which will safe a lot of space. The next thing is to find out how small we can actually make the interpreter.

So does anyone have any tips, can somebody help me out? Is somebody willing to help? I’m aiming to create a Ruby interpreter, which will run on the LEGO NXT device, which will load zipped .rb files and run’s them.

Java OS for LEGO NXT 13959

Posted by Tom Sun, 14 Jan 2007 12:19:34 GMT

They’ve done it! Just like for the RCX there is now Java for the NXT: leJOS is a firmware replacement for the NXT device. It currently does not have bluetooth, sound and I2C support. There is also no menu system (yet!). But you can upload Java programs via USB and have your but execute them. Excellent!

But as you know I’m a big Ruby fan, so if only it was Ruby instead of Java … :) Also, how can you fit a Ruby interpreter on 256 Kbytes FLASH & 64 Kbytes RAM. I know there is already ruby for 32-bit ARM7 microcontrollers so …

Drag & Drop NBC/NXC to RXE 1018

Posted by Tom Wed, 10 Jan 2007 21:02:44 GMT

Yesterday, I’ve put together Dropnbc2rxe, with the help of DropScript. If you put Dropnbc2rxe in your Applications folder (it NEEDS to be there, due to hardcoded paths). Then if you would drop .nbc or .nxc files onto the application, it will compile them to .rxe files, to be put on your LEGO NXT device. Dropnbc2rxe can be downloaded here. It has nbc 1.0.1.b20 bundled with it, no need to download that separate.

Ruby & Mindstorms NXT 21955

Posted by Tom Sat, 14 Oct 2006 09:29:00 GMT

Using Ruby with your Mindstorms NXT is easy using RubyNXT. But it still requires a bluetooth connection or USB connection.

How cool would it be if it was possible to write a Ruby program, upload it (in sourcecode) to your NXT brick and have a Ruby interpreter firmware running on the NXT? It wouldn’t be needed to port the whole Ruby Standard Library, it wouldn’t even be needed to convert the whole Ruby Core Library.

So what would be needed to get this to work? Cross-compilation of Ruby to ARM, someone already ported Ruby to his Zaurus. A new firmare is needed.

Maybe better yet is the use of a Ruby VM like YARV and get that to run on the Mindstorms brick. Still, that needs to be cross compiled and a new firmware is needed.

Ruby is a fully object oriented programming language and is fairly easy to learn, even easier to use. More and more programmers learn Ruby.

LibNxt on Mac OSX 770

Posted by Tom Thu, 12 Oct 2006 17:40:00 GMT

Earlier I came across LibNxt, a project by David Anderson (one of the MDP’s). As I’m a Mac OSX user I tried to find out whether I could get fwflash to run on OSX, well: IT DID! What follows is a HOWTO.

Actually it’s pretty easy if you have MacPorts installed:

Just do the following, it will all install neatly in /opt/local/:
sudo port install arm-elf-gcc
sudo port install scons
sudo port install libusb

If you’ve downloaded LibNXT somewhere follow the instructions upto typing scons, we need to change the SConstruct file to this:

from glob import glob

auto_libs = ''

# Detect the system's endianness
from sys import byteorder
if byteorder == 'big':
    endian = '_NXT_BIG_ENDIAN'
else:
    endian = '_NXT_LITTLE_ENDIAN'

BuildEnv = Environment(CCFLAGS=['-I/opt/local/include', '-Wall', '-std=gnu99',
                '-g', '-ggdb', '-D' + endian])
if auto_libs:
    BuildEnv.ParseConfig('pkg-config --cflags --libs ' + auto_libs)

BuildEnv.Command('flash_routine.h',
         ['flash_routine.h.base',
          'flash_write/flash.bin'],
         './make_flash_header.py')

Default(BuildEnv.Library('nxt',
             [x for x in glob('*.c')
              if not x.startswith('main_')],
             LIBS='usb'))

Default(BuildEnv.Program('fwflash', glob('main_fwflash.c'),
             LIBS=['usb', 'nxt'], LIBPATH=['.','/opt/local/lib']))
BuildEnv.Program('sambaget', glob('main_sambaget.c'),
         LIBS=['usb', 'nxt'], LIBPATH=['.','/opt/local/lib'])

Once this is done you can type scons and scons sambaget which will give you the two utilities you were looking for: fwflash and sambaget.