Go Down

Topic: Newbie - Java Question (Read 1 time) previous topic - next topic

davijeb

Hi,

I'm a Java developer by trade and have recently started looking to program the Arduino board. Have written a small app that connects to the board over the USB port.

One of the examples on the Arduino app itself was the simple blinking LED on pin 13. So I thought that would be a good place to start trying to write in Java.

And that's my question. Is this easy to do? Do I have to worry about setting up some native calls and/or compiling into C/C++ to actually achieve this.

As I said I'm very new to this and thought I'd pose this question to get a few pointers as to how I could achieve this simple test.

Many thanks,

Jez


PeterH

I'm not clear whether you'rehoping to develop a Java application to talk to an Arduino, or write some java that runs on the Arduino.

The Arduino IDE uses a language called Processing, which is essentially a subset of 'C'/C++ with some extra munging to take care of prototype declarations and library dependencies. As you know, C++ is a block structured language with a syntax very similar to Java. The further changes from C++ to Progressive actually make it even more similar to Java. I expect you'll find that after looking at the example sketches you will find the transition very easy.

cmiyc


One of the examples on the Arduino app itself was the simple blinking LED on pin 13. So I thought that would be a good place to start trying to write in Java.


Write what?  The Arduino runs C++ code complied with avr-gcc.  That complied hex is loaded into the ATmega's program memory (aka flash) with a utility called avrdude over a virtual serial port.  The micro is reset and it starts running.

I'm confused how you writing something in java fits in there.
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

Techone

@davijeb

I am trying to figure what your are trying to do... A Java to program the Arduino : the Arduino IDE is doing just that. The IDE is base on Processing, which Processing is base of JAVA, but to program the Arduino using it IDE, it base of C++. The easiest way to use "java" to communicate with the Arduino board is to use Processing. http://www.processing.org. Processing got the import files ( import processing.serial.*; ) to communicate with the Arduino and an Arduino library for direct control.


davijeb

Hi,

Thanks for all the replies. On reading my question again I can see the confusion.

The project I'm working on involves the use of the Arduino board to control a series of motors and sensors. I've already written an app (Java) that will be used to control this and now am looking to understand how to code the actual Arduino interface. As I already have the serial connection then I thought "great, I'll just send the board a sequence of packets, telling it what to do". That was the reason for my simplified "blinking LED" question. I assumed that once I'd worked that bit out I'd be able to figure out the rest.

In essense this is what I'd like to do:

Code: [Select]
public class MyBlinkingLED {

   public MyBlinkingLED() {
   ...
   // connect to the board using the RXTX libs
   ...
   flashASingleLEDWithFrequencyOfOneSecond()

   }

   private void flashASingleLEDWithFrequencyOfOneSecond() {

        final int pin = 13;

        // ???

   }

}


Will take a look at the Processing code too as I've not had a chance yet.

Thanks,

Jez




PaulS

Quote
Will take a look at the Processing code too as I've not had a chance yet.

Won't do any good, since Processing is Java, and the Arduino is NOT programmed using Java.

The art of getting good answers lies in asking good questions.

davijeb


PaulS

Quote
What do you suggest?

Learning to program in C/C++. There are plenty of examples provided with the IDE for simple things like blinking an LED.

There are also examples of sending/receiving serial data. Once you can do that, the Arduino can then be made to operate on the serial data in whatever way you like.

The art of getting good answers lies in asking good questions.

davijeb

Quote
Learning to program in C/C++

That did make me chuckle. I did just that in the mid to late 90's writing quant libraries for various investment banks in London/New York  :)

Looks like I'll have to dust off my Meyers and take another look.

Thanks for the pointers.

Go Up