Serial monitor question

I have a question. First what I have: 1x Arduino Mega 1x Ping 1x Macbook Pro with Mac OS 10.6 Arduino IDE with serial monitor. Eclipse C/C++ and Java (no libs/plugins whatever installed)


What I want to do is the following: I want to read the sensors value on my laptop, this can be done by the serial monitor. However, I cant do anything with this data so far. I know what to do: - make a connection with Eclipse to my Arduino. simply read raw data from the usb port, which is basically a serial port. - play with that from there on.

But I haven't got a clue how I should fix this. I know that I have to import a libraryu or some plugin. But I cant find the data to do this.


What am I looking for? Someone that tells me how to setup eclipse (or any other IDE) so that I can run software and read data from the Arduino.

I have looked into the rxtx.org website but when I put the .jar files in the extensions folder, I cant upload any files to my arduino anymore.

I really, really! need this. When this thing is setup I can manage on my own, but Im just not that good in setting up a IDE for a new Hardware platform without tutorials XD

Any help is welcome! Just leave a comment with a tip or a question. it'd really help me (:

With kind regards Machiel Veldkamp Student.

I have found something: http://silveiraneto.net/2009/03/01/arduino-and-java/

this is what I need but I cant get the rxtx installed. Could someone help me with this?

Wow, I have come very far!
Now I have setup eclipse almost 100% (I think)
However:

Using port: /dev/cu.usbserial-A9007LhO
java.lang.UnsatisfiedLinkError: /Users/machielveldkamp/Documents/workspace/NNR/librxtxSerial.jnilib:  no suitable image found.  Did find:  /Users/machielveldkamp/Documents/workspace/NNR/librxtxSerial.jnilib: no matching architecture in universal wrapper thrown while loading gnu.io.RXTXCommDriver
Exception in thread "main" java.lang.UnsatisfiedLinkError: /Users/machielveldkamp/Documents/workspace/NNR/librxtxSerial.jnilib:  no suitable image found.  Did find:  /Users/machielveldkamp/Documents/workspace/NNR/librxtxSerial.jnilib: no matching architecture in universal wrapper
      at java.lang.ClassLoader$NativeLibrary.load(Native Method)
      at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1861)
      at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1778)
      at java.lang.Runtime.loadLibrary0(Runtime.java:823)
      at java.lang.System.loadLibrary(System.java:1045)
      at gnu.io.CommPortIdentifier.<clinit>(CommPortIdentifier.java:83)
      at serialtalk.Main.main(Main.java:16)

Yeah, havent got a clue…

What does this mean and how can it be solved?

I don't know eclipse, maybe someone else will help with that.

When I want to work with arduino data on the pc i use "processing" which is an ide for and written in java, very similar to and easy to use with arduino.

When I use the same code in 'processing.app', I get another error:

exception in thread "main" java.lang.RuntimeException: java.lang.ClassCastException: Main cannot be cast to processing.core.PApplet at processing.core.PApplet.main(PApplet.java:6686) Caused by: java.lang.ClassCastException: Main cannot be cast to processing.core.PApplet at processing.core.PApplet.main(PApplet.java:6684)

How are we supposed to help you with code issues if you don't post the code?

Good point:

import gnu.io.CommPortIdentifier;
import gnu.io.SerialPort;
import java.io.InputStream;
import java.io.OutputStream;
import processing.app.Preferences;

public class Main {
    static InputStream input;
    static OutputStream output;

    public static void main(String[] args) throws Exception{
        Hack.init();
        System.out.println("Using port: " + Preferences.get("serial.port"));
        CommPortIdentifier portId = CommPortIdentifier.getPortIdentifier(
                Preferences.get("serial.port"));

        SerialPort port = (SerialPort)portId.open("serial talk", 4000);
        input = port.getInputStream();
        output = port.getOutputStream();
        port.setSerialPortParams(Preferences.getInteger("serial.debug_rate"),
                SerialPort.DATABITS_8,
                SerialPort.STOPBITS_1,
                SerialPort.PARITY_NONE);
        while(true){
            while(input.available()>0) {
                System.out.print((char)(input.read()));
            }
        }
    }
}

and

import processing.app.Preferences;

public class Hack extends Preferences
{
      public static void init()
      {
            Preferences.init("/Users/machielveldkamp/Library/Arduino/preferences.txt");
      }
}

In Processing, select File + Examples + Libraries + Serial. There are several examples of communicating with the Arduino. Try some of them before writing your own code.

Pay particular attention to the fact that [u]you[/u] do not define a main function.

I'm a newb too so I can't offer a whole lot of technical assistance but can just offer some encouragement. You're on the right track. Keep reading, researching, and experimenting. Youtube is a great resource too. Like Paul says, use the basic sketches that come with Arduino and Processing and then you can begin to experiment with changing how the data is both sent and received.

What it is you are trying to make and/or accomplish?

It looks like to me that someone broke the backwards compatibility of the Java example posted on the arduino.cc wiki (arduino.cc/playground/Interfacing/Java). I had the exact same problem.

Just so that others searching for the answer to the exact same problem can find an answer, you should forget what you saw in the wiki. It's horribly broken with the latest Arduino development environment.

Try this code instead:

import gnu.io.CommPortIdentifier;
import gnu.io.SerialPort;
import java.io.InputStream;
import java.io.OutputStream;

public class Test {
      public static void main(String[] args) throws Exception{
            SerialPort port = (SerialPort)CommPortIdentifier
                        .getPortIdentifier("COM3").open("serial madness", 4000);
            InputStream input = port.getInputStream();
            OutputStream output = port.getOutputStream();
            port.setSerialPortParams(
                        9600, // 9600bps
                        SerialPort.DATABITS_8,
                        SerialPort.STOPBITS_1,
                        SerialPort.PARITY_NONE);
            for(;;) {
                  while (input.available()>0) {
                        System.out.print((char)(input.read()));
                  }
            }
      }
}

Since there is no run.bat included with the software anymore, I also had to do the following.

  • Add RXTXcomm.jar from the Arduino environment to the classpath
  • Add rxtxSerial.dll from the Arduino environment to the PATH

This worked for me on Windows. You can do the equivalent for other platforms.

Basically, what's provided by the Arduino development environment is a JNI interface. My source code example above does hard code the COM port and bit rate, but at least it doesn't require me to copy the whole GNU based Arduino development environment into my workspace.

java.lang.UnsatisfiedLinkError: 
/Library/Java/Extensions/librxtxSerial.jnilib:  
no suitable image found.  
Did find:  
/Library/Java/Extensions/librxtxSerial.jnilib: no matching architecture in universal wrapper thrown while loading gnu.io.RXTXCommDriver

Exception in thread "main" java.lang.UnsatisfiedLinkError: /Library/Java/Extensions/librxtxSerial.jnilib:  no suitable image found.  Did find:  /Library/Java/Extensions/librxtxSerial.jnilib: no matching architecture in universal wrapper

Sooo..... what?

It looks like you're on Mac OS X.

Maybe this will solve your problem: http://arduino.cc/en/Guide/Troubleshooting#macupdate

I got a similar error on my 64-bit Windows. I had to use a 32-bit JDK.

Arduino IDE works perfect, but what I want to do requires Eclipse or some other IDE.

And that's where I have this error. Also, read THIS if you want to know what and how I am using this...

Machiel,

You get the error, because java is trying to find a 64bit-version of the native library, which is not availble. Run your Java VM in 32bit mode using the -d32 switch when launching your program.