- Home
- About
- Articles
-
- Enchanting 0.0.1 - Now Exports Code
- Status of Exporting Code from Enchanting
- An Enchanting Idea
- Code Blocks, Electronic Bricks, and LEGO Beams
- Future Directions of Scratch?
- WCRG 2010 just around the corner
- Sea Monster-cum-Dragon
- Guest Blog: Robofest, Stealth Learning, and Rodeo Spirit
- Website Has Moved To A New Host
- Robofest 2010 Cardston Highlights Video
- Contact Us
Enchanting 0.0.1 - Now Exports Code
I have got Enchanting exporting LeJOS code that will actually compile and run on your NXT. I have only tested it enough to see that it works, and I know there are bugs remaining to be found.
If you’d like to try it, and have LeJOS installed and set up, download it here. (36 MB)
New in this version:
- exporting actually works.
- if you want to mess with it, play with the two files starting with ‘lejos’ in the locale directory.
- you should be able to double-click on Enchanting.exe/Enchanting.app to start the program, instead of dragging and dropping the image. (Not tested on Windows).
- I have removed blocks that do not export, and created a few that translate nicely into LeJOS.
So, open up Enchanting, and create a script.
Right click on your sprite and choose “Export”. You’ll be prompted for a name. Please, use a name that can be used as a Java class — stick to letters and numbers (and maybe underscores) and you’ll be fine.
Then, go to your trusty terminal and compile and upload the program:

And run it on your NXT!
Please let me know how well it works for you and what fixes I need to make.
Addendum
I forgot to mention that variables and lists do not work at all, and that the following configuration is assumed:
Motors
- Left is Motor C.
- Right is Motor A.
- ‘Claw’ is Motor B.
Sensors
- Touch Sensor is on port 1
- Sound Sensor is on port 2
- Light Sensor is on port 3
- Ultrasonic Sensor is on port 4
If you don’t have a given sensor attached, it should not be a problem.
Status of Exporting Code from Enchanting
In the far-too-brief periods of time I’ve been able to put into Enchanting of late, I’ve been working on making it so that you can export code. I wanted to put up some incomplete results of my work.
If I construct the following script:

middle click on the sprite that owns the script and choose “export code”:

