MonoBrick

MonoBrick is a LEGO Mindstorms communication library written in C# that runs on a wide variety of operating systems including Linux, Mac OS and Windows. The library can communicate with the Mindstorms NXT brick over USB, Bluetooth or Ethernet. Ethernet communication is done using MonoBrick Tunnel or MonoBrick Tunnel for Android. Since MonoBrick works with both Mono and Microsoft’s.Net Framework it can be used with either Visual Studio or MonoDevelop. Although most Windows users will prefer Visual Studio – MonoDevelop is definitely worth a try. MonoBrick has the following features:

  • Communicates with the NXT using USB, Bluetooth and Ethernet
  • Works with Linux, Mac OS, Windows, Windows Phone and Android (using Mono for Android)
  • Supports more that 20 analog and I2C sensors
  • Control the motors individual or as a vehicle
  • Send and receive messages using the mailbox system
  • Set Brick name, get battery level, read firmware version etc.
  • Play tones and sound files
  • Use the NXT’s file system to download and upload files
  • Start and stop on-brick programs
  • Use exceptions to catch sensor and connection errors
  • Open and close connections with multiple NXT units
  • and more..

Writing your first MonoBrick program

Before writing your first program please make sure that you are able to communicate with the Mindstorms brick over either USB or Bluetooth. Mac Os and Linux uses will also have to make sure that Mono is installed. These guides will help you setup communication under Windows, Linux and Mac OS for use with MonoBrick. Once you have a working connection download the MonoBrick library dll using the download link and add the dll as a reference in your project. Another option is to download the test project. The test project includes the sample program shown below where the keyboard is used to read sensor values and control motor A.

using System;
using MonoBrick;

namespace Application
{
  class Program
  {
    static void Main(string[] args)
    {
	var nxt = new NXTBrick<TouchSensor,Sonar,NoSensor,NoSensor>("usb");
	nxt.Connection.Open();
	nxt.Sensor2.Mode = SonarMode.Centimeter;
	ConsoleKeyInfo cki;
	Console.WriteLine("Press Q to quit");
	do 
        {
		cki = Console.ReadKey(true); //press a key
		switch(cki.Key)
                    {
			  case ConsoleKey.D1://1 was pressed
			      Console.WriteLine("S1: " + nxt.Sensor1.ReadAsString());
			  break;
              case ConsoleKey.D2://2 was pressed
			      Console.WriteLine("S2: " + nxt.Sensor2.ReadAsString());
			  break;
			  case ConsoleKey.UpArrow: 
			      Console.WriteLine("Motor A forward");
			      nxt.MotorA.On(50);  
              break;
			  case ConsoleKey.DownArrow: 
	              Console.WriteLine("Motor A reverse");
			      nxt.MotorA.On(-50);
			  break;
	          case ConsoleKey.S: 
		          Console.WriteLine("Motor A off");
			      nxt.MotorA.Off();
			  break;
		    }
	   } 
       while (cki.Key != ConsoleKey.Q);
    }
  }
}

Documentation

For more MonoBrick examples have a look at the MonoBrick guide and the documentation pages.

Make a donation
Download
MonoBrick448 downloads
PDF Class View256 downloads