Arduino

javadoc

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:


#file : toSort/Arduino.analog.input.py edit raw
# getting analog input back from arduino into Python

arduino = Runtime.createAndStart("arduino","Arduino")
arduino.connect("COM15")

readAnalogPin = 1
readDigitalPin = 7

# make friendly sample rate
# arduino.setSampleRate(8000)

# add call back route
arduino.addListener("publishPin", "python", "publishPin")

# my call-back
def publishPin(pin):
  print pin.pin, pin.value, pin.type, pin.source

# get data from analog pin for 5 seconds
arduino.arduino.enablePin(readAnalogPin)
sleep(5)
arduino.arduino.disablePin(readAnalogPin)  

# get data from digital pin for 5 seconds
arduino.enablePin(readDigitalPin)
sleep(5)
arduino.digitalReadPollingStop(readDigitalPin)  


 

Examples:


#file : service/Arduino.py edit raw
#########################################
# Arduino.py
# description: service to connect and control to an Arduino
# categories: microcontroller, servo, control, motor
# more info @: http://myrobotlab.org/service/Arduino
#########################################
virtual = 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

port="COM3"
outputPin = 8
inputPin = 13

# start the services
arduino = Runtime.start("arduino","Arduino")

# start optional virtual arduino service, used for test
if ('virtual' in globals() and virtual):
    virtualArduino = Runtime.start("virtualArduino", "VirtualArduino")
    virtualArduino.connect(port)

#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)

eziovn123's picture

How can I control a servo

How can I control a servo through analog pins ?