a window pops up with the text converted into a Java-esque format:
public void WhenGreenFlagClicked()
{
// GoTo(-100, 0);
// ClearDisplay();
// PenDown();
// PlaySound();
// PlayDrum(48, 0.2);
// WaitSecs(RandomRange(1, 10) / 5);
// WaitSecs(Math.pow(Math.E, 10));
}
public void WhenGreenFlagClicked()
{
LightSensor.SetMaxPoint(LightSensor.GetRawReading());
LightSensor.SetMinPoint(LightSensor.GetRawReading());
LeftMotor.runUnlimited();
Right Motor.runUnlimited();
for (int i = 0; i < n; ++i)
{
if (LightSensor.GetRawReading() > LightSensor.GetMaxPoint())
{
LightSensor.SetMaxPoint(LightSensor.GetRawReading());
}
if (LightSensor.GetRawReading() < LightSensor.GetMinPoint())
{
LightSensor.SetMinPoint(LightSensor.GetRawReading());
}
}
while(true)
{
LeftMotor.setPower(LightSensor.GetBrightness());
Right Motor.setPower();
}
}
There are still flaws and shortcomings to overcome, and it isn’t real code yet, but I’m pleased with the progress.
If you want to try it out (without getting the latest from version control), download this snapshot of the program, drag and drop Enchanting.image onto your Enchanting.exe or Enchanting.app, and have fun.
The files of note are:
- the Enchanting.image file, which has all the code changes
- locale/lejos.exp — a translation file used to translate from Scratch to the java-esque output (go ahead and play with it; it is reloaded every time you click export)
- the ReferenceImages folder, which has pictures of the different code blocks with their block specification name in English. (This is handy for translating, and, if you hold down Shift and click on the file menu, there is an option to generate these files.)
An Enchanting Idea
In my previous post, where I discussed creating custom code-tiles in a variant of Scratch and using them to control devices external to the computer — namely an Arduino and an NXT robot — I finished off by saying that I would discuss where I want to go to from here.
An Enchanted Vision
I want to make a graphical code-creation tool to make it easier for kids to program robots—so that they can cast a magic spell, as it were, that makes a robot sing and dance and do as they’ve instructed.
My current plan is to build off of Scratch, which my kids enjoy working with. (The same can not be said for the NXT-G programming environment which comes with the LEGO Mindstorms NXT kits).
I envision two modes of operation:
1. Interactive Mode
In interactive mode, your robot is instructed step-by-step on what to do by the computer, and can interact with other sprites and such in Scratch.
You could, for example:
- have a robot with an ultrasonic sensor on it that spins in place, with a sonar-like display on-screen.
- adjust parameters (like speed, or degrees to turn) with sliders on screen as a program is running.
- use the NXT as an input device; for example, one could build a crank to spin a motor, and on the computer, read the motor’s encoder position to, say, reel in a fish on screen
- have a robot (or robots) be in a play with virtual actors who appear on screen.
- see what your sensors are seeing, so as to better understand and correct a program.
- or just use this method to prototype programs.
2. Autonomous Mode
When you are ready to try a program that the robot runs directly, you export the code (see this video tutorial for Scratch For Second Life to get an idea of what I mean), and from there, put it onto the robot.
The reasoning behind this is two-fold:
- Plenty of good programming environments already exist that can be used to program the NXT (and other potentially supported platforms), and there is no sense re-inventing the wheel
- I want to expose kids to the idea of text-based programs, so that they are able to transition to them when the time is right.
Having said that, though, I want the code to look nice so that someone could study and learn from it.
Inclusive Support
My primary focus at the moment is to help kids program their NXTs. I’d like the same environment, though, to be able to target other systems, such as the RCX, the Arduino, and perhaps things like VEX or OLLO.
Next, I’d like the software to be multi-platform and open-source. It should run on Windows, Mac OS X, and Linux.
Lastly, I’d like the software to be accessible to as wide an audience as possible. If I were designing it from square one, I’d want to ensure that you could do everything with the keyboard, everything with the mouse, and that you can make the text really large so that people with poor visual acuity can use it. I also want to ensure that text can be translated into other languages. The software should also allow users to do advanced things but in a comprehensible manner.
Where Am I At?
I’m close to the beginning of this journey. My previous post gives a proof-of-concept peek into what I want to do. I’m reading through Squeak By Example and lurking in the Scratch Advanced Topics Forum to learn how to hack on Scratch. (I should mention that I programmed video-games professionally for three years, but Squeak (the language Scratch is written in) is not widely used and different from C++ and Python).
How Can You Help?
I’m not expecting much by way of coding help (but if anyone is interested, do let me know!), and I’m nowhere near ready for testing help, but I could certainly use some thoughts on design, specifically, on what sort of code tiles would be useful to have and how to organize them.
My current though is that, if you are programming for an NXT, perhaps you should use a special NXT sprite, which supports all options available for use in programming the NXT, and omits those which are not applicable (such as changing costumes, setting the graphic effect, or determining the distance to another sprite). That being the case, though, perhaps it is better to have different categories of tiles altogether, although I’m not really sure what those categories should be. I’d love to hear your ideas on this.
I’m also quite happy to hear suggestions on what language(s?) should be used as an intermediate language for autonomous programs. I’m partial to leJOS NXJ, and certainly there is something to be said for NXC ; I can’t help but think that NXTalk would be ideal, but it is also in an embryonic state and working on Enchanting itself is more important to me. I’d like to balance ease of use, readability of code, and ease of installation, and yes, there are many, many languages to choose from.
What of the Arduino? It might be easier to get it up and working with Scratch—especially as Scratch will already talk to a PicoBoard over a serial port, and the language to output to is obvious and readable. It looks to me like the Modkit project might have things covered, and the NXT is my primary focus at this time.
Feel free to contact me or add a comment below.

