Sending Serial Data To Arduino (Java)

Hey there!

I read through this topic and right now sending and receiving serial data via Serial Monitor is no problem at all.

But actually I want to send serial data to my arduino using Java. To do that, I am using the JSSC library. But for some reason my Arduino does not react to anything I send to it.

I think it might have something to do with the data that is sent. JSSC only offers to write Strings, Integers and Bytes, but my sketch is waiting for a char. Perhaps someone can tell me more.

Thanks!

P.S:

  • THIS is my Java source
  • THIS is my sketch

Hi Vulpecula

Please post your code using code tags (the </> button on the toolbar above the reply window). Many people won’t bother going to look at external links.

If you get a message about the code being too long, there is an attachments option below the reply window.

Regards

Ray

A common problem with PC programs is that the programmer does not allow time for the Arduino to reset after the PC program opens the serial port. It is also important for the PC program to keep the serial port open until it is completely finished using the Arduino.

I am not good with Java but I have used JSSC with JRuby. There is a JRuby program (as well as Python) in this demo.

…R

Many people won't bother going to look at external links.

In addition, many people (and I'm one of them) can't access rubbish bin. So, putting code there is a waste of time.

The Arduino IDE itself is written in Java, and it can communicate to the serial port via the RXTX Java library. That library is very similar to the Java Communications API extension. RXTX Java library is based on JNI (Java Native Interface, C extension). C is still killer program language.

One trick is install IDE will automatically installed RXTX Java library.

http://playground.arduino.cc/Interfacing/Java

One drawback is only support Windows, Mac, Linux. The BSD is out of luck ( or compile RXTX Java library extension yourself).

In your Arduino code, try setting the pins to output with pinMode() before writing to them.

sonnyyu:
The Arduino IDE itself is written in Java, and it can communicate to the serial port via the RXTX Java library.

Newer versions of the IDE use the newer (and better IMHO) JSSC library.

...R

Robin2:
Newer versions of the IDE use the newer (and better IMHO) JSSC library.

...R

Good catch, anything related to Assembly or C get me excited. :wink: