Show Posts
Pages: [1] 2 3 4
1  Using Arduino / Interfacing w/ Software on the Computer / Re: Serial communication with Java and Arduino Leonardo on: June 10, 2014, 02:15:57 am
I see! I removed that line from my code as it's just needed for the Raspi.

The Java program stops trying to connect if it already found a port to connect to. Look for the
Code:
break;
statement within the while loop.

I tried a few request-response cycles this weekend. Everything worked as expected. I'm so glad I switched to JSSC!
2  Using Arduino / Interfacing w/ Software on the Computer / Re: Serial communication with Java and Arduino Leonardo on: June 06, 2014, 08:10:14 am
However, I discovered that it wouldn't work if the serial port changed from ttyACM0 to ttyACM1 even though I added the extra option to the list on PORT_NAMES. And then I noticed a line with System.setProperty("gnu.io.rxtx.SerialPorts", "/dev/ttyACM0"); and when I changed that to ACM1 it would work with that and not with 0.

I'm not that familiar with the Linux handling of serial ports, but it seems that your Leonardo first appears with a certain port name, then disappears a little later and immediately reappears, but with a different port name.
If that's the case then it's normal because of the virtual port handling of the Leonardo: http://arduino.cc/en/Guide/ArduinoLeonardoMicro
On Windows, for example, I can see the Leonardo connecting on virtual port COM9, then it disappears and appears again on port COM10. In this case, COM9 is for the bootloader and COM10 for the sketch.

Where did you see the System.setProperty("gnu.io.rxtx.SerialPorts", "/dev/ttyACM0");?

3  Using Arduino / Interfacing w/ Software on the Computer / Re: Serial communication with Java and Arduino Leonardo on: June 06, 2014, 08:00:55 am
I have this suspicion as well.
I came across a third library during my research: http://mfizz.com/oss/rxtx-for-java
But it's quite old and only seems to be a fork of the qbang RxTx library for 64-bit support.

It's too bad that qbang.org has been down for a while now (and there's no sign of it to be up again soon). I haven't needed it yet, but according to the class names RxTx also seems to support Parallel, RS485 and I2C.
4  Using Arduino / Interfacing w/ Software on the Computer / Re: Serial communication with Java and Arduino Leonardo on: June 06, 2014, 02:38:27 am
I don't know which one existed before, but the Java part of RxTx and JSSC are very similar. The JSSC code ist more c-style (look at the mask handling).

However, in my first tests JSSC works perfectly with the Leonardo. Forgot to test it with a UNO though.
I wrote a sketch that responds with "pong" after receiving "ping" on the Serial port.
In the Java program I open the port, set the params and send the "ping". The "pong" arrives immediately.

If there aren't more/other problems in the long run, you can see my initial problem as solved.

Thanks for all your help!
5  Using Arduino / Interfacing w/ Software on the Computer / Re: Serial communication with Java and Arduino Leonardo on: June 05, 2014, 01:53:06 am
Isn't it always raining in the UK?  smiley-wink

I always looked at the port stated in the IDE or in the device manager in the Windows System panel and I'm convinced that I chose the right one as I'm able to send date to the Leonardo.

I downloaded the JSSC library instead of RxTx and tried out the "Hello World" example. I then added a SerialPortEventListener and printed all information concerning the event to the console.
I was actually able to see the String "test" in the Java console every second.
Today I want to try out some sort of handshake where the PC opens a port and sends some "ping" message and the Leonardo responds with a "pong".
By the way: Resetting was not necessary in my case, but somehow the Leonardo's port completely disappeared from the list of available ports after the first try. I could not get it to appear again until I plugged the board in a different USB port. But I guess that was just some Windows hiccup.

I'll post my progress with the JSSC library here.
6  Using Arduino / Interfacing w/ Software on the Computer / Re: Serial communication with Java and Arduino Leonardo on: June 04, 2014, 06:46:48 am
I've actually considered asking you for your code just to make sure it CAN work.
Besides, in my opinion the example code is just badly formatted. It just reduces to
  • get a Port object and open it
  • set params (baud rate, parity,...)
  • add listener
  • send/receive data
But maybe I'm just used to such code as I'm one of those "Java people"  smiley-wink

Unfortunately, the only way I know to talk to the (native) RxTx library is via the Java wrapper in the example. If you know a better way, please let me know.

I've also considered trying a different library. As far as the (very cooperative!) suggestions in this thread go, I'm more and more tending to ditch this lib because it seems I'm alone with this particular problem (in my particular setup).

Would you mind posting your JRuby code or a link where I can find it? I'd like to give it a try.
If it still doesn't work it's either a Windows (64-bit) problem or I have two defective Leonardos.
7  Using Arduino / Interfacing w/ Software on the Computer / Re: Serial communication with Java and Arduino Leonardo on: June 04, 2014, 12:42:19 am
Ok, For me it seems that with JRuby there is no issue when communicating with the Leonardo. (at least under Ubuntu)

I can see the Serial.println messages in the serial console of the Arduino IDE.
I try the shortcut for all of your "Have you..." questions: I'm using the example code from here
http://playground.arduino.cc/Interfacing/Java
which opens a serial connection as well as a BufferedReader for incoming messages (Arduino --> PC) and an OutputStream for outgoing messages (PC --> Arduino). This example code perfectly works with an Arduino UNO.
Hence, although most of the code you are asking for is under the hood, I can confirm that there is code that is notified if there is incoming data, gets the received bytes and fires an event if the message is complete.
I'm implementing the appropriate EventHandler and print all information available to the console.

