How do I upload myArduinofile.ino to the Arduino Board (MEGA-UNO) from a Processing sketch

I am using the exec(arg) function My arg is : C:\Program Files (x86)\Arduino\arduino.exe --upload C:\ArduinoProcessingV1\sketch_New\Arduino\HeatTransfer\HeatTransfer.ino

The arg works from commandline of windows it also works in run() function (or similar functions for executing external programs) in my C++ program

I have tried putting various quotes such as; “C:\Program Files (x86)\Arduino\arduino.exe” --upload C:\ArduinoProcessingV1\sketch_New\Arduino\HeatTransfer\HeatTransfer.ino

Hi @demir, Welcome to the forum.

I’ve used command line to build+load Ard sketches for many years. Here’s the contents of my Arduino_Build.bat

@rem Arduino build from command line.
@rem Just put this file in the Arduino project folder (with MyProg.ino)

@rem Arduino Board Type
@rem -----------------
@rem set brd=arduino:avr:uno
@rem Nano - older, slower loader
@rem set brd=arduino:avr:nano:cpu=atmega328old
set brd=arduino:avr:mega:cpu=atmega2560
@rem arduino pro mini 
@rem set brd=arduino:avr:pro:cpu=16MHzatmega328

@rem Port name
@rem -----------------
set prt=COM16
rem ------end-of-edited-settings--------

@rem Temporary files
set tmp=C:\DOCUME~1\RDL\LOCALS~1\Temp\%src%\

@rem Arduino software executable
set cmd=C:\Programs\Arduino\arduino.exe
@rem arduino.exe - GUI, output to stdout, stderr
set cmd=C:\Programs\Arduino\arduino_debug.exe
@rem  - output to console

@rem Project folder (and file name)
for /F "delims=\" %%A in ("%0%") do (
  set src=%%~nxA

@rem Source path and filename
set afl=C:%~sp0%src%.ino
echo %afl%

set tmp=%temp%\Arduino\%src%
if not exist %tmp% mkdir %tmp%
%cmd% --upload --board %brd%  --port %prt% --verbose-build --preserve-temp-files --pref build.path=%tmp% %afl%


It goes in the Ard sketch folder. If you use it directly you’ll need to edit/select the Ard type and port number. On line 24 is the location of the Ard executable. I simplify things by installing everything in C:\Programs<Name> avoiding the need for quotes. (Just noticed the specific temp dir on line 19, needs adjustment.)

Another challenge is the Java special use of backslash. Here is how I refer to a file in Processing, and what it actually is.

  String prime_file = "C:\\RDL\\Processing\\Sketches_Java\\Prime_Numbers\\Primes_4753000.csv";
  // C:\RDL\Processing\Sketches_Java\Prime_Numbers\Primes_4753000.csv";

On some occasions I’ve noticed that Windows will accept a path with forward slashes. I’ve never decided to make use of that, but it might be simpler.

Hope this lets you get things working.

1 Like

Thank you.
I am studying your code.
I have used a similar approach (exec function).
Here is my code (link for download): Demir_sketch - Google Drive
I have only implemented “Heat Transfer Test” yet.
…\Demir_sketch\Arduino\HeatTransfer\HeatTransfer.ino needs to be uploaded externally using Arduino.exe The program reads the analog signal from A0 (looping every 60 seconds)

At present I have 2 problems

  1. Although the code is the same as the others the ino file for “Heat Transfer Test” will not upload from the sketch as the others do.
  2. In the Heat Transfer window I want to save the space for the button and then restore it after the button is pressed. However I keep on saving the Main_sketch window.

Demir Bayka

@demir (sorry, been away from good internet.) I’ve had a quick look at your code, can’t run any as controlP5 won’t install on the PC I have with me. I can only suggest general techniques. 1. I suggest you swap the contents and/or names of the Ard files to identify if the problem is with the contents or name. I don’t see mySerial.stop to make Processing release the port while you load the Ard prog. Maybe you have Processing connected to one of the Mega’s other serial ports. 2. You have only 1 saveWindow, and that’s in setup, will only run once and do the same thing. (?) suggest you make a copy of the project, progressively delete other tabs, everything not involved in the problem. The answer will become obvious or you can post the remaining code.

I normally export the compiled binary in the Arduino IDE and then upload the resulting hex file.

Thank you for your reply.
I solved the problem but I’m not sure how.
I’m new to processing.
I normally use Borland Builder6 C++.
Before that Delphi4.0 (still using it for certain programs).
Before that Turbo Pascal (I have the impression that processing is similar)

I didn’t fell like a stranger when I started and I intuitively started compartmentalizing into tabs.
Again looking at examples I used << class PWindow extends PApplet… >>.
This resembled the “unit” in my Pascal and C++ code.

I localized <> and this solved the problem.
I can send my code, however I don’t exactly know how to do that on these platforms.

Demir Bayka

I am working on the code you sent.
The reason I’m using processing is that my C++ program uses windows serial communication procedures which increases my sampling time to nearly 1000 ms (safe). I have now been able to decrease this to approximately 100 ms (or less). I intend to use the Arduino as a cheap data acquisition and control platform for lab experiments. I will post my processing coding as mp4 videos to the students via youtube.

Hi @demir, glad things are working. Several method to post code, think easiest is: get code in paste buffer, click on </>, then paste. Interested to see link to your videos when ready.