The MonoBrick communication library is a LEGO Mindstorms communication library written in C# that works with the standard firmware on both the EV3 and NXT. MonoBrick communication library runs on a wide variety of operating systems including Linux, Mac OS and Windows. The library can communicate with the brick using either USB, Bluetooth or WiFi(only EV3). Furthermore it is also possible to communicate with the brick over the Internet using a tunnel connection. Tunnel communication is done using MonoBrick Tunnel or MonoBrick Tunnel for Android. Since the library works with both Mono and Microsoft’s.Net Framework it can be used with either Visual Studio or MonoDevelop/Xamarin Studio. Although most Windows users will prefer Visual Studio – MonoDevelop/Xamarin Studio is definitely worth a try. MonoBrick communication library has the following features:
- Communicates with the brick using USB, Bluetooth, WiFi or a tunnel connection
- Works with Linux, Mac OS, Windows, Windows Phone and Android
- Support for all LEGO sensors that comes with the Retail and Educational sets
- Support for a wide range of Hitechnic sensors (not yet supported on the EV3)
- Control the motors individual or as a vehicle
- Use the mailbox system to send messages/data to the brick
- Play tones and sound files
- Use the file system to download and upload files
- Start and stop on-brick programs
- Use exceptions to catch sensor and communication errors
- Open and close connections with multiple bricks
- and more..
Writing your first program
Before starting 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 the library. Once you have a working connection download the MonoBrick library source files using the download link and add these to your project. Another option is to download the test project and use this as a starting point. The test project includes the source files and the sample program shown below. For more examples have a look at the library guide as well as the documentation.
using System; using MonoBrick.EV3;//use this to run the example on the EV3 //using MonoBrick.NXT;//use this to run the example on the NXT namespace Application { public static class Program{ static void Main(string[] args) { try{ var brick = new Brick<Sensor,Sensor,Sensor,Sensor>("usb"); sbyte speed = 0; brick.Connection.Open(); ConsoleKeyInfo cki; Console.WriteLine("Press Q to quit"); do { cki = Console.ReadKey(true); //press a key switch(cki.Key){ case ConsoleKey.R: Console.WriteLine("Motor A reverse direction"); brick.MotorA.Reverse = !brick.MotorA.Reverse; break; case ConsoleKey.UpArrow: if(speed < 100) speed = (sbyte)(speed + 10); Console.WriteLine("Motor A speed set to " + speed); brick.MotorA.On(speed); break; case ConsoleKey.DownArrow: if(speed > -100) speed = (sbyte)(speed - 10); Console.WriteLine("Motor A speed set to " + speed); brick.MotorA.On(speed); break; case ConsoleKey.S: Console.WriteLine("Motor A off"); speed = 0; brick.MotorA.Off(); break; case ConsoleKey.B: Console.WriteLine("Motor A break"); speed = 0; brick.MotorA.Brake(); break; case ConsoleKey.T: int count = brick.MotorA.GetTachoCount(); Console.WriteLine("Motor A tacho count:" +count); break; case ConsoleKey.C: Console.WriteLine("Clear tacho count"); brick.MotorA.ResetTacho(); break; case ConsoleKey.M: Console.WriteLine("Enter position to move to."); string input = Console.ReadLine(); Int32 position; if(Int32.TryParse(input, out position)){ Console.WriteLine("Move to " + position); brick.MotorA.MoveTo(50, position, false); } else{ Console.WriteLine("Enter a valid number"); } break; } } while (cki.Key != ConsoleKey.Q); } catch(Exception e){ Console.WriteLine("Error: " + e.Message); Console.WriteLine("Press any key to end..."); Console.ReadKey(); } } } }
Support
The MonoBrick communication library has its own forum where you can find answers and questions related to the library.
Hey Anders, it’s me again.
After the failure with the Monobrick remote connecting to the Ev3, I recently downloaded the Monobrick Test Project.
I connected the EV3 via USB to the PC, but when I open the Test Application and debug it, I got the message, that the application cannot build a connection to the brick.
The compiler says:
An exception of the type “System.BadImageFormatException” appeared in TestApplication.exe.
An exception of the type “MonoBrick.ConnectionException” appeared in TestApplication.exe.
So, do you know what the problem could be. I’m using the EV3 (Education set), firmware 1.03E and the EV3 software is running on my PC.
And by the way, thank you very very much again for the whole Monobrick project and for your help.
Greets,
Konne
Please post this question in the forum
Hey, I have no idea how to set this up. >_< Could you help me?
Ask your question in the forum. And please try to tell what you did and what the problem is. Thanks
Anders
Visual Studio (C#) can use Android Library DLL ?
only MonoDevelop/Xamarin Studio can use?
Hello,I am a Java Android developer…. But now I see your library, think it is good. And it is a DLL library. How I use it??????? But seems the Android cannot use library. How I do?
You need to use Xamarin to get things working with the Android
/Anders
Is this library works with your MonoBrick firmware as well?
Hello,
Can you said me, how the dll (Monobrick.dll) is run (communication, etc) ?
It’s very urgent !
Thanks in advance, and thanks ask me the 03/05/2015 !
Regards
Please ask questions in the forum…
Hi, this library is broken on mac – you need to change the name of the external calls to the hidapi to “hidapi.dylib”
Please use the forum is you have questions
Nice – thanks for using MonoBrick