Sending messages from a PC application in C# to the Lego EV3

I have managed to connect the EV3 to a PC and are now able to send messages back and forth between the PC and the EV3 using bluetooth. Although it is no rocket science, it wasn’t that easy since there is no documentation available on the Internet about the protocol. So, there was no other way then to download the Linux EV3 source (this is the documentation, and it can be compiled too ;-)) and to locate the code that is responsible for the messaging. And I found the following in the ‘c_com.h’ file:


So, that shouldn’t be that difficult to send a string from the PC to the EV3. I wrote a small program that reads out a mailbox on the EV3, and ‘tataa’: it worked. Adding a second mailbox  to test if another mailbox name would work as well, was just some additional minutes of work. But… it didn’t work as expected! The first mailbox worked still fine, but after sending a message to the second mailbox (which also worked fine), the first mailbox didn’t work anymore.

To check if the EV3 program was not the problem, I took a second EV3 and wrote a small program to send messages. This worked as expected, so it had to be the C# program that causes the problem. Since I didn’t make any progress, I started to write the part to send messages from the EV3 to the PC. This was far more easy:

  • Just write all the bytes you read?
  • Check if you can locate in the HEX codes the string that I send from the EV3
  • And then figure out how the message is coded

And this is the result:

  • bbbbmmmmttssllaaaLLLLppp


  • bbbb = bytes in the message, little endian
  • mmmm = message counter
  • tt = 0x81
  • ss = 0x9E
  • ll  = mailbox name length INCLUDING the \0 terminator
  • aaa… = mailbox name, should be terminated with a \0
  • LLLL = payload length INCLUDING the , little endian
  • ppp… = payload, should be terminated with the \0

So, it seems that the comment in the header file was wrong. It was stupid to trust that the programmer had written flawless comment ;-).

I updated the code to send data to the EV3 with this new information, and now it all works fine!


103 thoughts on “Sending messages from a PC application in C# to the Lego EV3

  1. This is great. Are you familiar with anyone who’s been able to connect the iPhone to the EV3 brick and communicate via the iOS SDK? It should be possible since the EV3 uses an iPhone app to control it, but I haven’t found anyone who’s done so with their own application yet.

    Great work!

  2. Hi Hans,
    Greetings and Thanks for sharing ! :)
    .Net developer here just getting started with LMS EV3.
    I would also like to get a copy of your source code to learn how to control the Brick using Bluetooth messaging.
    email: getsmartpaul at gmail dot com

  3. Pingback: Using Python and Raspberry Pi to communicate with Lego Mindstorms EV3 | EE GIP Projects at Damiaaninstituut Aarschot Belgium

  4. Pingback: Blog of spblinux » Blog Archive » Hardware connected to raspberry pi driven by lego mindstorms ev3 using bluetooth

  5. hi Hans
    Could you send me a copy of the code.
    my school project need that skill~ please~~
    Thank you very much~
    by the way , what is you using wireless LAN? EDIMAX EW-7811Un? NetGear WNA1100?
    I only have EDIMAX EW-7811Un. Can I do it?

    • Hi Minghan,

      Will send you a copy of the code via a Dropbox link.

      With respect to your question: We are using the Netgear WNA 1100 dongles for our project. I have not tested other dongles. If you Google your question about other Wifi dongles, the information you get is that the Netgear WNA 1100 is the only dongle that works with the Mindstorms EV3.

      Best, Hans

  6. Pingback: Talking to robots (or other devices) using Bluetooth from a Windows Runtime app |

  7. Pingback: Talking to robots (or other devices) using Bluetooth from a Windows Runtime app | SDK News

  8. Pingback: Talking to robots (or other devices) using Bluetooth from a Windows Runtime app | Building Apps for Windows

    • Hi Neil,

      Sorry, don’t know if this will work on a Macbook. I know that my colleagues work on a MacBook, so it should be possible.

      Will send you a Dropbox link to the sources.

      Kind regards,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s