Sending serial data to Uno via Java. Code works on Uno R3 but not on Mega2560

Hello World!

I have been struggling with this issue for a while.
I have a simple arduino sketch reading incoming serial data and turning an LED on and off if a character "L" is received.
Im using a Java program (jSSC library) to send characters to arduino via USB. The code works beautifully if I use arduino UNO r3.

If I replace Uno with Mega 2560 (same setup, same sketch uploaded), the LED wont turn on and off when I send "L" using Java. However, If I send "L" to the board via Serial Monitor (arduino IDE), the LED turns on and off like it is supposed to.

Any ideas of what is going on?

Much thanks!!!!

Could your Java program be sending to the wrong serial port?

I dont believe so. Here is a section of a Java code where I establish serial connection (pretty much copied straight from jSSC example posted online);

SerialPort serialPort = new SerialPort("COM10");
        try {
            serialPort.openPort();//Open serial port
            serialPort.setParams(SerialPort.BAUDRATE_9600, 
                                 SerialPort.DATABITS_8,
                                 SerialPort.STOPBITS_1,
                                 SerialPort.PARITY_NONE);//Set params. Also you can set params by this string: serialPort.setParams(9600, 8, 1, 0);
                   
        
        
        }
        catch (SerialPortException ex) {
            System.out.println(ex);
        }

Im pretty sure that Im connecting to the right serial port. My arduino Uno is on "COM8" and Mega is on "COM10" (i verify this in device manager). Before running Java code I modify that very first line. I dont change data bits or stop bits or parity parameters though.

In addition, when I run Java program, the RX LED on the board is flashing..... but nothing is happening. And the code works perfectly with Uno...

Thank you very much for responding! What else could be wrong?

If the RX light is blinking the data is getting to the processor... Perhaps it is time to show your code. Maybe someone can spot code that could cause a problem on a MEGA.

Have you the Mega and the Uno connected at the same time?

I haven't used Windows for years so forgive me if this does not apply ....

If you only have the Uno connected and communicating with the Java code and then plug out the Uno and replace it with the Mega will the PC see it attached to the same port so that the same Java code will work?

I'm pretty sure I have communciated with an Uno and Mega using JSSC (I'm using JRuby on Ubuntu).

...R

Robin2:
Have you the Mega and the Uno connected at the same time?

I haven't used Windows for years so forgive me if this does not apply ....

If you only have the Uno connected and communicating with the Java code and then plug out the Uno and replace it with the Mega will the PC see it attached to the same port so that the same Java code will work?

I'm pretty sure I have communciated with an Uno and Mega using JSSC (I'm using JRuby on Ubuntu).

...R

Hey Robin2!
Im still struggling with this issue. Im only connecting one board at a time.

So here is a procedure that im following
Arduino Uno:
1)uploaded Blink LED example to test if pin13 works: works!
2)uploaded a code that uses Serial.read() command to search for "L" character and turn led on and off.
3)sent "L" to arduino via Serial Monitor (Arduino IDE). LED works!
4)Went to a device manager and found the port name my arduino is plugged in: "COM10"
5)Edited java code so that it sends stuff to "COM10".
6)Ran Java. Java sends "L" using this section of code (jSSC library)

try {
                        serialPort.writeString("L"); 
                    } catch (SerialPortException ex) {
                System.out.println(ex);
                    }

and it works!!!

Arduino Mega 2556
1)uploaded Blink LED example to test if pin13 works: works!
2)uploaded a code that uses Serial.read() command to search for "L" character and turn led on and off.
3)sent "L" to megavia Serial Monitor (Arduino IDE). LED works!
4)Went to a device manager and found the port name my arduino is plugged in: "COM11" (note different port)
5)Edited java code so that it sends stuff to "COM11".
6)Ran Java. Java sends "L" using this section of code (jSSC library). DOESNT WORK!!!!

I found 1 more Uno and 1 more MEGA board and repeated this. It worked on the other UNO and didnt work on the MEGA..... what is going on?

I'll see if I can try it with my Mega later.

... Later ...

I have a JRuby with JSSC program that I used to test something for a project in another Thread. It sends an S Cr Lf sequence to the Arduino which responds with :nnn where nnn is a sequential count.

It worked completely unchanged on my Mega. I just plugged out my Uno, plugged in the Mega and uploaded the sketch. And started my JRuby program and it just worked.

I'm using Ubuntu 12.04 and "java version 1.7.0_17". I have the Java JDK installed.

...R