Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.


Folders and files

Last commit message
Last commit date

Latest commit



44 Commits

Repository files navigation


Haskell-Nxt is a library to control Lego Mindstorms NXT Bricks from Haskell.

Since the nature of the communication with the Brick is stateful, the library consists almost entirely of monads.

Haskell-NXT is my first piece of Haskell software and probably has a lot of rough edges still so comments, tips, bug reports or patches are very much appreciated.


I want to briefly explain the architecture of the Library here.


This module is used for setting up a NXTBrick and fiddling around with it. Mainly for testing purposes


Contains various Enums and Translations between NXT protocol bytecodes and descriptive strings or haskell types.


Various helper functions for converting bytestrings, converting little- to big-endian integers, dissecting messages etc.


Lowest level communication with NXT Bricks. Provides a wrapper around System.IO calls to make top-level programs a little less noisy and basic read/write commands


Implementations of the most common Direct Commands in two parts each. One function to assemble the message to send to the Brick, one action to send the message to the Brick in the IO Monad A custom class Appendable is used to more easily combine various data types into NXT messages.


High-level library on top of NXT.Commands to easily run and stop motors.


High-level library on top of NXT.Commands to easily read out the sensors. Requires an initialization call after opening the connection to the Brick and assumes that the sensors are plugged into their intended ports on the brick.


Since the Ultrasonic sensor communicates with the NXT via I2C, controlling it is a little more complicated. This module contains mainly a list of I2C commands.

Usage Example

btBrick = NXTBrick Bluetooth "/dev/tty.NXT-DevB-1"

main = do
	h <- nxtOpen btBrick
	playtone h 500 500
	setupDefaultSensors h
	s <- getDistance h
	putStrLn (show s)
	nxtClose h

This opens a NXT Brick located as a serial device at /dev/tty.NXT-DevB-1 in Bluetooth mode (as opposed to USB, which isn't implemented yet). The brick is opened, plays a tone and reads the distance from the distance sensor.

Usage restrictions

  • The library works only on POSIX systems currently.
  • It was developed on Mac OSX 10.5 with GHC 6.8.3 and uses some GHC-extensions to the Haskell standard.
  • Communication with Bricks via USB isn't implemented yet.


  • I2C delay
  • Implement USB interface
  • Implement the rest of the NXT Commands
  • Debugging helpers


Copyright (c) 2008 Jan Varwig, released under the MIT license Original and official version at


A haskell library for controlling Lego Mindstorms NXT Bricks







No releases published


No packages published