14.9 - Compile and Upload Arduino Sketches Programmatically

With this short Jython script, an Arduino service is created and a Arduino sketch is compiled then uploaded to the microcontroller.  In this case the sketch is MRLComm which allows communication between MRL and Arduio, but other sketches could be loaded too, depending on the state of the Borg :)

 


from org.myrobotlab.service import Arduino

# create an Arduino service
arduino = runtime.createAndStart('arduino','Arduino')

# set board's serial port
#arduino.setPort('/dev/ttyS50');
arduino.setPort('COM10')

#set the serial parameters of the connection
arduino.setSerialPortParams (57600, 8, 1, 0)

arduino.compileAndUploadSketch('C:\\mrl\\myrobotlab\\.myrobotlab\\MRLComm\\MRLComm.ino')

arduino.pinMode(44, Arduino.OUTPUT)
arduino.digitalWrite(44, Arduino.HIGH)