Interfaceing with java (newbie)

Hello,
I recently got my first arduino (Duemilanove) and i got trugh a few tutorials on lighting LED's and funn stuff like that.
What i wan't to do now is write my own java application that would send commands to arduino.
I realize this was done before and i found lots of forum discussions on how to do it, but problem is i don't seem to have enaugh experience to suessfuly complete any of those guides.

So i figured, what better place to go get help then the arduino forum it self.
I read about using Libraries of the arduino softwere and all that but i realy need a newbie guide and a simple explanation on what it does and how does it work.

I would like to get it working on windows 7 on Eclipse if possible.
So if any of you ever done this before please give me some guidelines on where to start, cause at the moment im LOST :cry:

for now i got as far as sending strings from arduino's softwere serial monitor and made arduino respond to those string acrodingly + lighting some LED's on the way.

Best regards

If you want to develop this application in java, may we presume that you are familiar with java? Do you know how to make java connect to a serial port? Do you know how to make java write to/read from the serial port?

Hey,
I've done some programming with java but never something like this.
I've done some aplications with sound analizing and java 2D
And lots of sorting algirithms in school. A bit of parallel programming(thread synhronization, bariers,..)
But connectiong to a serial port and writing/reading on/from it is actualy what i need. Arduino can alrady pickup any data on the serial port..problem is getting that data on it with java and reading from it..

Short verison:
Im afraid we can not make that assumption :frowning:

Thanks for the reply light of hope has turned on :smiley:

Hi,

Have a look at Processing. The Arduino IDE is based on this technology.

It takes all the pain out of it, it also generates an executable JAR file that you can run on Windows (as long as Java is installed).

It also has script examples for serial comms to an Arduino, and even shows you what the Arduino counterpart should be.

Thanks, altugh its not realy java but i could get it working.
But somehow i can't seem to find the tutorial you mentioned about comuncting with arduino..

The point of using java is platform indipendence.
And i've done some work in it before so i got most of my aplication alrady prepared.
Is it realy that hard to make arduino talk to java aplication ? :-X

Processing is java with some libraries.

Check here:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1283939295/2#2

You can take the sketch in Processing and drop it in Eclipse and add the import statements and you have yourself an applet or application.

Or since you have your app written you can just add the import statements, look at the example serial code and off you go.

I'm building an app right now to graph the signals coming from the arduino with ability to manipulate signals, etc.

I got started by looking at this example:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1245723011/15#15

aplication and aplet are very diferent in my case but ok.
Maybe im getting this the wrong way but isn't processing a programming language? I cant prgram in both java and processing at the same time :o
I'll give it a try tough and thanks for the info :slight_smile:
I'll let you know when i get stuck ! ;D

Thanks!

I think the processing.org site doesn't state very clearly that it's java but it is.

When you use the processing library, and their IDE, it limits how you can do the graphics.

I don't think it's a problem for you could build your own AWT or Swing app and import the processing library to do the communication and such.

So far, I went ahead and used the processing way to do all the graphics and such. It's pretty nice but since I use Eclipse, I can use java 1.5 or 1.6 stuff. The processing ide only supports 1.4. The biggest deal for me is having generics in 1.5 & greater.

Read their FAQ:
http://wiki.processing.org/w/FAQ#Why_Java.3F_Or_why_such_a_Java-esque_programming_language.3F

I did the folowing guide on Eclipse and processing and got as far as this.
It apparently works but i realy don't get the idea of processing.
Its a black screen on witch i can draw.
I guess i'll try to connect it with arduino.
And i read i need to upload Firmata on my arduino is that rite?

Oh and 1 more thing...after completing an aplication in processing.
How can such an aplication be compiled to an easy to use executable..
What im doing here is for people with no computer knewledge so running a console and stuff is out of the question.
Any ideas? :smiley:
Thanks for the help.

You don't need to load firmata on your arduino.

All you are essentially doing is running java app or java applet and communicating over Serial or something else to your arduino.

If you are using the Processing IDE you can export it as an app.

But, if you are using eclipse you just need to package up the java class files as a jar and execute as: java -jar .jar

You can make a batch file and launch it that way. I assume you'll be putting it on people's computers if they have no computer knowledge.
I think you can also double-click on a jar file and it will execute.

I don't get the point of Firmata but i'll keep reading.
What would solve my provlem is a simple code that sends a string or anything to arduino and arduino's code to respond witch is not a priority..
It should be sooo simple but i can't get it working :slight_smile:

I think I'll be going full with Processing since it appears easy to use and can be exported as an app.
Basicly i'm trying to do is set my arduino to listen to serial port.
Make an aplication that would alow the user to send RGB (hex) value to arduino.
Once arduino gets the value it should change the RGB led acordingly.

Thanks!

Check here. It graphs the data in real time from the arduino board.

http://www.glacialwanderer.com/hobbyrobotics/?p=261

Thanks for that graphing example oscarcar.

I find the concept of graphing live data fascinating!.

Thanks for the graphing example it helps :slight_smile:
I would like to make an ambient light for my PC
I was thinking of making sreenshoots as fast as posible and calculate the avrage RGB value of each image and send it to arduino to color the LED's acordingly.
Am i thinking the wrong way? is there a nother method that's somewhat faster or less consuming (CPU) to get the avrage RGB value??

I was thinking on making the sreenshots in jpg format with LOW resolution to make it less consuming.
Can screenshooting like this be done in processing?
I failed to find any examples yet..

Thanks for everything ! :smiley:

I don't know, you'd have to look at the reference page to see what could easily be done.

You could also put a light sensor up to your screen with one for each color. That all could be done directly on the arduino though.

Is the entire image the same color? Or do you want the average of an entire complex picture?

It needs to be the avrage cause i want to play movies and stuff so my LEDs need to light the colors acordingly.
It would actualy mean i would need the avrage of sreenshot i take
Offcourse it wouldn't be full resolution but an aproximate value would come out of it.
I would like to do it with sreenshots so i don't need to depend on the video player..whatever player or program is cool.
If i do an aplication with processing for playing videos its easyer but then the user must use my softwere and only play formats my softwere supports witch is a big downside.

Do you have a way to do that in Java?

I'm thinking videos might be difficult since hooks often aren't provided for this by the OS cause of DRM.

You could try communicating with VLC and java.

You could also possibly write a program to analyze an entire movie and write out the RGB values to a file and play the file to control the arduino, and play the movie back at the same time.

Comuncating with VLC would be cool but i think its dificult to do..
Now making a softwere to build a txt file of rgb values (like movie subtitles) could be done. But i would still need to comunicate with the player to get the current time of the movie.
Rgb lighits would have to change acording to the movie time (like subs)
and comunicating with the player is again hard (i think).
Thats why i was thinking of doing it on the fly..so the user can still forward or stop or do whatever else with the movie and it wouldn't confuse arduino.

Well, I guess you'll need to start by seeing if you can find some way to get a screen capture of the video playing window. Either directly in java or using another program to write it to a file and load the image in java.