You say your TX LED is blinking when you send data from the Leonardo to the PC. In my case it's doing nothing. I tried it with two differend boards. Only the RX LED is blinking when I send messages from the PC to the Leonardo.

Maybe it's a driver-related issue?

I have an old 32-bit laptop with a Fedora 20 installation. I'll have a look if it works there.
8  Using Arduino / Interfacing w/ Software on the Computer / Re: Serial communication with Java and Arduino Leonardo on: June 03, 2014, 10:16:14 am
In my JRuby code I did the reset thing (open at 1200 baud and close), waited 10 secs for the Leonardo to go through the reset process and then my JRuby code opened the serial port at the baud rate that Serial.begin(bbb) uses.

I can open a connection at 1200 Baud and close it immediately. The Leonardo resets as expected.
Then I'm waiting 15 seconds before going on opening the port again at 9600 Baud.

The Leonardo is constantly sending data (Serial.println("test")smiley-wink in a one second interval.
However it never reaches my program.

Can you confirm that you are actually able to send data via Serial.println from the Leonardo and receive it at the PC?
Is there an RX or TX LED blinking while your Leonardo is sending data to the PC?
9  Using Arduino / Interfacing w/ Software on the Computer / Re: Serial communication with Java and Arduino Leonardo on: June 02, 2014, 04:57:37 am
This is a very useful information for me! I always wanted to know how to soft-reset the Arduino.

So you think my problem is related to an "unreseted" board?
If so, should a hardware-reset (pressing the reset button) do the trick as well?
When I tried the serial communication with a Java program, I first connected the Arduino and then started the Java application which listens to the Arduino.
At which point should I reset the Leonardo?
10  Using Arduino / Interfacing w/ Software on the Computer / Re: Serial communication with Java and Arduino Leonardo on: June 02, 2014, 12:26:50 am
I'll give it a try in the evening.

When I upload the Leonardo sketch to the UNO everything works (Ardulink and Serial communication in both ways).
So there must be an issue with the Leonardo. The Leonardo has a different IC than the UNO, Duemilanove,...

Maybe it handles serial communication differently?

11  Using Arduino / Interfacing w/ Software on the Computer / Re: Serial communication with Java and Arduino Leonardo on: May 30, 2014, 12:41:32 pm
Well, I can send messages from Ardulink TO the Leonardo, but I don't get any data FROM it.
I tried connecting the wire from pin 11 to 13 but if I turn on pin 13 I still get no feedback.

I assume it worked for you with a Leonardo. So I guess it's not a problem with the Java program or the sketch.
Maybe it's a Windows and/or 64-bit issue!?
You said you are running on a Ubuntu machine. Is it 32 or 64 bit?
12  Using Arduino / Interfacing w/ Software on the Computer / Re: Serial communication with Java and Arduino Leonardo on: May 30, 2014, 04:01:12 am
Ardulink works now.
The LED on pin 13 turns on and off as I press the button on the switch panel.

However, if I go to the digital sensor panel and turn on the sensors I get no feedback.
I tried it with two Leonardo boards.
13  Using Arduino / Interfacing w/ Software on the Computer / Re: Serial communication with Java and Arduino Leonardo on: May 29, 2014, 09:53:37 am
Is there a 64 bit version?
I get the error "Can't load IA 32-bit .dll on a AMD 64-bit platform" if I click on the Discover button.
14  Using Arduino / Interfacing w/ Software on the Computer / Re: Serial communication with Java and Arduino Leonardo on: May 29, 2014, 09:14:03 am
I just tried adding while(!Serial); int the sketch and several Thread.sleep in the Java program.
Unfortunately, that did not change a thing. I still can't receive any data and the TX led is not blinking (should it anyway?).

Are there any other things I should try?
15  Using Arduino / Interfacing w/ Software on the Computer / Serial communication with Java and Arduino Leonardo on: May 27, 2014, 02:13:34 pm
On my Arduino UNO the example here
http://playground.arduino.cc/Interfacing/Java
works just fine.

Here is my Arduino Code:
Code:
void setup() {
  Serial.begin(9600);
  //Serial1.begin(9600);
}

void loop() {
  Serial.println("ping");
  //Serial1.println("ping1");
  delay(1000);
}

The Java code is the same as in the example. I only changed the PORT_NAMES variable to the COM Port of the Uno (in my case it's COM7).

If I upload the code and run the Java program, I get the following output:
Code:
WARNING:  RXTX Version mismatch
Jar version = RXTX-2.2pre1
native lib Version = RXTX-2.2pre2
trying to connect to port COM7
Started
ping
ping
...

Which is what I expected.

However, if I upload the code to the Leonardo the Java program apparently does not receive any messages.
I have changed the PORT_NAMES variable to the COM Port of the Leonardo (COM9).
I even tried to uncomment the lines that use Serial1.
I can however, receive data sent from the Java program to the Leonardo.

I noticed that if I send data from the Java program to the Leonardo, the RX led blinks. However, if I send data from the Leonardo RX and TX leds are off.

Why does sending data from the UNO to the PC work, but not from the Leonardo?
Pages: [1] 2 3 4