Javadoc link

The Arduino service is used to communicate and control the very popular Arduino micro-controller. MyRobotLab runs on a computer and controls the Arduin hardware through a serial port.

The Arduino needs to be loaded with an Arduino sketch called MRLComm. The latest can be found at the end of this page.

This sketch allows commands from MyRobotLab to be processed on the Arduino hardare, it also allows the Arduino the capability to send data back to MyRobotLab (MRL).

This sketch only has to be loaded once on the Arduino.  The only time it would need to be re-loaded is when it needs to be updated.  After you load the Arduino sketch you may connect (MRL) with the Arduino through the appropriate communication port.  If the Arduino sketch is up to date, you'll see a message after connecting (goodtimes)

<<picture goodtimes>>

If your Arduino sketch it out of date it should say which version it is expecting.  

<<picture out of sync>>

Simply, load the latest MRLComm sketch to fix.

Once MRL is connected to the Arduino, it allows all the many other Services to interact with the Arduino.

  • You can use Arduino as a simple type of oscilliscope
  • You can use Python to effectively program the Arduino, turn on off or read pin values, interact with sensors, control servos, etc.
  • MRL can control and communicate with many Arduinos, there is no limit
  • MRL can be used to communicate between Arduinos
  • With MRL's WebGUI service you can very quickly and easily setup a web interface for an Arduino.
  • With MRL's Sphinx service you can control and Arduino with speech recognition.

<<video demostration>>

<<TODO - hyperlink all oher services>>

<<sketch at bottom>>

<<library at bottom>>

Additonally if you are experienced with Arduino or interested in integrating rather than replacing one of your sketches with MRL, you can use the MRLComm library.  

<<how to load mrcomm library link>>

The GUI view to this service has two sub panels.  It has a Pins Panel, and an Oscope.  

<<oscope>>

You should be at least somewhat familiar with Arduino setup and programming.  See the Arduino website for more information. The Arduino must be connected to your computer when MyRobotLab starts.

In the MRL tab, start the arduino service by right clicking it and selecting start.  Name it anything you like.  Open the Arduino service tab by clicking it.

Editor Menu Bar:

Editor Icon Bar:

Sub Panels:

Pins:

 

Oscope:

[[toSort/Arduino.analog.input.py]]

 

Example code (from branch develop):
#file : Arduino.py (github)
#########################################
# Arduino.py
# description: service to connect and control to an Arduino
# categories: microcontroller, servo, control, motor
# more info @: http://myrobotlab.org/service/Arduino
#########################################
Platform.setVirtual(True) # uncomment this to connect to a virtual arduino
#
# Connects a serial device on Windows this would COMx
# You will need MRLComm.ino loaded on the Arduino
# http://www.myrobotlab.org/content/uploading-mrlcomm-arduino
 
port="COM3"
outputPin = 8
inputPin = 13
 
# start the services
arduino = runtime.start("arduino","Arduino")
 
# you have to replace COMX with your arduino serial port number
# arduino.connect("/dev/ttyUSB0") - Linux way
arduino.connect(port)
 
# give it a second for the serial device to get ready
sleep(1)
 
# update the GUI with configuration changes
arduino.broadcastState()
 
# set the pinMode of pin 8 to output (you can change the pin number if you want)
arduino.pinMode(outputPin, Arduino.OUTPUT)
 
# turn pin 8 on and off 5 times
print "start to play with pin output"
for x in range(0, 5):
     print('digitalWrite pin {} high'.format(outputPin))
     arduino.digitalWrite(outputPin,1)
     sleep(1) # sleep a second
     arduino.digitalWrite(outputPin,0)
     print('digitalWrite pin {} low'.format(outputPin))
     sleep(1) # sleep a second
 
print "stop to play with pin output"
 
# analog input pins - you can see input
# on the oscope
# analog pin range are 14-18 on uno, 54-70 on mega
# rate is the number of polling / sec
arduino.setBoardMega()
arduino.setAref("DEFAULT")
def publishPin(pins):
        for pin in range(0, len(pins)):print(pins[pin].value)
arduino.addListener("publishPinArray","python","publishPin")
 
print "start to poll pin input"
arduino.enablePin(inputPin, 1)
sleep(5)
print "stop to poll pin input"
arduino.disablePin(inputPin)

GroG

3 years 2 months ago

In the WebGUi there is now a button you can download the approrpiate MrlComm.ino and files to upload to the Arduino

Example configuration (from branch develop):
#file : Arduino.py (github)
!!org.myrobotlab.service.config.ArduinoConfig
connect: false
listeners: null
peers:
  serial:
    autoStart: true
    name: arduino.serial
    type: Serial
port: null
type: Arduino