NXT / pbLua dump screen to XPM 913
With very little effort one can change the function DumpDisplay from the tutorial to a DumpDisplayToXPM, which will create a human-readable as well as computer readable file.
/* XPM */
static char *xpm_[] = {
"100 64 2 1",
"* c #000000",
". c #ffffff",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"....................................................................................................",
"......*.....*.......................****.........*..................*...*****.*.....................",
"......*.....*.......................*...*........*.................**...*.....*.....................",
"****..*.**..*.....*...*..***........*...*..***..***....***..........*...****..*.**..................",
"*...*.**..*.*.....*...*.....*.......****..*...*..*........*.........*.......*.**..*.................",
"****..*...*.*.....*...*..****.......*...*.*****..*.....****.........*.......*.*...*.................",
"*.....*...*.*.....*..**.*...*.......*...*.*......*..*.*...*.........*...*...*.*...*.................",
"*.....****..*****..**.*..****.......****...***....**...****........***...***..****..................",
"....................................................................................................",
};
Using PixelMator this can easily be translated to PNG:

Here’s the function:
function DumpDisplayToXPM()
print("/* XPM */")
print("static char *xpm_[] = {")
print("\"100 64 2 1\",")
print("\"* c #000000\",")
print("\". c #ffffff\",")
for y=0,63 do
s = ""
for x=0,99 do
if 0 ~= nxt.DisplayGetPixel(x,y) then
s = s .. "*"
else
s = s .. "."
end
end
print( "\"" .. s .. "\"," )
end
print("};")
end
Currently this function outputs to the console, which is fine for our purpose, so we can copy and paste it over to our computer.
As said earlier, I’m using MacVim which supports XPM natively.
XPM / XPiXMap and pbLua / NXT 252
Well, while I was at it tonight, I found that the text-based interface of pbLua isn’t very user friendly in comparison to the default LEGO NXT interface with it’s nice icons. Not that we need icons of course, but they’re cool. ;)
So I wrote a Lua class which can open XPM images, which are stored on the FileSystem and show them anywhere on the NXT-screen.
XPM images are also textbased, very ideal for our purpose, albeit they don’t have a very small footprint (the below image is 160 bytes, so it’s also not TOO big):! XPM2 16 7 2 1 * c #ffffff . c #000000 **..*........... *.*.*........... **..*..**.**..** *.*.*.*.*.*..*.* **..*..**.*...** ...............* .............**.
Luckily MacVim understands this format and allows you to see it:

Right now this image is on my NXT display – inverse though, next is making the parsing a bit more flexible.
A good thing is that PixelMator can convert to XPM, so no manual editing of XPM files ;)
Now to see whether we can get the below image to show on the NXT screen (nope no colors):

Getting a Lua program onto the NXT 1452
In my last post, only yesterday, we’ve seen how to install pbLua onto the LEGO NXT. Now we also want it to do something ofcourse.
Let’s first start with connecting to the pbLua-NXT again (using screen – or a utility if you like) and at the > prompt copy and paste the whole following code:
-- Replace HelloWorld on the next line, with the name of the program you want fileName = "HelloWorld" -- Replace the text between [[ and ]] with your own program. programText = [[ nxt.DisplayClear() nxt.DisplayText( "Hello, World!" ) ]] h = nxt.FileCreate( fileName, string.len(programText) ) nxt.FileWrite( h, programText ) nxt.FileClose( h )
This now created a file called HelloWorld onto your NXT. To now also run the program give the following command: nxt.dofile('HelloWorld')
That’s all there is to it, isn’t it easy?
Remember that this procedure is not needed if you just want try the API, remember (if you checked yesterday’s article) that we did nxt.SoundTone() on the console.
Lua on LEGO Mindstorm NXT 120
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.
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.
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 3470
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 14304
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 …
Mac OSX and Lego NXT stuff 2070
From John Hansen I understood that there’s nice OSX stuff for your LEGO NXT coming up or already there.
The first is a full-blown IDE for use with nbc/nxc called NXTCode . I must say: it looks good and I hope it’ll get finished and released.
The second is a utility called NXTBrowser. It allows you to browse your NXT with OSX. It’s a Universal binary so it runs on your PPC as well as your Intel Mac. Good stuff!
Drag & Drop NBC/NXC to RXE 25916
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 46050
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.
8002: Destroyer Droid 2818
Yesterday I received my 8002: Destroyer Droid and built it. Apparantly the instructions were faulty, because I received a supplement with it. It was quite a hassle to get it correct.
Older posts: 1 2


