
Do you want to code advanced tasks for your Lego Mindstorms Ev3 brick? If your answer is yes, you are definitely in the right place! In this tutorial you will learn how to set up your environment to start to program with C# and Monobrick Ev3 Firmware Library.
Things to know
The Lego Mindstorms Ev3 brick has a very nice feature: it comes with a microSD port that you can use to boot the brick with a new firmware without permanently affecting your beloved device. This means that you can always revert to the factory settings by just removing the microSD and then power cycling the Ev3 brick.
There are several firmware projects around to choose from if you don’t want to rely only on the original Lego Mindstorms graphical programming tools. The projects I have explored so far are:
- Lejos, is a set of well documented Java libraries to program the Ev3 brick, the NXT brick and the RCX brick using Java.
- Ev3Dev is a Debian Linux-based operating system that runs on several Lego Mindstorms compatible platforms including the Lego Mindstorms Ev3 and Raspberry Pi-powered BrickPi. Several languages are available to choose from including C#.
- The Monobrick Ev3 firmware library is firmware replacement that allows you to program and debug the Ev3 brick using the open source .Net Framework called Mono.
If you are a C# fan, then the right projects are Ev3Dev and Monobrick. In this tutorial I will focus on the Monobrick Ev3 firmware library.
Oh, and why this tutorial despite the all documentation available on the Monobrick website? Because I thought helpful to have all the steps in just one single page.
This tutorial assumes you are using a Windows 7 Pro or later operating system.
Things to have
To follow and complete this tutorial you will need:
- The Lego Mindstorms Ev3 brick.
- A microSD card of the appropriate size. Currently you can choose between 512Mb, 2Gb or 4Gb due to the firmware replacement images available.
- A microSD reader for your PC.
- A Microsoft Visual Studio 2015 or later edition. You can download the Community Edition which is essentially free from this link.
- A USB cable from your computer to the Ev3 brick
- Optionally a WiFi dongle. I am currently using this one.
Things to do
Now let’s proceed with the actual steps.
Step 1 – Get the firmware replacement
First, download the firmware image from the Monobrick.dk website. You need to download the firmware image suited for the microSD card you have:
- For a 512Mb microSD card use this link.
- For a 2Gb microSD card use this link.
- For a 4Gb microSD card use this link.
Step 2 – Prepare the microSD with the firmware replacement
- Unpack the appropriate file for your microSD you have downloaded at step 1. If you do not have an application to unpack the compressed image, you can download and install the open source archiver 7-zip.
- Download and unpack Win32 Disk Imager. You need this application to create the bootable microSD with the Monobrick firmware.
- Plug the microSD into the reader.
- Run Wind32 Disk Imager as administrator. Open the unpacked firmware image and write it to the microSD. Remember that during this process all files the microSD will be lost, so backup them first.
- Once the process is complete, you can unplug the microSD from the reader and plug it into the Ev3 brick.
- Turn on the Lego Mindstorms Ev3 brick.
- If everything went smooth, you should see the Monobrick logo on the LCD screen of your Ev3 brick. Don’t forget that if you want to revert to the original Lego Mindstorms Ev3 firmware, you just need to remove the microSD and reboot the brick.
Step 3 – Connect your PC to the Ev3 brick
Using a USB cable to connect your PC to the Ev3 brick is pretty straightforward: the connection will be set up by means of the RNDIS protocol. This means that the Ev3 brick will be accessible at the IP address 10.0.1.1 with the Ev3 brick emulating an Ethernet TCP/IP device on the USB port.
Just connect the Ev3 brick to the PC with USB cable. Then update the RNDIS driver using the device manager and manually choose Microsoft Corporation/Remote compatible NDIS device.
It’s time to check that the process is completed with success: open a terminal and ping the address 10.0.1.1. If you get an answer, then the connection is up and running.
The following pictures show the procedure, although in Italian.
If you have a WiFi dongle compatible with the Ev3 brick, you can use the Monobrick menu system to select the WiFi network to connect to, provide the WiFi password if needed, and check that the connection is up and running pinging the Ev3 ip address. You don’t need to follow the procedure to update the RNDIS driver in this case.
Step 4 – Get the Monobrick firmware library
To write a program with C# and Monobrick, you need to download the Monobrick Firmware Library which comes as a .dll file. There are several options:
- Get the source files from the original repository on GitHub and compile them yourself. This repository is managed from the Monobrick Firmware library authors.
- Get the compiled .dll from the Monobrick.dk website.
- Get the compiled .dll from Smallrobots.it website (recommended). This last option will let you download the compiled .dll obtained from this forked library. As explained in this post, this version has the PlaySoundFile() bug resolved, so it’s worth to give it a try.
Step 5 – Write a program with C# and Monobrick
Now we are ready to program with C# and Monobrick.
- Open Microsoft Visual Studio.
- Create a new Visual C# Console Application.
- Add a reference to the MonoBrickFirmware.dll obtained at Step 4.
- Copy and paste the following HelloWorld code in the Program.cs file, and compile it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
using MonoBrickFirmware.Display; using MonoBrickFirmware.UserInput; using System.Threading; namespace HelloWorld { class MainClass { static void Main(string[] args) { // Welcome messages LcdConsole.Clear(); LcdConsole.WriteLine("*****************************"); LcdConsole.WriteLine("* *"); LcdConsole.WriteLine("* SmallRobots.it *"); LcdConsole.WriteLine("* *"); LcdConsole.WriteLine("* Hello World *"); LcdConsole.WriteLine("* *"); LcdConsole.WriteLine("* *"); LcdConsole.WriteLine("* Press *"); LcdConsole.WriteLine("* Escape to quit *"); LcdConsole.WriteLine("* *"); LcdConsole.WriteLine("*****************************"); // Turn on the Green Led(s) Buttons.LedPattern(1); // Busy wait for user bool escapeButtonPressed = false; while (!escapeButtonPressed) { // Actively checks for Escape button pressed escapeButtonPressed = (Buttons.ButtonStates.Escape == Buttons.GetKeypress(new CancellationToken(true))); } if (escapeButtonPressed) { // Turn off the Led(s) Buttons.LedPattern(0); } } } } |
Step 6 – Transfer the program to the Ev3 brick
Copying the compiled program to the Ev3 brick goes through the same procedure regardless of the connection media: using the USB cable or a WiFi connection does not change the process, just the IP address to connect to will be different.
Download and install a SCP client like WinSCP. Open a connection to your Ev3 brick (remember that the IP address to connect with the USB cable is 10.0.1.1). Use the following credentials:
- Userid: root
- Password: blank (no password)
You can ignore the security warning messages.
Last thing to do: copy all the content of your output folder (debug or release) to the /home/root/apps/HelloWorld folder on the Ev3 brick.
Step 7 – Start the program

From the top menu, click Programs/HelloWorld/Run Program to launch the program. You should see the picture shown on the right on the LCD of your Ev3 brick. Click the Escape button to get back to main menu.
Next steps
Congratulations! You have just learnt the steps to follow to program with C# and Monobrick. Have a look at the Robots page to check out other projects you can try.
If you liked this tutorial, please rate it 5 stars! Thank you!
And don’t forget to comment with questions or suggestions!
how to creating this tools?
Hello Rani,
Thank you for asking. Could you please try to be more specific?
I will be glad to help.
Regards,
Riccardo.
Hey, me again.
I do have the following problem:
When I compile my program with VisualStudio, I’m getting an error saying “Exception during execution” when I try to run it via the Brick.
However, when I write the same Program with MonoDevelop (on my Raspberry Pi) everything works perfectly.
Also when I run the VisualStudio program via SSH, everything works perfectly.
That’s pretty confusing to me.
I will use Xamarin/MonoDevelop if there’s no other solution, but I would prefer to use VisualStudio.
The program is pretty simple:
using System;
using MonoBrickFirmware;
using System.Threading;
using MonoBrickFirmware.Display;
namespace Ev3_framework4
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(“Hello World from Visual Studio”);
Thread.Sleep(10000);
}
}
}
EDIT:
Using Mono on my pc also does not work.
It could be beacuse of Mono and Visual Studio creating a .pdb file instead of a .mdb file in bin/debug. The Mono version on my Raspberry Pi, which I made the working version with, creates such a .mdb instead of the .pdb.
EDIT 2:
I don’t know what happened, but it’s working right now with my Visual Studio version using the Brick.
Hello Kim,
The line
Console.WriteLine(“Hello World from Visual Studio”)
will not print the string on the LCD Display of the Ev3 Brick, but only just on the Console of Visual Studio. Replace this line with:LcdConsole.WriteLine("Hello World from Visual Studio");
With this you should get the string printed on the LCD display of the Ev3 Brick, however nothing will be printed on the Visual Studio Console window.
Let me know!
Ciao,
Riccardo.
Can you please send me an working SD-Card-Image with Monobrick? I can’t find any download-link… monobrick.dk says “Error 403″… 🙁 🙁 🙁
Hello Christian,
I was not aware that the Monobrick website is down. I don’t know if it is temporary under maintenance or if this issue is going to last. I’ve checked in my files, and I have found the SD images you may need. I will try to upload those images on this website (hopefully without infringing copyrights).
Ciao,
Riccardo.
Hello Riccardo,
I’m looking forward to find the images on your website. I would appreciate you notificating me when and where to find them. Thanks for you help.
Kind regards
Christian
Hello Christian,
I have uploaded the latest Mondobrick firmware libraries images I have. Here are the links:
Monobrick SD 512Mb
Monobrick SD 2Gb
Monobrick SD 4Gb
I will check in the following days if the Monobrick site comes back up and eventually will write a post about it.
Cheers,
Riccardo.
Today I wanted to give Monobrick a try. I wrote the 4GB-image on a 16GB-SD-Card I earlier used with LeJOS. After switching on the EV3 with inserted SD-card I get the Monobrick-Logo presented, the LEDs shining red – and nothin more is happening. Any idea what to do?
I think that you should use a SD card with size matching that of SD image.
Let me know.
Cheers,
Riccardo.
EV3 LCDConsole Error
Using the LCDConsole.WriteLine function
Exception during execution An error occurs.
I do not know what caused it.
Source
using MonoBrickFirmware.Display;
using System.Threading;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
LcdConsole.WriteLine(“Hi”);
Thread.Sleep(5000);
}
}
}
Using the LCDConsole.WriteLine function
Exception during execution An error occurs.
I do not know what caused it.
Try changing v4.0 in YOUR_PROJECT.csproj to v4.0. That worked for me!
Any idea where to download the monobrick sd-card-images? The website monobrick.dk says “Error 403″… 🙁 🙁 🙁
Try changing v4.x.x in your_project.csproj to v4.0.
Worked for me 🙂
Hi,
if someone would like to debug a C# app in MonoBrick within Visual Studio 2019, then try the “VSMonoDebugger” extension (https://github.com/GordianDotNet/VSMonoDebugger). Its free. Actually it works fine. Start the debug agent on the Brick using putty. Just ensure that your have admin rights on your development PC, so that the extension is visible for use. Greetings, Manni