Can I code a small java application to commuincate with my arduino? How?

I'm pretty sure it's possible, but I was wondering if it can be done. I recently got into Java and I've learned a lot. The other day I had the idea that I'd see if I can create a java applet to let me cotrol which LED's turn on and off through my Arduino. Any help is appreciated :)

The answer is an unqualified yes. The Arduino IDE itself is an example of such an application -- it is a Java app that communicates with an Arduino and tells it what to do.

The question you have to figure out is how you want to connect the computer that runs Java to the Arduino. Will you use a serial port? ethernet shield? Infra-red signaling? Smoke signals?

Where will you run your Java application? On a PC? a mainframe? an embedded system? a server? And what connectivity options exist on the Java end?

tbaldwin102: I'm pretty sure it's possible, but I was wondering if it can be done. I recently got into Java and I've learned a lot. The other day I had the idea that I'd see if I can create a java applet to let me cotrol which LED's turn on and off through my Arduino. Any help is appreciated :)

Easiest is to use the serial port. You can write a sketch that reads from the serial port, and writes to the output ports based on what it reads -- this is fairly simple. Then, open a serial port from Java, just like the Arduino IDE does, and write commands to the board while it's running. The commands will go over the USB-serial connector and be available to your sketch running on the board.

There are, of course, many more advanced ways of doing these things, but I think such a simple sketch would be a great start.

Java has a serial port class that you can use to read and write to the virtual COM ports. You would need to either hard-code the COM port number for your Arduino, or find a way to work out what is attached to which port. It looks as if WMI provides enough information to do that, but there might be easier ways to do it.

One possible issue - if you're planning to implement this as an applet, I suspect the sandbox will keep you away from host devices. As an application, there would be no problems.

If you're thinking of doing whatever-it-is with an application, you could also implement it in JScript and run it as an HTML app, or server-side code in your web page, or any of the other endless ways there are to run the script engine.

gardner: The answer is an unqualified yes. The Arduino IDE itself is an example of such an application -- it is a Java app that communicates with an Arduino and tells it what to do.

The question you have to figure out is how you want to connect the computer that runs Java to the Arduino. Will you use a serial port? ethernet shield? Infra-red signaling? Smoke signals?

Where will you run your Java application? On a PC? a mainframe? an embedded system? a server? And what connectivity options exist on the Java end?

I connect my Arduino through my PC's serial port. As for the Java script, it will be running on the same computer. I'm basically trying to figure out how I can write the proper code to allow my Java script to communicate with my Arduino.

tbaldwin102: I connect my Arduino through my PC's serial port. As for the Java script, it will be running on the same computer. I'm basically trying to figure out how I can write the proper code to allow my Java script to communicate with my Arduino.

On the Arduino side, or the Java side, or both?

tbaldwin102: I connect my Arduino through my PC's serial port. As for the Java script, it will be running on the same computer. I'm basically trying to figure out how I can write the proper code to allow my Java script to communicate with my Arduino.

You're asking how you should go about writing your Java application?

Hi. Had similar issue. Know a little Java, next to no Arduino. Spent some time looking through Java forums. A number of posts there were useful with large chunks of code which pretty much solved the problem, together with a bit of trial and error.

PeterH:

tbaldwin102: I connect my Arduino through my PC's serial port. As for the Java script, it will be running on the same computer. I'm basically trying to figure out how I can write the proper code to allow my Java script to communicate with my Arduino.

You're asking how you should go about writing your Java application?

Basically, I just don't know what commands to use to get the two to communicate. I just want to learn how I can have the Arduino read from the connection while the java script does the writing part. The java script will only be changing a few boolean values in the Arduino's code so the Arduino can change which LED's light up accordingly.

Not sure if you've looked here yet, but it's certainly interesting! http://www.arduino.cc/playground/Interfacing/Java