The VirtualArduino is an Arduino Hardware Emulator for MyRobotLab.

The Arduino service will only see a COM port, and when it connects, it cannot tell the difference betwen this emulator and a "real" Arduino.

Emulators can be very useful in testing, developing and simulating "real" hardware.

The following script should create a VirtualArduino, connect an Arduino service to it, attach a servo and enable several pins which can be viewable on the Oscope tab in the WebGui

Below is the result of running the script

The status reports :

  • An Arduino Uno was found on COM5 and connected at 115200 bps
  • load - is measured in the number of micro seconds per loop.  The higher the number means MrlComm is taking longer to process.  The emulator is almost always at ~10K because there is a 10 ms sleep in the main loop.  The sleep is necessary, otherwise the computer emulating the Arduino will not be happy (it has many other things to do besides emulate Arduinos !)
  • heartbeat -  is the time the roundtrip time it takes to send a BoardInfo request and get back a PublshBoardInfo response - in this case it took 6 ms, this will vary depending on load, and task switching
  • 2 active pins - means 2 pins are currently being read from
  • 1 devices - refers to the single servo listed below with its device id

Now the only thing you need to do to "switch" between a virtual and a real Arduino is, comment out the connect with the virtual arduino.

Below is the exact same script with the virtual arduino connect commented out.  This makes the script connect to the real Arduino I have on COM5.

As you can see the general behavior is the same.  It enabled two real pins for reading and moved a real servo.  The plan going forward is to integrate a 3D environment where a servo can move from the commands of the virtual arduino.  

This would allow testing and experimentation to be done in a virtual 3D environment, and when perfected, a very simple switch can be made to allow the perfected program or service to operate with real hardware in the real environment.

MrlComm - is the sketch/firmware used so MyRobotLab can control Arduinos.  It has been ported line by line to a set of Java classes under the package org.myrobotlab.arduino.virtual.

The picture below shows the list of files and a comparison between MrlComm.ino and its Java counterpart.

The emulator can be a great tool for developing new services and interfacing with a 3D virtual environment, but its important that these files remain in sync.  Changes in MrlComm should be replicated to its virtual counterpart and vise vera.  If we all want to use this tool, we all need to be responnsible to keep it up to date.  Have fun !


Example for develop:

#file : edit raw

# start the virtual arduino service
varduino = Runtime.start("varduino","VirtualArduino")

# "connect" - creates a virtual COM port with 2 ends
# one called "COM5" the other "COM5.UART"
# the virtual arduino connects to the COM5.UART end,
# and an arduino service can connect to the "COM5" end

# Runtime.start("WebGui","WebGui")
varduino = Runtime.start("varduino","VirtualArduino")

# start the Arduino service
arduino = Runtime.start("arduino","Arduino")
# connect it to the emulator

# start reading from a digital and an analog pin
# "default" emulator values of pin is random

# create a servo and attach it
servo = Runtime.start("servo","Servo")
servo.attach(arduino, 7)


Gelvis's picture

Good for use in education


This is a great feature - it means each student in my software course at college can now run MyRobotLab with the InMoov script and their changes *without* having to have a full InMoov attached.

They can now develop their scripts, test locally and then, once they are happy it is debugged, they can run it on the full InMoov - they will only have to change one line too!

Any idea when it will be in a release, rather than using 'bleeding edge' versions?

Thanks again!


moz4r's picture

thanks. now I can use mrl at

thanks. now I can use mrl at work ! mmm sorry at home I want to say