HowTo LeJOS for Lego Mindstorm NXT
Aus JSUG
written by Christoph P; created Sunday, January 4, 2009
Inhaltsverzeichnis |
[Bearbeiten] introduction
[Bearbeiten] lego mindstorm
- using common lego technic parts
- intelligent brick (brain)
- two connection types: usb, bluetooth
- runs with 6 AA batteries
- tech specs
- ram
- input sensors: light, audio, ultrasonic, touch
- output: up to three motors
- third party parts available too
[Bearbeiten] lejos
environment for running a java vm and custom java code on the lego mindstorm nxt (and rcx).
features offered:
- java 5 (preemptive threads, synchronization, exceptions, ...)
- file system
- full access to hardware (sensors, motors)
- event listeners
- playing wav files (11025khz, 8bit, 1 channel, pcm)
- and much more!
remember: there is no common JDK (JRE) available on the nxt, you only are able to use a much slimmer reimplementation of the standard library (API documentation).
[Bearbeiten] setup
first of all before going on reading this chapter, please have a look at the official readme file provided with each lejos distribution.
for troubleshooting or if you experience problems or just have any question about the setup, consult the official forum:
http://lejos.sourceforge.net/forum/viewforum.php?f=7 (i am sure andy will respond promptly with a very nice and useful answer).
[Bearbeiten] requirements
- java 5 or later
- ant
- lego mindstorm nxt software installed
- libusb (http://libusb.sourceforge.net/)
- jfantom
- NXJ_HOME environment variable set
- add NXJ_HOME/bin to PATH
[Bearbeiten] build distribution
# cd $NXJ_HOME/build # ant
[Bearbeiten] flash the firmware
- boot nxt in firmware upload mode via pressing the hidden button (at the back of the nxt, upper left corner below the usb port) for at least 5 seconds until you hear the bricket ticking.
- connect computer and nxt via usb
- invoke
nxjflash; done (hopefully)
[Bearbeiten] usage
[Bearbeiten] nxj tools overview
- nxj ...
- nxjbrowse ...
- nxjc ...
- nxjconsole ...
- nxjconsoleviewer ...
- nxjdataviewer ...
- nxjflash ...
- nxjflashg ...
- nxjlink ...
- nxjmonitor ...
- nxjpccomm ...
- nxjsocketproxy ...
- nxjupload ...
[Bearbeiten] hello world
- invoke nxjc
- either nxj and finished, or link and upload separately
[Bearbeiten] eclipse plugin
[Bearbeiten] codesamples
[Bearbeiten] play a soundfile
import java.io.File; import lejos.nxt.Button; import lejos.nxt.LCD; import lejos.nxt.Sound; public class PlaySound { public static void main(String[] args) { final File soundFile = new File("r2d2.wav"); LCD.drawString("Play: " + soundFile.getName(), 0, 1); Sound.playSample(soundFile, 100); // 100 ... volume try { LCD.drawString("Enter to Exit", 0, 2); Button.ENTER.waitForPressAndRelease(); } catch (InterruptedException e) { } } }
[Bearbeiten] appendix
[Bearbeiten] icommand
[Bearbeiten] links
- http://lejos.sourceforge.net/ ... official lejos website



