Program your Lego NXT robot in a Scratch-like language

Lead Image © Ricky Corey, 123RF.com

Enchanting Programs

, ,

Enchanting lets you program your Lego Mindstorms robots in a language and environment based on Scratch.

Enchanting is a free, open source programming language that allows you to program Lego Mindstorms NXT robots in a Scratch-like language. Many kids are familiar with Scratch, and we found we were able to start programming robots almost right away.

Getting Started

Enchanting [1] can be run in Windows, Mac OS X, or Linux. The Enchanting application can be downloaded from Canonical's Launchpad [2].The first time that you run Enchanting, it will need to reload the NXT firmware with LeJOS (a Java-based Lego NXT firmware). You'll see a warning message about possible problems during this process, although we loaded and unloaded the firmware many times without any issues.

We found that Enchanting had all the functionality that the Lego software had. The only exception was Bluetooth support for brick-to-brick communications. Some of the things we liked about Enchanting include:

  • Costumes and backgrounds are easy to make.
  • PC webcams are integrated for picture taking.
  • Enchanting has a nice library of images and sounds.

Ball Thrower

We built a simple ball-throwing robot that was activated with a push button. Although there are many ways you could build the robot [3], we chose a fast-moving straight arm that used one motor (Figure 1). With the fast motion of the throwing arm, we needed a large Lego mounting sheet for support.

Figure 1: Ball launcher.

The first step in writing the application was to define which ports the motor and touch sensor were plugged into. To define the motors, click the Motors button, then select Configure Motors and drag the NXT motor block to your port (Figure 2). To configure the touch sensor, click the Sensing button, then select Configure Sensors, and drag the Touch Sensor block to your port (Figure 3).

Figure 2: Setting up a motor.
Figure 3: Setting up a touch sensor.

The entire program comprised only about 12 blocks (Figure 4). All programs need to start with the when clicked block. The forever block was used to repeat the ball throwing many times. For our code, we had the arm rotate up fast (-90 degrees) and come down slowly (90 degrees). We added sounds and a cool background to make it more fun.

Figure 4: Ball launcher code.

Some future project ideas could include:

  • Use the buttons to adjust the speed and launch angle.
  • Add a second motor to pivot the base.
  • Add guides to launch paper airplanes.

Buy this article as PDF

Express-Checkout as PDF

Pages: 4

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content