Go Down

Topic: How to upload ready HEX file using processing or java? (Read 1 time) previous topic - next topic

4ntoine

I'd like to upload ready HEX file to Arduino board. How can i do that in java code?
Should i implement stk500 protocol in java? Are there any working solutions or examples in java? Thank a lot!

PS. I've found stk500 implementation in Erlang (https://github.com/msantos/stk500) but i don't know it.

pylon

You can call avrdude from java. Why do you need to circumvent avrdude? You need native code anyways (for accessing the serial interface), so why don't you wanna use avrdude?

4ntoine

#2
Jan 30, 2013, 06:07 pm Last Edit: Jan 30, 2013, 06:10 pm by 4ntoine Reason: 1
The idea was to upload Arduino sketch right from Android device via USB, Ethernet or Bluetooth.
I can use native code using NDK but it should be not console app and it's not good to use arch-dependent code in java app in general.

I tend to write stk500 implementation as it seems to be pretty simple protocol.
But i agree that it's better to use smth ready and bugs-free instead of reinventing the wheel.

So what do you think about it?

PS. Serial interface is available in java code too

pylon

Quote
PS. Serial interface is available in java code too


Interfaces: yes, but you don't have support for it in the JVM, you need an external native library (like RXTXcomm or javax.com, but javax.com is available only on Unix platforms). To be a little picky: Dalvik (the vm for running code on Android) is not Java.

I guess, to emulate avrdude on Android and update Arduinos over Ethernet or Bluetooth, stk500 is not your biggest challenge.

4ntoine

#4
Jan 31, 2013, 02:30 pm Last Edit: Jan 31, 2013, 02:37 pm by 4ntoine Reason: 1
Okay, let's say i already know how to pass bytes array to bootloader (via Serial, Bluetooth, Ethernet, etc, etc). Serial at least for sure.
Uploading via Bluetooth example:
http://www.youtube.com/watch?v=i-69D0iDVxE

The problem is how to interact with it in optimal way..

pylon

So you're uploading via Bluetooth and hit the reset button when your upload is ready? Why do you need it to be wireless then?

4ntoine

No, it's just a proof of concerns that compiled sketch can be uploaded via Bluetooth too. Let's leave the question about transport: usb, serial, bluetooth, ethernet - anyway.
The goal is to "talk with bootloader". So the question is "is there smth useful that can be used in java (Android to be exact) to help to do it".

One idea suggested was to use avrdude and it has few drawbacks like arch-dependency. And it's pretty difficult to integrate it into java app as Process.exec() is not supported in Android.
So it will be necessary to change avrdude code to use streams instead of file input and serial output. Does anyone want to do it?

Another idea is to implement stk500 in pure java code by myself.

Any suggestions, anyone?

pylon

Keep in mind that Arduino is using something similar to stk500 but it's not identical. If you implement it yourself take a look at the C implementation in avrdude.
Also keep in mind that not all Arduinos are using that protocol. For example the Leonardo or the Mega2560 are using another protocol for the upload. If you stay with UNOs and compatible you're fine with a slightly adapted stk500.

4ntoine

#8
Feb 01, 2013, 12:35 pm Last Edit: Feb 01, 2013, 12:36 pm by 4ntoine Reason: 1
I've found smth useful here (protocols for boards):
http://arduino.cc/en/uploads/Main/boards.txt

Stk500 protocol description can be found at:
http://www.atmel.com/Images/doc2525.pdf

I will use avrdude code and erlang impl too.
Thank you, pylon!


Go Up