Processing to Arduino communication

First thanks for creating this great community.

I've been searching for a couple days but i didn't find anything.
I think is no need to explain the code, it's quite simple.
When I use a Ruby script to send the data trought the Serial port everything is correct, so I suppose that the error is in the Processing code.
When I execute this, Arduino puts on the Serial Window, random 6,5, and New Lines.

Thank you!

Arduino code:

void setup() {
  Serial.begin(9600);
}

void loop() {
  if (Serial.available() > 0) {
    Serial.println(Serial.read());
  }
}

Processing code:

import processing.serial.*;

Serial port;

void setup() {
  port = new Serial(this, Serial.list()[0], 9600);
  size(400, 50);
}

void draw() {
  port.write(65);
  delay(500);
}

When I execute this, Arduino puts on the Serial Window, random 6,5, and New Lines.

You have the Arduino on one end of the serial port. On the PC, there can be one thing on the other end. Is that the Processing application or the Serial Monitor? It can't be both.

I have connected Arduino to the USB, with de Serial Monitor opened to watch what's writing Arduino.

I have connected Arduino to the USB, with de Serial Monitor opened to watch what's writing Arduino.

So, when you do that, Processing is not talking to the Arduino. It can't, the Serial Monitor has the port tied up.

You can read responses from the Arduino in Processing, and print them in Processing's message area.

When I do this with Ruby it works fine.
I only want to do the same, but with Processing.

The ruby code:

require 'serialport'

port_str = "/dev/tty.usbmodem621"  #may be different for you
baud_rate = 9600
data_bits = 8
stop_bits = 1
parity = SerialPort::NONE
sp = SerialPort.new(port_str, baud_rate, data_bits, stop_bits, parity)
 
#just read forever
while true do
  sp.write('A')
  sleep(500)
end
 
sp.close