How to load HEX file into Arduino in Java?
I want to upload a finished HEX file to the Arduino board. How can I do this in Java code?
Should I implement the STK500 protocol in Java? Are there any working solutions or examples in Java?
PS. I found an implementation of STK500 in Erlang , but I don't know.
+3
source to share
2 answers
The wheel exists. Use the wheel.
Download from Java using the excellent AVRdude.
/*
A command line looks like this in a stock Arduino IDE:
D:\arduino-dev\arduino-1.0.3\hardware/tools/avr/bin/avrdude
-CD:\arduino-dev\arduino-1.0.3\hardware/tools/avr/etc/avrdude.conf
-v -v -v -v -patmega328p -carduino
-P\\.\COM8 -b115200 -D -V
-Uflash:w:e:\Temp\build100458372319682483.tmp\Blink.cpp.hex:i
Just write the binary to the .HEX file and let the dude upload it:
*/
String hexfile = "e:\somefolder\Blink.cpp.hex";
String exefile = "D:\arduino-dev\arduino-1.0.3\hardware/tools/avr/bin/avrdude";
String conffile = "D:\arduino-dev\arduino-1.0.3\hardware/tools/avr/etc/avrdude.conf";
String opts = " -v -v -v -v -patmega328p -carduino -P\\.\COM8 -b115200 -D -V ";
String cmd = exefile +" -C"+ conffile + opts +" -Uflash:w:" + hexfile +":i";
Process proc = Runtime.getRuntime().exec(cmd);
int retcode = waitFor(proc);
+1
source to share