title: Arduino - Processing bidirectional communication can't receive data via serial
body: <p>I'm trying to communicate arduino with java using jssc. Just for testing I'm trying to receive the data on Arduino and sending back to PC, pretty straight forward. The problem is, board seems to not receive it. When a code for arduino to just send, works fine, but it just can't receive any data. I first thought the problem was jssc, so I change my application to Processing, same problem. I even try to change the board, no diference, the board is fine and it can communicate normally with Arduino Serial Monitor. So my problem must be the Java and Processing code. I know its a very simple problem, and i'm kind of ashamed for posting this, must be a very simple problem that past me.</p>
  
  <p>One more thing, no errors at all is shown</p>
  
  <p>Java code:</p>
  
  <pre><code>public class ArduinoTest{
      public static void main(String[] args) throws SerialPortException, InterruptedException {
          SerialPort serialPort = new SerialPort("COM6");
          serialPort.openPort();
          serialPort.setParams(SerialPort.BAUDRATE_9600,
                  SerialPort.DATABITS_8,
                  SerialPort.STOPBITS_1,
                  SerialPort.PARITY_NONE);
          int i;
          serialPort.writeBytes("a".getBytes());
          while(true){
              a=serialPort.readBytes(1);
              i = a[0] &amp; 0xff;
              System.out.println(i);
          }
      }
  }
  </code></pre>
  
  <p>Processing code:</p>
  
  <pre><code>import processing.serial.*;
  
  Serial port;
  int r;
  void setup(){
    port = new Serial(this, "COM6", 9600);
    port.write(1);
  }
  void draw(){
    if(port.available()&gt;0){
      r = port.read();
      println(r);
    }
  }
  </code></pre>
  
  <p>Arduino code:</p>
  
  <pre><code>int r1=0;
  
  void setup() {
    Serial.begin(9600);
  }
  
  void loop() {
    if(Serial.available() &gt; 0){
      r1 = Serial.read();
      Serial.write(r1);
    }
  }
  </code></pre>