Runing Programs from the Menu

IMPORTANT: This method has been tested on a Lego EV3 with firmwares version 1.03H and 1.06H (check Brick Info). The first EV3s had version 1.01 which does not support using the “system” command. You may need to update the firmware before using this method.

The Lego VM provides a function that can call the system command. This function allows running any command either from the operating system or user-created programs available in the microSD card. Using the lmsasm tool from the EV3 source code, I created a program that runs in the Lego Virtual Machine. Its only purpose is to execute a program located in the microSD card.


In the following video I chose the “Open Loop Control” program as example. The video shows this program running from a terminal, and after removing the WiFi dongle, directly from the EV3 brick menu.

These files must be copied in the microSD card. The executable C or C++ program must be placed directly in the root directory of the microSD card. The LVM file must be inside the “myapps” directory in the sdcard. I have been using this program to run all my demos when a WiFi network is not available or I can not (or don’t want to) have a computer. As far as I can tell, this program does not interfere with the LVM. In fact, it prevents that from happening, since the program will prevent the LVM to run any other application. It does not prevent user from running applications from a terminal though.

This web site provides an explanation of how to compile and create programs using this scripting language.

Source Code
This is the source code for the Lego-VM program. Notice that the executable file must be named “program”. A copy of the compiled version of this program can be found here.

vmthread MAIN
DATA32 Timer
DATA32 Status

//Write a message

//This is the command that executes the program

//Wait before exiting

I found that applications that use the terminal intensively to display information, may slow down significantly when running from a menu. This issue can be solved by redirecting the program output the null device as follows:

./program > /dev/null 2>&1

Prev >> Sensors
Next >> Applications

7 Responses to Runing Programs from the Menu
  1. Christoph says:

    Thanks for the info. We tried running your “run_program.rbf” on a ev3, but are getting a ” VM PROGRAM VALIDATION” error and nothing happens.
    We copied “run_program.rbf ” into the myapps dir and “program” into the root of the SD card.
    We’re running the stock LEGO OS using Linux kernel 2.6.33 and firmware v1.01h.
    Can you offer any advice? Thanks in advance,

    • admin says:

      My current firmware version is 1.03H. The first time I used the EV3 with the provided windows program, it recommended upgrading it.

  2. Stephan orsholm says:

    I get the same problem: “VM PROGRAM VALIDATION”.

    I have tried recompiling the run_program.lms program above. If I leave out the call to SYSTEM, the program runs without validation errors but then it does not help much since the C program is not started.

    I conclude the problem is in the C program which cannot be validated. I don’t know why but will investigate.

    • admin says:

      Lego has a “DISABLE_SYSTEM_BYTECODE” flag that can disable the “system” call (see lms2012.h file). I am wondering if some EV3s had the firmware compiled with that definition enabled. Could check your firmware version? mine is 1.03H

      • Stephan Korsholm says:

        My firmware was 1.01H :-(

        I updated and now it works :-)

        I should have tried that before, so sorry for wasting your time.

        – Stephan

  3. MikoĊ‚aj Karawacki says:

    Hi, I found your blog/website while google-vestigating how to run C programs without telnet-ing to the brick. How exactly do you compile the source for Lego-VM wrapper/caller for your C program? This part got me buffled.